Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Packaging SWT app in jar
Packaging SWT app in jar [message #454625] Tue, 26 April 2005 05:48 Go to next message
Eclipse UserFriend
Originally posted by: samik.frKKshKll.org

Hello,
I tried out packaging a simple program which loads an image from a file. When I tried to run the executable jar, it gives me an Exception message which looks like this:

--------------------------------------------------
Samik@mylappy >java -jar Test.jar
Exception in thread "main" java.lang.IllegalArgumentException: Argument cannot be null
at org.eclipse.swt.SWT.error(SWT.java:2677)
at org.eclipse.swt.SWT.error(SWT.java:2616)
at org.eclipse.swt.SWT.error(SWT.java:2587)
at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:1 22)
at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:308)
at org.eclipse.swt.graphics.Image.<init>(Image.java:668)
at Test.showSplashScreen(Test.java:34)
at Test.<init>(Test.java:21)
at Test.main(Test.java:68)
------------------------------------------------------------ -

My packing command and packed file list are below:

Samik@mylappy >jar cvfm Test.jar Test.manifest *
adding: META-INF/ (in=0) (out=0) (stored 0%)
adding: META-INF/MANIFEST.MF (in=257) (out=161) (deflated 37%)
adding: Test.class (in=2552) (out=1338) (deflated 47%)
skipping: Test.jar
adding: Test.manifest (in=257) (out=161) (deflated 37%)
adding: extlib/ (in=0) (out=0) (stored 0%)
adding: extlib/ApacheMathLib.jar (in=145636) (out=126248) (deflated 13%)
adding: extlib/jface.jar (in=513271) (out=459924) (deflated 10%)
adding: extlib/jfacetext.jar (in=618365) (out=549072) (deflated 11%)
adding: extlib/lpsolve51j.jar (in=32098) (out=30665) (deflated 4%)
adding: extlib/osgi.jar (in=47992) (out=39654) (deflated 17%)
adding: extlib/runtime.jar (in=355229) (out=326614) (deflated 8%)
adding: extlib/swt.jar (in=1128591) (out=1059453) (deflated 6%)
adding: extlib/text.jar (in=170641) (out=152279) (deflated 10%)
adding: images/ (in=0) (out=0) (stored 0%)
adding: images/splash.jpg (in=16183) (out=15331) (deflated 5%)
Total:
------
(in = 3031072) (out = 2762554) (deflated 8%)
============================================================ =====

The offending line of the code is:
Test.java:34: Image SplashImage=new Image(display, this.getClass().getResourceAsStream(IMAGE_PATH+"splash.jpg"));
IMAGE_PATH is a static string containing "image/"

The program runs fine as such from the command prompt (java Test), with all the class paths set etc. Only when I pack the reqd. files in the jar and try running, the problem appears. Did I miss any file? I tried including the dll's (I am running on Win XP Home), that didn't help.

Thanks for any pointers.
-Samik
Re: Packaging SWT app in jar [message #454656 is a reply to message #454625] Tue, 26 April 2005 12:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: martin.j.nilsson.sverige.nu

> adding: images/ (in=0) (out=0) (stored 0%)
> adding: images/splash.jpg (in=16183) (out=15331) (deflated 5%)
> Test.java:34: Image SplashImage=new Image(display,
this.getClass().getResourceAsStream(IMAGE_PATH+"splash.jpg"));
> IMAGE_PATH is a static string containing "image/"

This might be just you making a typo here in the NG, but you are adding
the image to the "images" directory and the static string contains the
path "image/", missing the "s".

In this case java can't find the file you've specified in (IMAGE_PATH +
"splash.jpg"), if it is not because of the above problem I'm not sure why.


regards,
martin
Re: Packaging SWT app in jar [message #454662 is a reply to message #454656] Tue, 26 April 2005 18:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: samik.frKKshKll.org

On 4/26/2005 7:10 AM, Martin J Nilsson wrote:
> This might be just you making a typo here in the NG, but you are adding
> the image to the "images" directory and the static string contains the
> path "image/", missing the "s".
>
> In this case java can't find the file you've specified in (IMAGE_PATH +
> "splash.jpg"), if it is not because of the above problem I'm not sure why.
>
Thanks for replying Martin. It was a typo in my post. Sorry about that.
-Samik
Re: Packaging SWT app in jar [message #454668 is a reply to message #454662] Wed, 27 April 2005 03:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: samik.frKKshKll.org

The problem is in loading the image from the jar file. I think I have to use some tool to extract the image from jar file while executing.
-Samik
Re: Packaging SWT app in jar [message #454669 is a reply to message #454668] Wed, 27 April 2005 03:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: samik.frKKshKll.org

On 4/26/2005 10:25 PM, Samik Raychaudhuri wrote:
> The problem is in loading the image from the jar file. I think I have to
> use some tool to extract the image from jar file while executing.
> -Samik
Ok I found out the error. Here are the details:
Apparently getClass().getResourceAsStream(IMAGE_PATH+"splash.jpg") should get the image from inside jar file too. My problem was in using System.getProperty("file.separator") in constructing IMAGE_PATH. My OS is Windows, but I was running the program on Cygwin. So file.separator was coming as "\". Once I hardcoded IMAGE_PATH="images/", the jar executed fine.

Basically, I was compiling from WINDOWS but trying to execute in Unix, so there was a messup.

Hope it helps somebody.
-Samik
Re: Packaging SWT app in jar [message #454699 is a reply to message #454669] Wed, 27 April 2005 15:42 Go to previous message
Stefan Zeiger is currently offline Stefan ZeigerFriend
Messages: 102
Registered: July 2009
Senior Member
Samik Raychaudhuri wrote:

> Apparently getClass().getResourceAsStream(IMAGE_PATH+"splash.jpg")
> should get the image from inside jar file too. My problem was in using
> System.getProperty("file.separator") in constructing IMAGE_PATH. My OS
> is Windows, but I was running the program on Cygwin. So file.separator
> was coming as "\". Once I hardcoded IMAGE_PATH="images/", the jar

This is not caused by Cygwin. Java resource paths always use forward
slashes ("/"), no matter which platform.

--
Stefan Zeiger - Developer of Novocode Application Framework
Build SWT-based MVC GUIs via XML: http://www.novocode.com/naf/
Previous Topic:How to check System Clipboard
Next Topic:What is the CreateHatchBrush equivalence in draw2d?
Goto Forum:
  


Current Time: Sat Feb 27 10:26:59 GMT 2021

Powered by FUDForum. Page generated in 0.02176 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top