is there a web page with a

T

tiewknvc9

Is there a web page that details the java coding differences between
running a java application in a directory structure, and running an
application as a jar file?

Basically I have created a java application. In my debugger, of
course, it is in a directory structure, so I reference things like
images by opening the image file in myapp\images\myimage.jpg

However this fails when I jar the application. Of course it fails!
It's in a jar file!

But I was looking for a reference page on how to alter my code for all
occurrences similar to this. Surely there must be some web page that
details what I would need to do to make my application jar --- safe?

Thanks!
 
I

Ingo R. Homann

Hi,

The solution is Class/Classloader.getResource()/getResourceAsStream().

It should be not too difficult to find all occurances of file-access in
your project (with your IDE, with 'grep' or even with an editor) and a
bit more laborous to change the code in the apropriate way.

Hth,
Ingo
 
T

tiewknvc9

Ah,

This I knew. My question is, is there a <b> website </b> that details
ALL of the code changes that one would need to make in order to make
the application jarred without errors?

Basically I dont want to go through each and every problem that arises
from jarring a file, I would rather work off of a reference, instead of
having to research each problem individually.

Thanks for the response though :)
 
S

Simon Brooke

Is there a web page that details the java coding differences between
running a java application in a directory structure, and running an
application as a jar file?

Basically I have created a java application. In my debugger, of
course, it is in a directory structure, so I reference things like
images by opening the image file in myapp\images\myimage.jpg

However this fails when I jar the application. Of course it fails!
It's in a jar file!

Backslashes.

Don't hard code your path separators - use java.io.File.separatorChar
 
T

Tom Cole

Any resources that are not classes (i.e. text files, images, etc.) will
need to use the Classloader to get them. That's it. It's not that
complicated. No other changes needed. Classes will automatically find
themselves as the Classloader is already looking in the jar (since the
first class with the main method was loaded from it...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top