Java 如何在 Eclipse 中运行 jar 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4505372/
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
How to run a jar file in Eclipse
提问by stevebot
I tried to run a jar file by going to Run configurations and then creating a new Java App, but Eclipse wants me to give it a main class and reference to the project. Can't I just give Eclipse a jar file?
我试图通过转到运行配置然后创建一个新的 Java 应用程序来运行一个 jar 文件,但是 Eclipse 希望我给它一个主类和对项目的引用。我不能只给 Eclipse 一个 jar 文件吗?
采纳答案by Isaac Truett
You could run the JAR with an "External Tool" launch configuration, found at Run > External Tools > External tools Configurations.
您可以使用“外部工具”启动配置运行 JAR,该配置可在运行 > 外部工具 > 外部工具配置中找到。
回答by Vince
Is the jar file you provided have "public static void main(String [] arg)" method ? In order for java to run your and application, a main class with a "public static void main(String [] arg)" method must exist. So that jvm will understand the starting execution point of your jar.
您提供的 jar 文件是否具有“public static void main(String [] arg)”方法?为了让 Java 运行您的应用程序,必须存在具有“public static void main(String [] arg)”方法的主类。这样 jvm 就会理解你的 jar 的起始执行点。
回答by j040p3d20
Try the following command line
试试下面的命令行
C:\Program Files (x86)\Java\jdk1.6.0_24\bin\javaw.exe
with the following arguments (one per line)
带有以下参数(每行一个)
-cp C:\dev\tcpmon-1.0-bin\build\tcpmon-1.0.jar
org.apache.ws.commons.tcpmon.TCPMon
回答by GermanK
You cannot directly execute a jar file. Instead, you need to run it using the java -jar
command. In order to do that you:
您不能直接执行 jar 文件。相反,您需要使用java -jar
命令运行它。为了做到这一点,你:
- Go to Run > External Tools > External tools Configurations
- Create an item under "Program"
Fill in:
Location:
/usr/bin/java
(or the route to your java executable, in Linux you can find this by runningwhich java
on a terminal, in Windows you can usewhere java
in command prompt)Working directory: The working directory for your jar program (usually its location)
Arguments:
-jar [path to your jar]
- 转到运行 > 外部工具 > 外部工具配置
- 在“程序”下创建一个项目
填写:
位置:(
/usr/bin/java
或到您的 java 可执行文件的路径,在 Linux 中您可以通过which java
在终端上运行来找到它,在 Windows 中您可以where java
在命令提示符下使用)工作目录:jar 程序的工作目录(通常是它的位置)
参数:
-jar [path to your jar]
回答by TastyCode
回答by Robert H?glund
回答by Gabriel Angelo Parcon
Try running 'java -jar yourprogramname' in a console.
尝试在控制台中运行“java -jar yourprogramname”。