开发者

How to make maven "add directory entries" when packaging?

开发者 https://www.devze.com 2023-01-04 11:05 出处:网络
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.

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


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>


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消