Help: App runs fine in Studio but get nothing when running dist/jar file?

Good Day,

I hope someone else might be able to help me out. I am new to java and already stumped on an issue. I created a small application in SE 8 and it will run/debug fine when in the studio. But if I build the jar file and try running it by double clicking the jar file I get nothing. I have even tried to copy the jar file to another pc with the same result. I eventually go into the task manager to kill the javaw.exe to free up the file. One thing I did try was putting a "showMessageDialog" above the "setVisible(true)" for my form and I get the dialog but no form...

It just blows my mind how everything runs great in the IDE as expected, but when you create the jar file you get nothing?

Thanks in advance!

Jake

[753 byte] By [jake99a] at [2007-10-3 2:39:56]
# 1
> It just blows my mind how everything runs great in> the IDE as expected, but when you create the jar file> you get nothing?Probably because you did something wrong. May I see your main class's code for a beginning?
CeciNEstPasUnProgrammeura at 2007-7-14 19:38:12 > top of Java-index,Java Essentials,New To Java...
# 2

> Probably because you did something wrong. May I see

> your main class's code for a beginning?

Sorry, you are probably right about me doing something wrong? I am a C# developer by trade and looking for a new challenge by jumping to Java for a while. Thanks for the quick responce and help !

Here is my entry class:

package lasso;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowListener;

import java.awt.event.WindowEvent;

import baseWizard.*;

public class LassoWizard extends javax.swing.JFrame implements baseWizard.WizardListener {

/** Creates new form LassoWizard */

public LassoWizard() {

initComponents();

this.setTitle("");

this.setResizable(false);

this.addWindowListener(createAppCloser());

wizard1.addWizardListener(this);

wizard1.start(new WelcomeStep());

wizard1.setVisible(true);

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

private void initComponents() {

wizard1 = new baseWizard.Wizard();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

wizard1.setMaximumSize(new java.awt.Dimension(700, 500));

getContentPane().add(wizard1, java.awt.BorderLayout.CENTER);

pack();

}

// </editor-fold>

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new LassoWizard().setVisible(true);

}

});

}

private static WindowListener createAppCloser() {

return new WindowAdapter() {

public void windowClosing(WindowEvent we) {

System.exit(0);

}

};

}

/** Called when the wizard finishes.

* @param wizard the wizard that finished.

*/

public void wizardFinished(Wizard wizard) {

System.out.println("wizard finished");

System.exit(0);

}

/** Called when the wizard is cancelled.

* @param wizard the wizard that was cancelled.

*/

public void wizardCancelled(Wizard wizard) {

System.out.println("wizard cancelled");

System.exit(0);

}

/** Called when a new panel has been displayed in the wizard.

* @param wizard the wizard that was updated

*/

public void wizardPanelChanged(Wizard wizard) {

System.out.println("wizard new panel");

}

// Variables declaration - do not modify

private baseWizard.Wizard wizard1;

// End of variables declaration

}

jake99a at 2007-7-14 19:38:12 > top of Java-index,Java Essentials,New To Java...
# 3
Do this NetBeans tutorial "Packaging and Deploying Desktop Java Applications", it should be close enough to serve as an example: http://www.netbeans.org/kb/articles/javase-deploy.html
ChuckBinga at 2007-7-14 19:38:12 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks, just what I needed :)
jake99a at 2007-7-14 19:38:12 > top of Java-index,Java Essentials,New To Java...
# 5

> It just blows my mind how everything runs great in

> the IDE as expected, but when you create the jar file

> you get nothing?

It shouldn't blow your mind. An IDE hides much of the complexity of compiling, deploying and running a java app for you. I've always had the opinion that people learning Java should use nothing more sophisticated than notepad/vi and the command line until they are comfortable with the java, javac, and jar commands. Once you have this foundation, *then* switch to the IDE to improve your productivity, not before.

bckrispia at 2007-7-14 19:38:12 > top of Java-index,Java Essentials,New To Java...
# 6

Did you set the size for the window.

That is a common mistake that many people make. If you do not set the size you will only see a small title bar at the top left corner of the desktop. Most of the times the developer do not notice that and think that window never appeared.

I searched in your code for setSize didnt found any matches. Next time you run the code check whether you see a samall title bar with minimize, maximze and close button at the top left corner of the desktop probably with a coffee cup icon on it.

LRMKa at 2007-7-14 19:38:12 > top of Java-index,Java Essentials,New To Java...
# 7

Hey jake99.

Two things in particular caught my attention:

import baseWizard.*;

This was the first major one. What is the baseWizard package? If you are referencing this package from the library manager in sun studio, this may be the problem. You see what happens is when you hit that magic button to compile your project, it packs a lovely little jar file for you, and dumbly forgets to package any supporting library files with it. You need to copy all your library jar files into the same directory and include them in the class path.

second thing.

For another reason, the magic button will not make an executable jar. Either that or I havent found out how to do it yet. I fixed the problem by manually creating the jar using the jar tool in the command prompt.

jar -cmf MANIFESTFILE myPackagedJar.jar *.java

where MANIFESTFILE contains the path to the class with main method. Doing this should enable an executable jar file.

Are you using windows? Another way to take the hassle out of all this stuff is to download Xenoage Java Exe Starter (free program) and construct an exe file that launches your jar file in all its glory. That way you can specify all libraries in the class path from just double clicking the out put file exe.

Hope this helps.

Jason Barraclough.

fireman.sparkeya at 2007-7-14 19:38:13 > top of Java-index,Java Essentials,New To Java...
# 8

final tip, just worked out you are using windows as you have javaw.exe

lol

Using that guy will prevent you from seeing a command prompt when running the java app(if memory serves me correct that is as I use linux)

Better to use java instead of javaw in the early stages as if it stuffs up, you will get the error messages fed to you to help you out a bit.

See ya!

fireman.sparkeya at 2007-7-14 19:38:13 > top of Java-index,Java Essentials,New To Java...