I'm trying to generate the (.JAR) file using NetBeans 11.0, I have followed some answers like How to create a Jar file in Netbeans but I don't find the Packaging under Build, Also I tried to Clean & Build Project but I can't find /dist
folder.
Can anyone help me
LOG :
Scanning for projects...
------------------------------------------------------------------------
Building FlickerURLMaker 1.0-SNAPSHOT
------------------------------------------------------------------------
--- maven-clean-plugin:2.5:clean (default-clean) @ FlickerURLMaker ---
Deleting C:\Users\USER\Documents\NetBeansProjects\FlickerURLMaker\target
--- maven-resources-plugin:2.6:resources (default-resources) @ FlickerURLMaker ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\Users\USER\Documents\NetBeansProjects\FlickerURLMaker\src\main\resources
--- maven-compiler-plugin:3.1:compile (default-compile) @ FlickerURLMaker ---
Changes detected - recompiling the module!
Compiling 2 source files to C:\Users\USER\Documents\NetBeansProjects\FlickerURLMaker\target\classes
--- maven-resources-plugin:2.6:testResources (default-testResources) @ FlickerURLMaker ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\Users\USER\Documents\NetBeansProjects\FlickerURLMaker\src\test\resources
--- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ FlickerURLMaker ---
Nothing to compile - all classes are up to date
--- maven-surefire-plugin:2.12.4:test (default-test) @ FlickerURLMaker ---
No tests to run.
--- maven-jar-plugin:2.4:jar (default-jar) @ FlickerURLMaker ---
Building jar: C:\Users\USER\Documents\NetBeansProjects\FlickerURLMaker\target\FlickerURLMaker-1.0-SNAPSHOT.jar
--- maven-install-plugin:2.4:install (default-install) @ FlickerURLMaker ---
Installing C:\Users\USER\Documents\NetBeansProjects\FlickerURLMaker\target\FlickerURLMaker-1.0-SNAPSHOT.jar to C:\Users\USER\.m2\repository\maa\FlickerURLMaker\1.0-SNAPSHOT\FlickerURLMaker-1.0-SNAPSHOT.jar
Installing C:\Users\USER\Documents\NetBeansProjects\FlickerURLMaker\pom.xml to C:\Users\USER\.m2\repository\maa\FlickerURLMaker\1.0-SNAPSHOT\FlickerURLMaker-1.0-SNAPSHOT.pom
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 2.613 s
Finished at: 2019-06-26T10:26:33+01:00
Final Memory: 16M/170M
------------------------------------------------------------------------
POM.xml :
<?xml version="1.0" encoding="UTF-8"?>
<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>maa</groupId>
<artifactId>FlickerURLMaker</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
STRUCTURE :
This is a maven
project. In maven projects, when you build the jar file it will be in the target
folder. But if you use any dependencies it will not attach them to that build jar
automatically. You need to add the following code to the pom.xml
file.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Commonly this goal is tied to a build phase to execute automatically. So when you build your project, at that time your fat.jar
file will be available in your target folder.
So in your case your pom.xml
file should be like this,
<?xml version="1.0" encoding="UTF-8"?>
<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>maa</groupId>
<artifactId>FlickerURLMaker</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>maa.flickerurlmaker.URLMaker</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>