Maven and Netbeans: how do I build project and get executable jar?

user1666562 :

I've just started standard Maven -> Java Application in Netbeans 7.4. It created "App" class (which has main method) by default. I also went to project's Properties->Run and set that class as a Main Class. I then built the project.

In the project's directory, I got the "target" folder with a couple of jars inside. None of them is the executable one. How do I simply fix the problem and get the executable jar at the end of each build?

thanks.

taringamberini :

This may be a little lack of integration between Netbeans and Maven.

Doing "Properties->Run and set that Main Class" in the IDE doesn't make Maven to set the main class in the MANIFEST.MF of the generated jar: you have to explicitly say to Maven which is the main class by adding the <mainClass> tag to the configuration of the maven-jar-plugin.

For example if your pom.xml were:

<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.taringamberini</groupId>
    <artifactId>AppTest</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.taringamberini.apptest.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

than in the target directory you would find the AppTest-1.0.0-SNAPSHOT.jar, and you should be able to run:

AppTest/target$java -jar AppTest-1.0.0-SNAPSHOT.jar
Hello World!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to build an executable jar from multi module maven project?

From Java

How to generate executable jar in JavaFX with maven project

From Dev

How do I add a jar-file to Ant for a NetBeans Java Web App project so that it gets build on Jenkins?

From Dev

How to create a executable jar file using Maven and Netbeans

From Dev

Maven: How to include my external jar into build executable jar

From Dev

How to build an maven executable jar with external jar library?

From Dev

How do I import a non-Maven Java project in Netbeans to a Maven project in Eclipse properly?

From Java

How do I create a standalone jar from a maven project?

From Java

How do I build a Java project in Eclipse, to create an external JAR

From Dev

Why executable jar file produced from netbeans doesn't work as I run project from Netbeans itslef?

From Dev

How to get CodenameOne Maven Project Running in Netbeans

From Dev

How to get Netbeans to increment version / build number of .WAR in Maven based project?

From Java

In netbeans 7 how do I skip testing and add maven additional parameters when building a maven project?

From Dev

How do I create an executable jar file including dependencies where the main class is in Test, using Maven

From Dev

How do I add a jar to netbeans 7.3.1?

From Java

How can I create an executable jar without dependencies using Maven?

From Java

How can I create an executable JAR with dependencies using Maven?

From Dev

How can I create an executable/runnable JAR with dependencies using Maven?

From Java

With Maven, how can I build a distributable that has my project's jar and all of the dependent jars?

From Dev

Make an executable JAR from a maven project

From Dev

How to build an executable jar in java

From Dev

How to build executable micronaut jar

From Java

how do i get a java maven build to fail for compiler warnings?

From Dev

Maven build for machine learning - how do I get it working?

From Java

How can I create single executable jar in my gradle project

From Dev

How do I get the direct (non transitive) dependencies of a Maven project?

From Java

Importing javaFX (.jar) files into a Netbeans Maven Project

From Dev

How do I grant 'all' permissions to a netbeans project? | netbeans 8.2

From

How to build GO executable with maven

Related Related

  1. 1

    How to build an executable jar from multi module maven project?

  2. 2

    How to generate executable jar in JavaFX with maven project

  3. 3

    How do I add a jar-file to Ant for a NetBeans Java Web App project so that it gets build on Jenkins?

  4. 4

    How to create a executable jar file using Maven and Netbeans

  5. 5

    Maven: How to include my external jar into build executable jar

  6. 6

    How to build an maven executable jar with external jar library?

  7. 7

    How do I import a non-Maven Java project in Netbeans to a Maven project in Eclipse properly?

  8. 8

    How do I create a standalone jar from a maven project?

  9. 9

    How do I build a Java project in Eclipse, to create an external JAR

  10. 10

    Why executable jar file produced from netbeans doesn't work as I run project from Netbeans itslef?

  11. 11

    How to get CodenameOne Maven Project Running in Netbeans

  12. 12

    How to get Netbeans to increment version / build number of .WAR in Maven based project?

  13. 13

    In netbeans 7 how do I skip testing and add maven additional parameters when building a maven project?

  14. 14

    How do I create an executable jar file including dependencies where the main class is in Test, using Maven

  15. 15

    How do I add a jar to netbeans 7.3.1?

  16. 16

    How can I create an executable jar without dependencies using Maven?

  17. 17

    How can I create an executable JAR with dependencies using Maven?

  18. 18

    How can I create an executable/runnable JAR with dependencies using Maven?

  19. 19

    With Maven, how can I build a distributable that has my project's jar and all of the dependent jars?

  20. 20

    Make an executable JAR from a maven project

  21. 21

    How to build an executable jar in java

  22. 22

    How to build executable micronaut jar

  23. 23

    how do i get a java maven build to fail for compiler warnings?

  24. 24

    Maven build for machine learning - how do I get it working?

  25. 25

    How can I create single executable jar in my gradle project

  26. 26

    How do I get the direct (non transitive) dependencies of a Maven project?

  27. 27

    Importing javaFX (.jar) files into a Netbeans Maven Project

  28. 28

    How do I grant 'all' permissions to a netbeans project? | netbeans 8.2

  29. 29

    How to build GO executable with maven

HotTag

Archive