You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jeffrey Williams <je...@gmail.com> on 2008/10/26 11:34:41 UTC

Wierd issue with getting a resource from inside a jar

Hi,

I am having an issue with maven and getting a file from within my
executable jar project.

I have the following code in my main

		URL url = this.getClass().getResource("/comma.txt");
		File commaFile = new File(url.getFile());

The issue is that the url that is found when executing the jar has an
exclamation mark in it. ie

/home/jeffxor/workspace/cyrus/target/cyrus-0.0.1-SNAPSHOT.jar!/comma.txt

you will notice it after the jar file name. Obviously when I then try
to get a file I get FileNotFoundException.

I have used this code on other machine and have had no issue. I am
using Ubuntu and maven 2.0.8 and java 1.6., I have searched the
internet but have got no results and I am out of ideas.

Any help would be great.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Wierd issue with getting a resource from inside a jar

Posted by Andrew Robinson <an...@gmail.com>.
How is this a weird issue? URL != file.  Just because some URLs can be  
converted to valid files doesn't mean all can. If you need the file  
contents use getResourceStream. If you need information on the file,  
use the java.util.zip package

Sent from my iPod

On Oct 26, 2008, at 4:34 AM, "Jeffrey Williams" <jeff.williams.jobs@gmail.com 
 > wrote:

> Hi,
>
> I am having an issue with maven and getting a file from within my
> executable jar project.
>
> I have the following code in my main
>
>        URL url = this.getClass().getResource("/comma.txt");
>        File commaFile = new File(url.getFile());
>
> The issue is that the url that is found when executing the jar has an
> exclamation mark in it. ie
>
> /home/jeffxor/workspace/cyrus/target/cyrus-0.0.1-SNAPSHOT.jar!/ 
> comma.txt
>
> you will notice it after the jar file name. Obviously when I then try
> to get a file I get FileNotFoundException.
>
> I have used this code on other machine and have had no issue. I am
> using Ubuntu and maven 2.0.8 and java 1.6., I have searched the
> internet but have got no results and I am out of ideas.
>
> Any help would be great.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org