0

Recently I developed a fairly simple GUI application in NetBeans, and before I take the development any further I decided to test the application on another computer since I don't know a lot about distributing an application and wanted to make sure I was doing it right.

In NetBeans it runs fine, and when I click Run->Clean and Build Project it creates the .jar file as expected in the dist folder of my project. When I run the .jar file on my computer from the dist folder it runs as expected.

Then I tried running it several different ways on another computer (from a flash drive), none of which worked:

  1. Copied only the jar file to my flash drive, tried to run it, got an error saying "Could not find the main class: MyApplicationPackage.MyApplication. Program will exit."

  2. In NetBeans clicked File->Export Project->To Zip... and copied the zipped folder to my flash drive. When I unzipped the file on the other computer there is no dist folder (I didn't really expect there to be one).

  3. Copied the entire project folder onto my flash drive, and tried to run the jar file on the other computer, generating the same error message.

How can I get it to run on other computers? And is there an easier way to distribute applications? I don't expect the average person to know how to unzip a file, find the dist folder, and run the jar file. Could I combine everything into one runnable file somehow?

EDIT: I found the solution on my own: The version of java on the other computer was not the current version. To make the application run I opened the properties window of the project, and under the "Sources" tab there is an option near the bottom that says "Source/Binary Format". Changing it to an earlier version of Java let it run on the other computer. Another (and better) option would be to just upgrade to the current version of Java on the other computer.

Nathan Bucki
  • 33
  • 1
  • 6

1 Answers1

1

you have to check if there is a MANIFEST file that will indicate where is located the main class.

if you are using maven, you can use the assembly plugin and it will generate your MANIFEST file with the arguments you've specified.

<plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
                <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                        <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>com.blabla.Main</mainClass>
                        </manifest>
                        <manifestEntries>
                                <SplashScreen-Image>splashscreen.png</SplashScreen-Image>
                        </manifestEntries>
                </archive>
        </configuration>

</plugin>

EDIT:

Community
  • 1
  • 1
Pierre
  • 59
  • 4
  • I opened the jar file with 7-zip and found the MANIFEST.MF file which contains the following: Manifest-Version: 1.0 Ant-Version: Apache Ant 1.8.3 Created-By: 1.7.0-b147 (Oracle Corporation) Class-Path: X-COMMENT: Main-Class will be added automatically by build Main-Class: MyApplicationPackage.MyApplication So the MANIFEST.MF file does indicated where the main class is. I have no idea what Maven is, or what the code you posted means, could you explain your response to my question? And I apologize for not knowing how to add newlines in this comment to make it more readable. – Nathan Bucki Nov 15 '12 at 22:40