Marsellus Wallace
Marsellus Wallace

Reputation: 18601

IntelliJ not seeing resources folder

I created a new Project from scratch in IntelliJ by using a Maven Module. I didn't select any specific archetypes and I clicked on finish. The project gets created nicely and I have the java and resources folders under src/main as expected.

Unfortunately, my application does not find any property files in the resources folder because it looks in the project base folder instead.

I double checked that the resources folder is marked as 'source folder' in the Project Structure and I also tried to add the following to the pom.xml with no success:

<resources>
  <resource>
    <directory>src/main/resources</directory>
  </resource>
</resources>

I'm using Maven 2.2.1 and IntelliJ 11.1, Any thoughts??

Upvotes: 17

Views: 33987

Answers (6)

davidfrancis
davidfrancis

Reputation: 3849

I had a similar issue and resolved it.
My issue was not an Intellij issue, it was an error in my pom.xml
I had included this by mistake:

<packaging>pom</packaging>

Removing this (or correcting it) fixed my issue.

Upvotes: 2

master
master

Reputation: 19

Well the answer is quite simple ..!
Just reference the file path in your source code as below:

src\\main\\resources\\FileName

& it should work as expected.

Upvotes: 1

mafyak
mafyak

Reputation: 61

Had similar issue. Solution that worked for me:

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("path").getFile());

Upvotes: 1

Ahmad Abdelghany
Ahmad Abdelghany

Reputation: 13208

Right Click the Directory -> "Mark Directory as" -> "Resource Root"

Upvotes: 7

Ichtion
Ichtion

Reputation: 91

There is a bug in Intellij 12 please go to Settings->Compiler and un-check "Use external build" check box - the idea behind it was that it was suppose to run faster with a compiler run in a separate process but in fact there is a bug and when using maven it does not copy resources.

Upvotes: 9

fo_x86
fo_x86

Reputation: 2613

try

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <includes>
      <include>**/*</include>
    </includes>
  </resource>
</resources>

or under settings -> compiler -> resource patterns, add the resource pattern (i.e ?*.prefs)

Upvotes: 1

Related Questions