【发布时间】:2021-03-31 10:11:16
【问题描述】:
我已经用 NetBeans 中的 Swing GUI 完成了我的 Java 程序,并且已经构建、清理和运行它没有错误。但是,现在我希望将其保存为可运行的格式,我似乎错过了诀窍。我花了几个小时搜索并尝试了以下所有死胡同或多年来不适用的问题:
- 在 Eclipse 中打开程序并导出一个可运行的 .jar 文件
- 在 NetBeans 中运行“构建和清理”以生成“快照”.jar 文件
- 我尝试从命令行和提升的命令行运行这两个 .jar 文件,但出现不同的错误。
我感觉这与我的 pom.xml 文件有关,但正如我所说,我找不到任何东西,或者我完全没有抓住重点。
这是我的 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>com.OETrackerV0</groupId>
<artifactId>OETrackerV0</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
<type>jar</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>1.1</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>frameOne</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
</project>
如有必要,我很乐意编辑和发布其余代码,它也在我的 GitHub 上:https://github.com/ChaseVsGodzilla/oetracker.git
【问题讨论】:
-
“我尝试从命令行和提升的命令行运行这两个 .jar 文件,但出现不同的错误。”你是如何尝试运行它们的,你遇到了什么错误?这些都是需要在问题中提出的非常重要的细节。