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

I have a program that uses getClass().getClassLoader().getResource() to get the URL in a directory, it works fine when in eclipse, but after jared returns null.

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

The problem is because the path itself did not exist in the bank. The files with the specified path, but not the path itself . I used the Export command "Runnable JAR File" in Eclipse. When I tried the older Jar File export to create a jar, I noticed the โ€œ add recording directory โ€ checkbox, and that was the solution. For a Jar file, you need a directory entry by itself in the jar for getResource () in order to return the URL for the path.

But in maven I canโ€™t find such commands for โ€œadding directory entriesโ€ when packing, can someone tell me? Many thanks!

Env: eclipse 3.5, m2eclipse, maven 2.2.1

+7
java jar
source share
3 answers

If you use the standard maven 2 configuration, the directory and files will be placed in src / main / resources. If they are located elsewhere, you must determine where your resources are located.

 <build> <resources> <resource> <directory>path to my resources</directory> </resource> </resources> 
0
source share

you will need to include the assembly descriptor and create your directories.

0
source share

The assembly descriptor will help you solve this problem. Read the build plugin using this link http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html . If you still can't make it work, then let me know.

0
source share

All Articles