Specifying resources for runtime usage? [message #29231] |
Fri, 19 June 2009 08:11 |
Eclipse User |
|
|
|
Originally posted by: ddd.asd.com
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>
to the pom.xml file but that does not help.
Any ideas on how to use resources from the packaged jar files when running
an application?
|
|
|
Re: Specifying resources for runtime usage? [message #29269 is a reply to message #29231] |
Fri, 19 June 2009 09:14 |
Eclipse User |
|
|
|
Originally posted by: ddd.asd.com
"mlt" <ddd@asd.com> wrote in message news:h1fh8m$m8v$1@build.eclipse.org...
>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>
>
> to the pom.xml file but that does not help.
>
> Any ideas on how to use resources from the packaged jar files when
> running an application?
>
>
The resources is loaded:
....
URL url =
this.getClass().getClassLoader().getResource("somexmlfile.xml ");
try {
file = new File(url.getPath());
} catch (Exception e) {
}
I have also tried:
file = new File(url.toURI());
but this throws:
URI is not hierarchical exception.
It seems that this problem is not that the resource is not found but rather
how to use it. I will find another forum, but if anyone in here has an idea
you are welcome to make a comment.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02605 seconds