views:

34

answers:

3

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

A: 

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>
Robin
Thank you , but it seems not working ... maybe it is server's classloader issues ... (Resin)
smallufo
A: 

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

Hi , can you be more specific ?
smallufo
A: 

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.