关于Java:使用NetBeans 11.0生成.JAR文件

Generate .JAR file using NetBeans 11.0

我正在尝试使用NetBeans 11.0生成(.JAR)文件,我遵循了一些答案,例如如何在Netbeans中创建Jar文件,但是我没有在Build下找到Packaging,我也尝试了Clean&Build Project,但是 我找不到/dist文件夹。

谁能帮我

日志:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Scanning for projects...

------------------------------------------------------------------------
Building FlickerURLMaker 1.0-SNAPSHOT
------------------------------------------------------------------------

--- maven-clean-plugin:2.5:clean (default-clean) @ FlickerURLMaker ---
Deleting C:\\Users\\USER\\Documents\
etBeansProjects\\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\
etBeansProjects\\FlickerURLMaker\\src\\main\
esources

--- maven-compiler-plugin:3.1:compile (default-compile) @ FlickerURLMaker ---
Changes detected - recompiling the module!
Compiling 2 source files to C:\\Users\\USER\\Documents\
etBeansProjects\\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\
etBeansProjects\\FlickerURLMaker\\src\\test\
esources

--- 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\
etBeansProjects\\FlickerURLMaker\\target\\FlickerURLMaker-1.0-SNAPSHOT.jar

--- maven-install-plugin:2.4:install (default-install) @ FlickerURLMaker ---
Installing C:\\Users\\USER\\Documents\
etBeansProjects\\FlickerURLMaker\\target\\FlickerURLMaker-1.0-SNAPSHOT.jar to C:\\Users\\USER\\.m2\
epository\\maa\\FlickerURLMaker\\1.0-SNAPSHOT\\FlickerURLMaker-1.0-SNAPSHOT.jar
Installing C:\\Users\\USER\\Documents\
etBeansProjects\\FlickerURLMaker\\pom.xml to C:\\Users\\USER\\.m2\
epository\\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:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?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>
    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>

enter image description here

结构体 :

enter image description here


我将其视为maven项目。 在maven项目中,构建jar文件将位于target文件夹中。 但是,如果您使用任何依赖项,它将不会将它们附加到该版本jar。 您需要将以下代码添加到pom.xml文件中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<plugin>
  maven-assembly-plugin</artifactId>
  <configuration>
   
      <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>

通常,此目标与自动执行的构建阶段相关。 因此,在构建项目时,您的fat.jar文件将位于目标文件夹中。

因此,您的pom.xml文件应如下所示,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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>
    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>
                maven-assembly-plugin</artifactId>
                <configuration>
                   
                        <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>