Take the 2-minute tour ×

I have an application built in Java, which, when a certain button is pressed within the application, another jframe should popup with a message. The ant file I made places the runnable jar into a folder within my Eclipse project. When the jar is built, and I run the jar in the folder it was born in, it runs fine. I can click the button that makes the popup show up and it does, indeed, show up.

The problem comes when I move the jar out and say, onto the desktop. Then running the jar starts the application, but pressing the button does nothing (no popup).

Now, I know I had issues including some image resources before, and had to use getResource() etc. I do not see why I would have to do anything like this since all of the "resources" are just .class files which are specified in the build path. I mean, all the app should be doing is creating a jframe...

EDIT: adding build.xml EDIT: slimmed build.xml down -- I think the problem is in the building of the JAR.

<!--Creates the deployable jar file  -->
    <echo>"Making Deployable Jar..."</echo>
    <jar destfile="${shipping.dir}/POSsystem.jar" basedir="${build.dir}">

        <fileset dir="." includes="${imgs.dir}/**"/>
        <fileset dir="." includes="db/**"/>

            <attribute name = "SplashScreen-Image" value="${splash-screen}" />

    <echo>"Success Making Deployable Jar..."</echo>

EDIT 3: Added output from running via the command line.

C:\Users\Matt\Desktop>java -jar POSsystem.jar
java.io.IOException: The system cannot find the path specified
        at java.io.WinNTFileSystem.createFileExclusively(Native Method)
        at java.io.File.createNewFile(Unknown Source)
        at pos.log.GeneralLog.beginLog(Unknown Source)
        at pos.main.POSsystem.main(Unknown Source)

This is the first error. The application should keep a log.txt, within a log folder, within the JAR. You can see in the build.xml (first thing posted) that I add the log folder to be built in to the JAR, which is fine, but the path in my log.java code will obviously give me problems since it's a hard-coded path. So my question here is: How do I include a path to the resource in a JAR file. I know that to include an image I would do something like: javax.swing.ImageIcon(getClass().getResource("/images/pos_header_icon.png")); but I'm not sure how to access a file location...

share|improve this question
1) without pertinent code I'm not sure how we can play the "guess the bug" game and win. 2) You shouldn't even be popping up JFrames. That is what JDialogs are for. –  Hovercraft Full Of Eels Jan 25 '13 at 23:54
Thanks for the reply. I didn't intend you to play "guess the bug". I'm trying to figure out if there's a clear reason that this doesn't work. Posting code I didn't believe would be helpful to anyone in this case. Also, can you provide a reason for not using a JFrame as a popup? In this case it is a form that the user would be filling out. –  MattB Jan 26 '13 at 0:01
Sure, the JFrame is not dependent on the underlying window and that is bad window behavior. You rarely want to launch two separate windowing applications but rather would want to occasionally launch a dialog window that is dependent on the underlying window which is just what a JDialog does. It also gives you the flexibility and power of being either modal or non-modal, something a separate JFrame can't do. –  Hovercraft Full Of Eels Jan 26 '13 at 0:04
And yes, you have a bug but without pertinent code, preferably an sscce, I doubt anyone will have much of a chance of being able to help you. I hope that I'm wrong of course. –  Hovercraft Full Of Eels Jan 26 '13 at 0:05
1) What is your question? 2) See The Use of Multiple JFrames, Good/Bad Practice? 3) Run it from the command line (e.g. java -jar the.jar) and report any output. –  Andrew Thompson Jan 26 '13 at 2:40
show 2 more comments

1 Answer

up vote 3 down vote accepted

The application should keep a log.txt within a log folder, within the JAR.

As noted here, it is possible to extract a file from a JAR, modify the file, and restore the archive; but it is not practical to alter the JAR from which currently loaded classes are running. THis would be a particular problem for an ongoing log. Instead, solicit a suitable path using JFileChooser and save it among your application's java.util.Preferences. Some platforms have recommended paths, for example.

share|improve this answer
Thanks trashgod. I did something similar; I just made a directory under "user.home" where I will be storing data like log data and db stuff, rather than accessing the JAR. I think it's pretty much what you are recommending, though I don't give the user the option to choose the location. –  MattB Jan 26 '13 at 21:03
I will accept this answer, since my original problem had to do with the location of the db, log etc. –  MattB Jan 26 '13 at 21:08
add comment

Your Answer


