来自 netbeans 的 .jar 将无法在控制台中打开
.jar from netbeans will not open in console
在 netbeans 中构建了一个简单的 java 程序,build/compiled 它并在项目目录中为我生成了一个 .jar。
以下是我的src代码:
import java.util.Scanner;
public class Welcome {
public static void main(String[] args){
System.out.println("Welcome to Java");
Scanner input = new Scanner(System.in);
}
}
我希望能够在控制台中打开它以使用扫描仪功能,但我似乎无法打开 jar。
我尝试使用以下命令从命令行打开它:
java -jar "C:\Users\Nick\Documents\NetBeansProjects\JavaApplication1\dist\JavaApplication1.jar"
但是没有骰子。双击 .jar 也打不开。
有什么想法吗?
此致
如果您想使用 -jar
启动它,您需要将其构建为 运行nable jar
见https://docs.oracle.com/javase/tutorial/deployment/jar/run.html
You can run JAR packaged applications with the Java launcher (java
command). The basic command is:
java -jar jar-file
The -jar flag tells the launcher that the application is packaged in
the JAR file format. You can only specify one JAR file, which must
contain all of the application-specific code.
Before you execute this command, make sure that the runtime
environment has information about which class within the JAR file is
the application's entry point.
To indicate which class is the application's entry point, you must add
a Main-Class header to the JAR file's manifest. The header takes the
form:
Main-Class: classname
The header's value, classname, is the name of the class that is the
application's entry point.
另一种方法是 运行 通过指定 class 路径和主要 class
使用它
java -cp "C:\Users\Nick\Documents\NetBeansProjects\JavaApplication1\dist\JavaApplication1.jar" Welcome
在 netbeans 中构建了一个简单的 java 程序,build/compiled 它并在项目目录中为我生成了一个 .jar。
以下是我的src代码:
import java.util.Scanner;
public class Welcome {
public static void main(String[] args){
System.out.println("Welcome to Java");
Scanner input = new Scanner(System.in);
}
}
我希望能够在控制台中打开它以使用扫描仪功能,但我似乎无法打开 jar。
我尝试使用以下命令从命令行打开它:
java -jar "C:\Users\Nick\Documents\NetBeansProjects\JavaApplication1\dist\JavaApplication1.jar"
但是没有骰子。双击 .jar 也打不开。
有什么想法吗?
此致
如果您想使用 -jar
启动它,您需要将其构建为 运行nable jar见https://docs.oracle.com/javase/tutorial/deployment/jar/run.html
You can run JAR packaged applications with the Java launcher (java command). The basic command is:
java -jar jar-file
The -jar flag tells the launcher that the application is packaged in the JAR file format. You can only specify one JAR file, which must contain all of the application-specific code.
Before you execute this command, make sure that the runtime environment has information about which class within the JAR file is the application's entry point.
To indicate which class is the application's entry point, you must add a Main-Class header to the JAR file's manifest. The header takes the form:
Main-Class: classname
The header's value, classname, is the name of the class that is the application's entry point.
另一种方法是 运行 通过指定 class 路径和主要 class
使用它java -cp "C:\Users\Nick\Documents\NetBeansProjects\JavaApplication1\dist\JavaApplication1.jar" Welcome