aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Loading resources from jar using maven and ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Loading resources from jar using maven and ant" Watch "Loading resources from jar using maven and ant" New topic
Author

Loading resources from jar using maven and ant

biraji gafiff
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Hi everyone, my project has the following folder structure:
-scr
---main/java
---main/resources

I using maven but ant builds a jar because I still changing to maven. When I run it inside eclipse everything is ok but when I run the jar, it doesn't find the files from main/resources.

Can anyone help me out with this problem?

Thanks.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Wow, there are so many possible things that could be wrong here, I don't know which to ask you about first. Based on the wording of your question ("when I run the jar"), I will assume that you running the app as "java -jar xxx.jar", in which case yo are expecting the resources to be bundled in the JAR file. So my response is:
Is your Ant task that builds the JAR including both the classes in target/classes and the resources in main/resources?


JBoss In Action
biraji gafiff
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Is your Ant task that builds the JAR including both the classes in target/classes and the resources in main/resources?

It wasn't but now it is and it's working, thanks. I think the folder organization inside the jar is a bit confusing now, it looks like this:
-com
-images
-sounds
-META-INF

The folders images and sounds were in resources, is that correct? I thought it should be like /resources/images inside the jar.

Thanks.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Yes, that looks correct to me. The contents of main/resources should be copied as-is into the JAR file.

By the way, I prefer a two-step approach. The first step is to build a directory structure that contains what will be in the JAR/WAR/EAR/SAR file. The second step is to use the jar task to place those contents into the file. This way I always have a directory that contains what went into the final archive file.
 
 
subject: Loading resources from jar using maven and ant