Community
Participate
Working Groups
Build ID: 20090621-0832 Steps To Reproduce: 1. Create a new maven project 2. Put some Foo class in src/main/java 3. Put some bar.xml in src/main/resources 4. bar.xml can be reached from Foo by "classpath:bar.xml" (e.g. in a ClasspathResource from Spring) 5. Export this project as a runnable jar 6. Lo and behold: bar.xml is *not* in the root directory of the jar but in a subdirectory called "resources". Your class doesn't work any more, bar.xml can't be found.
Move to JDT/UI. JDT/Core doesn't do the export.
That sounds like an issue of the maven plug-in you're using. The Runnable JAR exporter just collects the contents of the output folders ('bin' directories) and puts them into the JAR together with the required libraries. It sounds like src/main/resources is not on the build path of your project. Please reopen if you can provide an example that fails with a pure Eclipse SDK. Otherwise, you can file a bug against the maven plug-in you use to see if there's something they could do. But be aware that the Runnable JAR exporter can only work for relatively simple Java projects. If you use frameworks that have their own classloading mechanisms, this won't work, and you will have to build your project depending on those frameworks' requirements.
(In reply to comment #2) > The Runnable JAR exporter just collects the contents of the output folders > ('bin' directories) and puts them into the JAR together with the required > libraries. It sounds like src/main/resources is not on the build path of your > project. Yes, it is on the build path: <classpathentry kind="src" output="target/classes" path="src/main/java"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> Both class files and resources go into target/classes/. That directory has the right structure (properties in the root directory like it should be in the jar, no trace of a sub-directory called resources). Nonetheless, I opened a bug in the m2eclipse project. If someone wants to follow this issue, here is the link: https://issues.sonatype.org/browse/MNGECLIPSE-1542
> <classpathentry excluding="**" kind="src" output="target/classes" > path="src/main/resources"/> If your project is correctly built, the 'excluding="**"' should prevent any child of src/main/resources from being copied to target/classes, so this should not even work if you run it from Eclipse. Can you please attach the whole project?
Created attachment 143308 [details] Test project for reproducing this issue
(In reply to comment #4) > > <classpathentry excluding="**" kind="src" output="target/classes" > > path="src/main/resources"/> > > If your project is correctly built, the 'excluding="**"' should prevent any > child of src/main/resources from being copied to target/classes, so this should > not even work if you run it from Eclipse. I think the resources are copied there by the maven plugin, at least that is what the ordinary maven command line is doing: copying files under src/main/resources into target/classes. Yet it still puzzles me how the folder called "resources" is ending up in the jar - if the export would be relying only on eclipse copying the files I could understand a completly missing resources file, but not ending up in the sub-folder.
I had the same problem with a Maven project. I came across this bug report and I created a plain Java project with the Maven directory structure. My exported jar was fine. So, back with my Maven project. I took the resources folder (src/main/resources) out of the build path and then put it back in again. Right-click, remove from build path and again for add to build path. I clicked again on my resources in the desc dialog, rebuilt the Jar file and it now works! The only difference I can see is that one of my resources is exported as a <javaElement> whereas before it was as a <folder>. Kevin
This still happens with Eclipse 4.5.2 and m2e 1.6.2
The problem exists in Eclipse 4.6.0, too.
Can confirm this problem still exists in Eclipse Oxygen. Can also confirm that the workaround provided by Kevin 2 comments above fixed the problem.
Maven's "Update Project..." creates Build Path entries with the "src/main/resources" entry having "Excluded: **" for some reason. If I manually remove the exclusion pattern (or do as Kevin wrote and remove and recreate the entry, thereby removing the exclusion pattern), "Export..." creates jars with the *contents* of src/main/resources copied to the root. If I put "Excluded: **" back in, the jar is created with a "resources" folder at the root and contents inside that folder. I can manually remove "Excluded: **" but doing Maven -> "Update Project..." puts it right back. So although I don't know the purpose, it seems to be intentional.
(In reply to Atsushi Nakagawa from comment #11) > Maven's "Update Project..." creates Build Path entries with the > "src/main/resources" entry having "Excluded: **" for some reason. > > If I manually remove the exclusion pattern (or do as Kevin wrote and remove > and recreate the entry, thereby removing the exclusion pattern), "Export..." > creates jars with the *contents* of src/main/resources copied to the root. > > If I put "Excluded: **" back in, the jar is created with a "resources" > folder at the root and contents inside that folder. > > I can manually remove "Excluded: **" but doing Maven -> "Update Project..." > puts it right back. So although I don't know the purpose, it seems to be > intentional. m2e devs believe this exclusion thing is a cool idea, but I definitely don't share their view on this. The ticket linked from comment 3 has not received a single reaction in 8 years. Since meanwhile the project has fully moved to Eclipse.org, you may try and file a new bug against m2e here in bugzilla. I don't think JDT should change anything, because the rule is to package everything that is on the classpath, and with that exclusion filter no files under resources/ *are* on the classpath, effectively. Just one more idea to try: invoke a maven build right before creating the jar, maybe this will cause maven to copy resources to target/classes as needed for the jar packager?
In case, that somebody has the same problem as me that the resources in the JAR are all in a sub-folder "resources" and not on root level: In the build path of "some" of my projects, the "src/main/resources" had an exclusion setting of "**" (I don't know why nor where it comes from). I removed that everywhere, which fixed the incorrect packaging of my resources.
(In reply to Andreas Lück from comment #13) > exclusion setting of "**" (I don't know why nor where it comes from). See comment 11 and comment 12
(In reply to Stephan Herrmann from comment #14) > See comment 11 and comment 12 Thanks, Stephan. I missed that.