LoginSignup
1
0

More than 3 years have passed since last update.

intelliJ IDEAで publicディレクトリをルート設定してパス補完する

Last updated at Posted at 2019-06-11

こんな方法しかないんだろうか。。

追記:もっと楽な方法がありました。下記です。

解決すること

環境

IntelliJ IDEA 2019.1.3 (Ultimate Edition)
Build #IU-191.7479.19, built on May 28, 2019
JRE: 1.8.0_202-release-1483-b58 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14
  • site/ (intelliJ の project root)
    • .idea/
    • app/
    • public/

みたいなディレクトリ構成において、html内のsrcとかhrefとかのパスを、publicディレクトリ内で探索してコード補完してほしい場合、ググると「mark as resrouce root」に設定すればよい、みたいな情報を見かけますが、やってみてもだめです。

image.png

そのやり方です。

publicディレクトリのパスを ContentRoot として、手作業でimlファイルに追加する

手作業じゃないと「このディレクトリはプロジェクトに内包されてる」とおこられてしまいます。
おそらくこんな感じになります。

idea/site.iml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$/public" /> <!-- この1行を足す -->
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

この結果、publicディレクトリ内のファイルをコード補完してくれるようになりました!
image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0