How to make maven "add directory entries" when packaging?
Asked Answered
F

3

7

I have a program that makes use of getClass().getClassLoader().getResource() to obtain an URL to a directory, it works fine when in eclipse , but after jared , it returns null.

According to this url : http://www.coderanch.com/t/385935/java/java/getResource-path-fails-Jar

The problem resulted because the path itself did not exist in the jar. The files with the path existed, but not the path itself. I was using the "Runnable JAR File" export command in Eclipse. When I tried the older export "Jar File" to create the jar, I noticed a check box for "add directory entries" and that was the solution. The Jar file needed the directory entry by itself in the jar for getResource() to return the URL for the path.

But in maven , I cannot find such commands to "add directory entries" when packaging , can someone give me a hint ? Thanks a lot !

Env : eclipse 3.5 , m2eclipse , maven 2.2.1

Finding answered 24/6, 2010 at 17:12 Comment(1)
can you add you project structure and path to the file you are trying to access?Bromoform
M
0

If you use a standard maven 2 configuration, the directory and files would be placed under src/main/resources. If they are elsewhere, you have to define where your resources are.

<build>
   <resources>
      <resource>
         <directory>path to my resources</directory>
      </resource>
   </resources>
Montymonument answered 24/6, 2010 at 17:54 Comment(1)
Thank you , but it seems not working ... maybe it is server's classloader issues ... (Resin)Finding
S
0

you would need to include an assembly descriptor and create your dirs.

Sean answered 1/7, 2010 at 20:6 Comment(1)
Hi , can you be more specific ?Finding
S
0

Assembly descriptor will help you solve this issue. Read up on the assembly plugin using this link http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html. If you still can't get it to work then let me know.

Sean answered 12/7, 2010 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.