1

I wrote a Java GUI program in Netbeans IDE 8.0.1 called SampleChat and used the 'clean and build' function to create a jar file.

I went to the 'dist' directory that Netbeans created and double-clicked the jar file it produced. A cmd window opened with the following line:

"Error: could not find or load main class.

However, when I opened cmd, changed to the same 'dist' directory and typed the command:

java -jar "SampleChat.jar"

the program ran just fine.

Can I not use Netbeans to create jar files that execute on double-click?

I did not use any pre-existing jar files to complete the program, hence, there was no 'lib' directory or anything like that.

I intend to share programs from a USB stick so it is vital that the only requirement is a JVM, mouse and maybe some fingers to double-click it.

An awkward solution I came up with is to write a batch file that runs the program, but it requires the jar file to not be moved around - screw that.

So how do I make my programs double-click executable?

Dziugas
  • 1,500
  • 1
  • 12
  • 28

1 Answers1

0

I guess you are missing to create a manifest file. Therefore it's unknown what your mainclass is. In your java command executed from a terminal you defined the mainclass to execute.

From the tasks you mentioned I guess you are using gradle to build your jar?

Here http://www.gradle.org/docs/current/userguide/java_plugin.html in chapter 23.14.1 an example of an manifest is given.

If you add attributes 'Main-Class': 'com.project.MainClass' it should work.

BR

questionaire
  • 2,475
  • 2
  • 14
  • 28
  • I don't understand how I defined the main class to execute from a terminal. I only specified the jar file? – Dziugas Dec 11 '14 at 20:04
  • Sorry my bad, did you try to add the manifest to your gradle task? Of course you have to add there the location of your mainclass and not of your jar... – questionaire Dec 11 '14 at 20:07
  • found solution at [jar file created in netbeans not executing](http://stackoverflow.com/questions/14143015/jar-file-created-in-netbeans-not-executing?rq=1) – Dziugas Dec 11 '14 at 20:10