如何从 NetBeans IDE 外部运行 .jar 可执行 java 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/176902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 10:54:45  来源:igfitidea点击:

How do I run a .jar executable java file from outside NetBeans IDE?

javaexecutable-jar

提问by

How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?

如何从 NetBeans IDE 外部运行 .jar 可执行 java 文件?(Windows Vista)。我的项目有一个由 Netbeans 创建的 .jar 文件。我们想运行它。要么:我们如何运行文件或如何在 NetBeans 6.1 中创建一个“正确的”可执行文件?

回答by Laplie Anderson

Running a jar is as simple as

运行 jar 很简单

java -jar filename.jar

回答by Josh Moore

from a command prompt you can run this command: java -jar your_jar.jar.

从命令提示符可以运行此命令:java -jar your_jar.jar

回答by Brian Gianforcaro

You can do it from the command prompt if java isn't in your path by finding the full path to your java install, something like:

如果 java 不在您的路径中,您可以通过查找 java 安装的完整路径,从命令提示符执行此操作,例如:

C:\java\java.exe -jar C:\jar_you_want_to_run.jar

or if java is in your path:

或者如果 java 在您的路径中:

java.exe -jar jar_you_want_to_run.jar

This will run the jar produced by netbeans.

这将运行由 netbeans 生成的 jar。

回答by anjanb

as Laplie said, java -jar your.jar

正如 Laplie 所说, java -jar your.jar

EXECUTABLE file : see this thread for answers How can I convert my Java program to an .exe file?

可执行文件:请参阅此线程以获取答案如何将我的 Java 程序转换为 .exe 文件?

回答by Richard Walton

In the project properties dialog in NetBeans you need to set the Main Class - otherwise the generated .jar will not be executable. Then, as already indicated, either double clicking on the .jar or the command java -jar will start the program.

在 NetBeans 的项目属性对话框中,您需要设置主类 - 否则生成的 .jar 将无法执行。然后,如前所述,双击 .jar 或命令 java -jar 将启动程序。

回答by Galghamon

First, make sure you set the Main Class in your NetBeans project properties dialog.
Then, you can either

首先,确保在 NetBeans 项目属性对话框中设置主类。
然后,您可以

  • Double-click the jar file (This should work on any machine with an installed JRE)
  • 双击 jar 文件(这应该适用于任何安装了 JRE 的机器)

or

或者

  • Make sure that java.exe is in the path (or replace javabelow with the fullpath and file name of the executable), put the following in a batch file:
    java -jar filename.jar
    Then you can double-click the batch file instead of the jar (useful if you have people unaccustomed to using naked jar files)
  • 确保 java.exe 在路径中(或用java可执行文件的完整路径和文件名替换下面的内容),将以下内容放入批处理文件中:
    java -jar filename.jar
    然后您可以双击批处理文件而不是 jar(如果您有没有人不习惯使用裸 jar 文件)

OR

或者

回答by Mr. Brahm Deo Sah

One of the best technique to run the jar file or jar jar file

运行 jar 文件或 jar jar 文件的最佳技术之一

  1. Create the jar file by jar command choose your jar filename Java_Jar_File.jar
  2. Run the jar file us the command like java -jar Java_Jar_File.jar
  1. 通过 jar 命令创建 jar 文件选择你的 jar 文件名 Java_Jar_File.jar
  2. 运行 jar 文件我们像这样的命令 java -jar Java_Jar_File.jar

回答by Raahil

Make a BAT file with

制作一个BAT文件

java -jar filepath.jar

回答by Jithin

To run a java jar file its file association should be properly configured. There is a free tool called jarfixto fix all jar file association problems. Run this file to fix all jar issues.

要运行 java jar 文件,应正确配置其文件关联。有一个名为jarfix的免费工具可以修复所有 jar 文件关联问题。运行此文件以修复所有 jar 问题。

回答by Jirik

If you have problems with running your jar, make sure you are trying to run your current version to get newest version in Netbeans: GoTo Run Menu--> Clean and build

如果您在运行 jar 时遇到问题,请确保您正在尝试运行当前版本以获取 Netbeans 中的最新版本:GoTo Run Menu-->Clean and build