Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Producing executable jar in NetBeans

I'm using NetBeans 6.5 and for some reason it won't produce executable jar "out of the box".

I set my project to be the main project, defined main class in the project properties "run" menu and it works flawlessly when I press F6 to run it.

I looked at the manifest file and it indeed didn't define the main class there, and also omitted the library dependencies.



Am I missing something? Is there a way (other than manually altering the manifest file) to produce executable jar files?

EDIT: yes, I tried clean and rebuild and it produced the jar in the dist folder, still with the same manifest.mf

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 10.0-b23 (Sun Microsystems Inc.)
like image 351
Dani Avatar asked Mar 02 '09 14:03

Dani


People also ask

How do I make an executable jar file?

Right click on your Java Project and select Export. Select Java -> Runnable JAR file -> Next. Select the Destination folder where you would like to save it and click Finish.

How do I create an executable Java project in NetBeans?

Netbeans does that automatically, just do clean and build (hammer sybol) and look in the dist subdirectory of your project. There will be the JAR with lib folder containing the required libraries. These JAR + lib are enough to run the application.


2 Answers

I just had the same problem in NetBeans 7.2.1 with a Maven Java Application project. Modify the pom.xml file to include the maven assembly plugin with one tweak to myrho's answer (needs to reference the predefined descriptor "jar-with-dependencies"):

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>your.app.MainClass</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

An alternate method is to build a Java Application project in NetBeans that doesn't use Maven. Select File -> Project Properties -> Build -> Packaging and check the "Copy Dependent Libraries" checkbox.

like image 127
rarchibald Avatar answered Oct 26 '22 15:10

rarchibald


Try this:

  1. Right click your project on the "Projects" panel, select "Properties"

  2. Click on "Run" in the new window.

  3. Edit the "Main Class:" field (click on Browse).

This way you will select the main class which is the entry point to your application and the Manifest will be created correctly.

like image 26
kv. Avatar answered Oct 26 '22 15:10

kv.