Executable JARs, JFrames, and ActionListeners

I'm fairly new to Java, and am currently attempting to create my first JAR executable file. I am using the Eclipse IDE and JDK 5.0. I use Eclipse's export option to create a JAR executable. When the JAR is exectued, it successfully creates and displays the intial JFrame; however, a second JFrame that is created by an ActionListener on a JButton, and is based on input from a JTextArea, is never created when the JButton is clicked on. The second JFrame also accesses txt files based upon the JTextArea input, each of which are contained inside of the JAR file as well. The program compiles and runs successfully when ran as a Java Application or SWT Application in Eclipse, so I am unsure why the export ability is not working.
   public FrameClass1()
      inputTextArea = new JTextArea(29, 95);
      inputTextArea.setFont(new Font("Courier New", 0, 12));
      //Adds the inputTextArea to a JScrollPane, and then adds it to the frame's Center
      buttonPanel = new JPanel();
      submitButton = new JButton("Submit");
      submitButton.addActionListener(new
         ActionListener()
            public void actionPerformed(ActionEvent event)
               String textInput = inputTextArea.getText();
               //Output frame creation
               FrameClass2 outputFrame = new FrameClass2(textInput);
               outputFrame.setVisible(true);
      buttonPanel.add(submitButton);
      //buttonPanel is added to the frame's south portion
   }Any suggestions as to why the second frame class is not being generated and how to fix it are greatly appreciated. Thanks in advance.

To capture the error messages, I've used this try-catch statement, though as I posted earlier, I am not familar with JARs. I have identified that my error is a IllegalArguementException, though I cannot find a precise location of where this exception occurs, as the exceptionOutputFrame is never populated with the stack trace. I've tried both e.getMessage() (below) and e.printStackTrace().toString() with both JLabels and JTextAreas, but the JPanel will not populate with data. Could anybody recommend a good method of outputing the stack trace? In addition, could someone explain the use of getResourceAsStream a little more? Should I be using the class ClassLoader's method or the interface ServletContext? I'm a little rough around the edges with the idea of a resource, so does anybody have a good online reference that I could look at?
     try
          // Insert output frame creation here.
          Class2 outputFrame = new Class2(textInput);
          outputFrame.setVisible(true);
     catch(Exception e)
          JFrame exceptionOutputFrame = new JFrame(e.getClass().getName());
          JScrollPane exceptionOutputScrollPane = new JScrollPane();
          JPanel exceptionOutputPanel = new JPanel();
          JTextArea exceptionOutputLabel = new JTextArea(e.getMessage());
          exceptionOutputPanel.add(exceptionOutputLabel);
          exceptionOutputScrollPane.add(exceptionOutputPanel);
          exceptionOutputFrame.add(exceptionOutputScrollPane);
          exceptionOutputFrame.setSize(exceptionOutputLabel.getWidth(), DEFAULT_HEIGHT);
          exceptionOutputFrame.setVisible(true);
     catch(Error e)
          JFrame errorOutputFrame = new JFrame(e.getClass().getName());
          JScrollPane errorOutputScrollPane = new JScrollPane();
          JPanel errorOutputPanel = new JPanel();
          JTextArea errorOutputLabel = new JTextArea(e.getMessage());
          errorOutputPanel.add(errorOutputLabel);
          errorOutputScrollPane.add(errorOutputPanel);
          errorOutputFrame.add(errorOutputScrollPane);
          errorOutputFrame.setSize(errorOutputLabel.getWidth(), DEFAULT_HEIGHT);
          errorOutputFrame.setVisible(true);
     }

