[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.technology.m2e] Re: Specifying resources for runtime usage?

mlt wrote:
I have some xml files in a maven module in:
src/main/resources
which is loaded in my application with:

URL url = this.getClass().getClassLoader().getResource("somexml.xml");

When running my application from eclipse the files are found and used correctly.

When I build my application using "mvn install" and then run it those resources are not found/used. I have opened the .jar files (created during the packaging) and the resources are included. I have also tried to add:

  <build>
  <resources>
    <resource>
      <directory> src\main\resources</directory>
    </resource>
  </resources>
  </build>
You shouldn't need to do that, because this folder is default one used by maven-resources-plugin
Have you tried to look inside jar file and check if resource files are actually in there? If they aren't then try to run mvn help:effective-pom and see if the actual resource folders are there. If folders are there, please post the log from execution "mvn -X clean package" command.
Also, when running in Eclipse, please run "Maven / update project configuration" to make sure that eclipse project settings match your pom.xml
The resources is loaded:
....
URL url = this.getClass().getClassLoader().getResource("somexmlfile.xml");
try {
file = new File(url.getPath());
} catch (Exception e) {


}
That is not going to work when resource is inside a jar file.
However you can print the url and see where it is being resolved to and then check if that place is actually exist


URL url = this.getClass().getClassLoader().getResource("somexmlfile.xml");
System.err.println(url.toString());


 regards,
 Eugene