Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading resources from jar using maven and ant

 
biraji gafiff
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
biraji gafiff
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic