• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading resources from jar using maven and ant

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic