运行 没有 IDE 的 GUI 应用程序

Running GUI Application without IDE

假设我使用 NetBeans 构建了一个 GUI 应用程序。对于 运行 这个 java 应用程序,我需要在 IDE 中打开源代码,然后在 运行 中打开源代码。我知道我也可以通过命令提示符运行。

但是如何独立于 IDE 启动应用程序。是不是有一些 .exe 文件或类似的东西,直接双击 运行 应用程序?

如果没有,如何生成这样的文件?

构建应用程序后,在项目文件夹中查找名为 "dist" 的文件夹。你应该找到一个 *.jar 文件,它可以在任何地方双击 运行。

在这里您可以找到如何在 Netbeans 中创建 .jar:How to create a Jar file in Netbeans 您可以在每台计算机上 运行 可执行 jar,前提是系统已安装 JRE。 如果需要,您还可以使用命令行构建 .jar,为此使用以下命令:

jar cf jar-file input-file(s)

来自 Oracle 文档的描述:

The options and arguments used in this command are:

The c option indicates that you want to create a JAR file. The f option indicates that you want the output to go to a file rather than to stdout. jar-file is the name that you want the resulting JAR file to have. You can use any filename for a JAR file. By convention, JAR filenames are given a .jar extension, though this is not required. The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file. The input-file(s) argument can contain the wildcard * symbol. If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively. The c and f options can appear in either order, but there must not be any space between them.

This command will generate a compressed JAR file and place it in the current directory. The command will also generate a default manifest file for the JAR archive.

要遵循的步骤:

  1. 创建一个 jar
  2. 运行 罐子