user2783641
user2783641

Reputation: 1

Using maven the resources folder is not getting generated at the same level where class files are getting generated

I am having my directory structure as

src/
- main/
  - java/
    - com/
      - resources/  // Folder where I have kept my properties file
      - class1.java
      - class2.java

When I am trying to build the JAR using maven the resources folder is getting skipped and I am having only this structure left

src/
- main/
  - java/
    - com/
      - class1.class
      - class2.class

I know that maven uses a conventional dir. structure for the resources as src/main/resources. But I want my resources folder to be at the same level where my class files are getting generated.

Can anyone please help me in this regard.

Thanks in advance.

Upvotes: 0

Views: 145

Answers (1)

user944849
user944849

Reputation: 14961

The key is what you said - you want your resources to be at the same level where the class files are being generated. That doesn't mean they have to start in the same folder. They must simply have the same package structure. You may do this following the normal Maven file layout conventions as follows.

- src
  - main
  | - java
  |   - com
  |     - mycompany
  |       - Class1.java
  |       - Class2.java
  | - resources  
  |   - com
  |     - mycompany
  |       - someResources.properties
  |       - anotherResource.jpg

Note that the directory/package structure under /src/main/java and /src/main/resources is the same. When the maven-compiler-plugin and maven-resources-plugin have finished running, the result will be

- target
  - classes
    - com
      - mycompany
        - Class1.class
        - Class2.class
        - someResources.properties
        - anotherResource.jpg

which is what you want.

Upvotes: 1

Related Questions