Similar Messages

  • Executable JAR file and subdirectories, locale...

    Hi:
    I have created an executable jar file. In my program, I have to display an icon in which I stored in a subdirectory. This subdirectory is also archived into the jar file. However, as the application runs, it can't find the icon! I have to seperately create a subdirectory (with the same name and structure as the archived directory) for my program to display the icon properly! Does anybody know how I can use the archived subdirectory directly?
    Also, the executable jar file has a problem of using the proper locale... Does anyone know how to get around this?
    Thanx in advance for helping me out = )

    Thanx! It worked!
    Does anyone know the answer to my second problem, namely, using the correct locale to display characters? When I run the application on the unarchived class file it works fine. However, when I run the application double-clicking the executable jar file icon, the characters are displayed incorrectly, which I assume to be problem with the locale...

  • Executable jar files and manifest file

    Hi,
    I have the following files in a folder named: Test
    a.jar
    b.jar
    c.jar
    Driver.class
    Driver.mf
    Here, MainClass is the main executable class that uses a,band c.jar files. This is how my MainClass.mf file looks:
    Manifest-Version: 1.0
    Main-Class: Driver
    Class-Path: a.jar b.jar c.jar
    Now I use the following command to make one executable jar file:
    jar cmf Driver.mf DriverMain.jar *
    It creates an executable jar file named : DriverMain.jar
    Now I copy the executable jar file (DriverMain.jar) into a different folder named: RunTest
    and double click it, doesn't work.
    my question is:
    what am I doing wrong? Any special characters needed in my Driver.mf file (space/newline/etc)?
    What I am trying to get is: One execuatble jar file so I can just double click to run it, and that single executable jar file will have all the necessary jars in it (i.e. a.jar, b.jar, c.jar in this case)
    Anyone please help!
    Thanks
    -Ron

    Rony,
    Sorry to disappoint, but you can not use embeded jar/zip files within an executable jar. The JDK sadly for some reason decided this was not a useful idea, so developers like me who want to distribute plugins with thier own dependencies have one of two choices. You either have to unzip the jar file that contains the embeded jars to a directory, then run your primary exectuable jar, OR you have to write a custom classloader that your "launcher" creates then loads the embeded jar files.
    The best thing to do is either jar up a, b, c and driver into one jar, so that it works, if you can legally do this. A lot of 3rd party libraries may not allow this per their license. Otherwise, another choice is to use a free installer or buy an installer that allows you to distribute a single exectuable installer program that will properly create the dir structure you need.
    As for the way it works, if you declare:
    Class-Path: a.jar b.jar c.jar
    the JAR loader code in the JDK looks in the root dir where your application was started for a/b/c jar files. They have to be on disk.
    If you want to place them in /lib, for example, you would havd a jar file like:
    Driver.class
    Driver.mf
    lib/a.jar
    lib/b.jar
    lib/c.jar
    When unzipped, your "root" dir would look exactly like the above, and your manifest would have Class-Path using ./lib/a.jar ./lib/b.jar ./lib/c.jar
    Anyway, there thus far isn't any way around this issue of embeding jar files in an executable jar file. You MIGHT be able to not specify any classpath, then in your Driver.class, create a new custom classloader that dervies from URLClassLoader, but in the findClass(), you get a ref to the .jar file that the classloader class is inside of, and from that use it to find the lib/*.jar files and add them to the classpath. For this to work, however, your Driver.class code should ALSO be contained in an embeded jar file that is loaded by this custom loader. The only thing Driver.class would contain (and I would rename it to something like Launcher) is the code to create the custom classloader.
    It's fun stuff, but a little bit of work to make it work. You can infact make it work! I may yet one day take our plugin engine custom loader and create a way for this to work!

  • Could not find the main class error with executable jar

    Hello,
    I have troubles creating an executable jar file and I ran out of ideas how to solve it so I would appreciate some help.
    I have created a jar file with the export function in eclipse
    the Manifest.MF file contains:
    Manifest-Version: 1.0
    Main-Class: view.AppTennisViewI tried starting the file with a batch file which contains following code:
    @echo off
    javaw -classpath c:\TennisHSQLDB_GC2\tennisApp.jar
    @start javaw -jar tennisApp.jar
    exitthe batch file and the jar are both located in c:\TennisHSQLDB_GC2.
    When i try command line I get the same result.
    I also tried alternate statements such as SET CLASSPATH iso javaw -classpath and including the classpath in the manifest file but no luck. It keeps given me the error: could not find the main class. program will exit
    Anyone any suggestions for my problem?

    nevermind, found it.
    classpath in manifest was incorrect

  • Unable to execute JAR files

    I am unable to execute jar files and applets. Also, the Java Web Start and the Java Plugin Control Panel will not load. I have unloaded the JRE and installed other versions. To date I have loaded and unloaded the following:
    1.4.1
    1.4.2_01, _02, _04
    1.4.2_04 SDK
    But no change in the outcome.
    The javaw application starts but does not load the jar file.
    The applets and jar files run fine on other computers with any of those JRE/SDK's installed.
    Any suggestions would be helpful.

    Command line
    To create a JAR file >jar cvf filename.jar filename.class(s)
    To view the contents of a JAR file >jar tvf filename.jar
    To extract the contents of a JAR file >jar xf filename.jar
    To extract specific files from a JAR file >jar xf filename.jar archived-file(s)
    To run an application packaged as a JAR file
    >jar xvf filename.jar META-INF/MANIFEST.MF
    The above will place META-INF/MANIFEST.MF file in your working directory. Open this file in text editor. Under Version, type in
    Main-Class: filename
    example;
    Manifest-Version: 1.0
    Main-Class: SelectPurchase
    Created-By: 1.3.0 (Sun Microsystems Inc.)
    save file
    update META-INF/MANIFEST.MF file in jar file with;
    jar umf META-INF/MANIFEST.MF filename.jarto run jar file from command line;
    java -jar filename.jarTo run an application packaged as a JAR file
    (version 1.1) jre -cp app.jar MainClass
    (version 1.2 -- requires Main-Class
    manifest header)
    To invoke an applet packaged as a JAR file <applet code=AppletClassName.class
    archive="JarFileName.jar"
    width=width height=height>
    </applet>
    Does anyone know how to get the application to run by clicking on a Desktop Icon?

  • Executable Jar? - Googled for hours, tried many solns, still doesn't work!

    I am fairly new to Java, and I'm just simply trying to create an executable jar that will run when I double-click on the icon.
    I have created my very basic program that uses java swing on Netbeans. I have right-clicked on the project, selected properties, and checked the packaging section to make sure that it creates a jar file. I also selected compress jar file, which some tutorial told me to do as well. (I've also tried not checking compress jar file to see if it made a difference... it didn't).
    I then went to folder options to make an association with the jar file to javaw.exe so that when I clicked on the icon, it would know to use javaw.exe to open it. When I double click on the jar file, it now just makes the error noise and nothing happens. Before I made the assocation, it would open up ultimatezip which would show me the original source code, the class file, and the manifest.mf file.
    In any event, I'm just playing around with creating an executable jar file and any advice on how to make it so that the GUI launches when I double click on it would be extremely helpful.
    Edited by: bigbamboo on Oct 13, 2009 8:41 AM

    bigbamboo wrote:
    Thanks for your prompt response. I just tried your suggestions. 1 & 2 both worked for me. I have fiddled around some more with my file association and have looked at several sites that go through it step-by-step and I have tried them all. I went to tools, folder options, and I have changed the association to javaw.exe
    I just can't figure out what's wrong.Good. So at least you know that it is the file type association that is not working correctly.
    On my Windows PC, when I edit the open Action for .jar files, the command string is
    "C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*Maybe that will help. Of course, the path to your javaw.exe may be different.

  • Newbie's problem with executable jar file

    hello
    i create an executable jar file and it seems ok except it fails to locate all of my image files.
    when i use
    java -jar myproject.jar
    it fails to display included pictures and files.
    however, when i extract this jar file and run, it works fine (displays everything).
    do i need to do add some informations about these included file's information into Manifest file?
    thank you

    thank you for the reply.
    i have searched through java, and find "class javax.commerce.cassette.JARCassetteLoader". is this one you referred? i have used file related examples from the java-swing samples.
    //post - return the file path
    protected static ImageIcon getImageIcon(String path)
    java.net.URL imgURL = TestDialog.class.getResource(path);
    if (imgURL != null)
    return new ImageIcon(imgURL, description);
    else
    System.out.println("Couldn't find file: " + path);
    return null;
    then i just use
    ImageIcon icon = getImageIcon("images"+File.separator+"simple.gif"); // images\simple.gif
    thank you

  • Adding a jar to the classpath of an executable jar (mixing -jar and -cp)

    Hello,
    frankly I hesitated over posting this to "New to Java"; my apologies (but also, eternal gratefulness) if there is an ultra-simple answer I have overlooked...
    I integrate a black-box app (I'm not supposed to have the source) that comes packaged as an executable jar (with a Manifest.MF that specifies the main class and a bunch of dependent jars), along with a few dependent jars and a startup script. Long story short, the application code supports adding jars in the classpath, but I can't find a painless way to add a jar in its "classpath".
    The app's "vendor" (another department of my customer company) has a slow turnaround on support requests, so while waiting for their suggestion as to how exactly to integrate custom jars, I'm trying to find a solution at the pure Java level.
    The startup script features a "just run the jar" launch line:
    java -jar startup.jarI tried tweaking this line to add a custom jar in the classpath
    java -cp mycustomclasses.jar -jar startup.jarBut that didn't seem to work ( NoClassDefFound at the point where the extension class is supposed to be loaded).
    I tried various combination of order, -cp/-classpath, using the CLASSPATH environment variable,... and eventually gave up and devised a manual launch line, which obviously worked:
    java -cp startup.jar;dependency1.jar;dependency2.jar;mycustomclasses.jar fully.qualified.name.of.StartupClassI resent this approach though, which not only makes me have to know the main class of the app, but also forces me to specify all the dependencies explicitly (the whole content of the Manifest's class-path entry).
    I'm surprised there isn't another approach: really, can't I mix -jar and -cp options?
    - [url http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html]This document (apparently a bible on the CLASSPATH), pointed out by a repited forum member recently, does not document the -jar option.
    - the [url http://download.oracle.com/javase/tutorial/deployment/jar/run.html]Java tutorial describes how to use the -jar option, but does not mention how it could play along with -cp
    Thanks in advance, and best regards,
    J.
    Edited by: jduprez on Dec 7, 2010 11:35 PM
    Ahem, the "Java application launcher" page bundled with the JDK doc (http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html) specifies that +When you use [the -jar] option, the JAR file is the source of all user classes, and other user class path settings are ignored+
    So this behavior is deliberate indeed... my chances diminish to find a way around other than specifying the full classpath and main class...

    I would have thought that the main-class attribute of the JAR you name in the -jar option is the one that is executed.Then I still have the burden of copying that from the initial startup.jar's manifest. Slightly less annoying than copying the whole Class-path entry, but it's an impediment to integrating it as a "black-box".
    The 'cascading' behavior is implicit in the specification
    I know at least one regular in addition to me that would issue some irony about putting those terms together :o)
    Anyway, thank you for confirming the original issue, and merci beaucoup for your handy "wrapper" trick.
    I'll revisit the post markers once I've actually tried it.
    Best regards,
    Jérôme

  • Executable jar that can extract some archive nested in it and do more

    Can anyone tell me how i can extract sfx(self -extracted) archive using executable jar if this archive is included into this jar. And how to include it.
    For example: i have jar witch prints hello world to screen but also contains sfx archive in it with pictures for example, so when i double click on this jar, it should start sfx and print hello world.

    hi Dear
    I have tried following example and it works well and good. Here i m using jdk 1.6
    package mypack;
    public class Test {
    public static void main(String args[]) {
    try {
    System.out.println("Hello World");
    Process p = Runtime.getRuntime().exec("Tcpview.exe");
    System.out.println("wait status " + p.waitFor());
    }catch (Exception e) {
    e.printStackTrace();
    i have created META-INF\MANIFEST.MF file in the same folder where mypack folder stays meance my folder hierarchy is this.
    META-INF\MANIFEST.MF
    mypack\Test.class
    Tcpview.exe
    I have created jar with following command
    jar -cvfM mypack.jar *
    and executing the mypack.jar as
    java -jar mypack.jar
    If after doing something like this then also if your problem not solved then do one thing that
    In jar creation give one more option 0 meance
    jar -cvfM0 mypack.jar *
    Try and then put your comment. I have successfully runned above e.g.

  • Executable Jars and their Classpath

    I have made a java application that takes requires several libraries to run. I am using netbeans 4.0 but have reached the stage where I'd like it to become a standalone application.
    I have editted the projects properties in netbeans to use the correct libraries for compilation and set the correct arguments to run it. It runs fine in netbeans. However, when i try to execute the jar file that netbeans generates with the command...
        java -jar  PeerPressure.jari get the error...
      Exception in thread "main" java.lang.NoClassDefFoundError: net/jxta/pipe/PipeMsgListenerI have tried to modify the manifest.mf file to (it has 2 enters at the end)....
    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    Main-Class: Main
    Class-Path: /lib/jxta.jar /lib/bcprov-jdk14.jar /lib/javax.servlet.jar /lib/log4j.jar /lib/org.mortbay.jetty.jarbut i get the same error. I've also tried the command...
      java  -classpath \lib\jxta.jar;\lib\log4j.jar;\lib\bcprov-jdk14.jar; -jar PeerPressure.jarI'm not sure what else i could try. I've already looked through loads of tutorials and forums posts but still havent got any further. Any help would be great.
    Cheers

    Tried it and still no luck :(
    I tried executing the jar that netbeans 4.0 generates with a project that doesnt require the classpath to be set and that works fine. Also, looking at the stack trace, I've noticed that the executable jar file that i'm having problems with does actually execute. But when it reaches a class that implements the PipeMsgListener it stops.
    C:\Documents and Settings\Scottie\PeerPressure\dist>java -classpath ..\lib\jxta.
    jar;..\lib\log4j.jar;..\lib\bcprov-jdk14.jar;. -jar PeerPressure.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: net/jxta/pipe/PipeMsg
    Listener
            at java.lang.ClassLoader.defineClass0(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at peerpressure.Main.main(Main.java:26)i get the same error when i try
    java -jar PeerPressure.jarMy first thought was that the class that implements the PipeMsgListener was at fault. But when i run the project through netbeans it works fine!
    Not sure whats going on really. Does anyone know how to find out the command that netbeans is using to execute a project? If i could find out what it is i could use it to execute my jar.
    cheers :)

  • Projects and executable jars

    I'd like to distribute single executable jar files, but share (the source's of) some packages.
    Netbeans 4.1 however refuses to add the same directory with sources to mutiple projects. Under packaging standard projects, the help files only tells how to suppress or rename/relocate jar files, and under creating dependencies between projects only about setting the classpath. Has anybody a hint?
    Jo

    I think if you create a separate project, then that project (including source) can be imported into multiple projects.
    But I'm using version 5, and this is from memory, so. . .

  • JavaFX Runtime, JDK Bundles and Executable Jar's.....

    It appears that a JavaFX applet can be executed/launched so long as JRE v1.6_u14+ has been installed (I believe). I've tested this and machines without a JavaFX SDK installation can run the javafx.com applets.
    But is this also true for an executable jar? What's needed to execute JavaFX desktop applications a bare minimum?

    I haven't tried, but the specified minimal JRE is 1.5. That's why we are restricted to 1.5 classes in JavaFX...
    JavaFX applets are deployed and run by using the dtfx.js script, which check if JavaFX runtime is installed, and if not, download and install it.
    JavaFX desktop applications (in .jar files) must be run through a JNLP file which does the same (check and deploy runtime if needed).
    In theory you can deploy the runtime yourself, to avoid the use of a JNLP file (why?), but I think it will go against the current license.
    At least the JNLP does a number of checks for you, checking you have the right version, upgrading if needed, installing shortcuts, etc.

  • Create executable jar and run it

    hi ,
    I want to create an executable jar file for my Swing application in windows environment and I want to run that jar file by double clicking on it. What should I do?

    I can't beleive I'm saying this given that I didn't like it only 3 months ago but if you change your development environment to Eclipse rather than JCreator/JBuilder or whatever, it saves all that creating manifest files by having one menu item, "Export". You should take a look at minifest files though and at least understand them, they aren't complex at all.

  • Download and execute jars without using javaws

    Hi
    I need to download and execute jars from remote computer. I hava jnlp file, but I strongly need to execute jars without using java web start.
    What is the best way to do this task?
    Thanks in advance :)
    Edited by: joekidd on Aug 3, 2009 5:55 AM

    joekidd wrote:
    The easiest the best:)The easiest way is to hire the programmers who made the Jar, to consult on your behalf to install the program, or advise on its installation. BTW - you said earlier.. "strongly need to execute jars without using java web start." Why? What advantage does that provide?
    So I download needed jars, add them to classpath and run my application (I get all information from jnlp file and pass them to vm and my application).
    But following exception occurs "Exception in thread "main" java.lang.NoClassDefFoundError: javax/jnlp/ServiceManager". What should I do?Get in contact with those programmers, because this app. is dependant(1) on functionality that is only available to web start apps.
    (1) Unless they put that call in there, just to ensure no one can run the app. outside web start. ;-)

  • Executing JAR Files Windows 98 and XP

    Hey can someone please help me.
    I made an executable jar file the extract contents of a jar file. In windows XP it runs fine, however in Widnows 98 it does not, has anyone come across this problem? Any info would be greatly appreciated.
    Thanks

    Well When I try, On a windows XP machine it shows the progress bar I made, and extracts all the files to the c drive. On Windows 98 It shows the progress bar but will not extract the files to the c: drive folder.
    The program simply gets all the files that are within the jar file, and puts their names in a Vector, then takes the names from the Vector and Extrats the ones that need to be extracted.
    Any other Ideas, I know this sounds very wacky thats why I am in need of help.
    Thanks for the ideas.

Maybe you are looking for