开发者

JAVA swing application+executing jar

I'm a newbie to java programming. I downloaded netbeans (java EE) bundle in ubuntu and wrote a simple swing application which runs fine from with netbeans. I tried running it from the terminal by typing "java -jar " as netbeans suggested and i got "could not find main class" error. So i tried to check the classpath by using echo开发者_开发知识库 $CLASSPATH and got nothing. Then i set the classpath using $ set CLASSPATH=. When i again tried "java -jar , i got the same error (main class not found). echo $CLASSPATH again gives nothing even though i tried setting classpath. Please help! Thanks in advance


Provide an entry point to the graphical interface. I typically call this class Main

public class Main
{
    public static void main(String[] args) {

           java.awt.EventQueue.invokeLater(new Runnable() {
                   public void run() {
                       new MyJFrame();
                   }
               });  
          }
}

Next, click the Files tab (next to projects tab on the top left) and look for a file called Mainfest.mf. You will need to add a Main-Class: attribute to this file.

Main-Class: Main

This tells the jar what to execute when double-clicked or run from the command line.


I don't use Netbeans, but I do know what java wants on the command line when using the -jar option.

One possibility is the jar's manifest is missing a Main-class declaration. This declaration tells where the entry point for the program should be when using the -jar invocation option. It specifies a particular class having a main method.

To verify what I'm saying is the case, try the following on the jar produced by Netbeans (I'm assuming bash shell because of $ prompt in your question .. tell me if I'm wrong):

$ jar xf my.jar META-INF
$ cat META-INF/MANIFEST.MF | grep Main-Class

If that comes up empty, or doesn't name your class, then your next SO question might be "How do I tell Netbeans what class is the entry point when making a jar".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