Java 从 cmd 运行 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4219341/
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
Running jar from cmd
提问by
I have seen a lot of posts and found lots of data on the net about this but I am still confused.
我看过很多帖子,在网上找到了很多关于这方面的数据,但我仍然很困惑。
I have downloaded a .jar file and I need to increase its heap size. I have added the jre1.6/bin in the Path of Windows 64 bit and I run from cmd.
我已经下载了一个 .jar 文件,我需要增加它的堆大小。我在 Windows 64 位路径中添加了 jre1.6/bin 并从 cmd 运行。
The problem arises that it says unable to access jar file.
出现的问题是它说无法访问 jar 文件。
Can anybody explain in some detail what should I do to run it from cmd. Do i need to add the location of jar file into the Path too ?? Also I have noticed that in many posts they tell to change the classpath but I have'nt done anything as such.
任何人都可以详细解释我应该怎么做才能从cmd运行它。我是否也需要将 jar 文件的位置添加到路径中??我还注意到,在许多帖子中,他们告诉更改类路径,但我没有这样做。
Do tell if you need any extra information.
请告诉您是否需要任何额外信息。
------------------------------- (Update)
- - - - - - - - - - - - - - - - (更新)
This is really wierd ..... I did it what was mentioned in here and now the program loads and then exits with Out of memory error saying that it needs more heap size even though it was working before with 128 m heap size. This happens when I increase it to 1024m. Can anybosy explain why the error could have come. I have 3GB Ram so I don't understand it.....
这真的很奇怪......我做了这里提到的事情,现在程序加载然后退出,出现内存不足错误,说它需要更多的堆大小,即使它之前使用 128 m 堆大小工作。当我将其增加到 1024m 时会发生这种情况。任何人都可以解释为什么会出现错误。我有 3GB 内存,所以我不明白.....
采纳答案by jjnguy
The following should run the jar:
以下应该运行jar:
java -Xmx1024m -jar /path/to/the/jar.jar
If you are running the command from the directory that the Jar is in, you can just specify it by name. Otherwise you need to qualify the path to the Jar in order for Java to be able to find it.
如果您从 Jar 所在的目录运行命令,则只需按名称指定即可。否则,您需要限定 Jar 的路径,以便 Java 能够找到它。
回答by Chris
From your "C:\Program Files\Weka-3-6" folder:
从您的“C:\Program Files\Weka-3-6”文件夹中:
java -Xmx1024m -jar weka.jar