简体   繁体   English

java“错误无法打开文件” jar

[英]java “error cannot open file” jar

I can't run the class or jar file it gives me the "Error cannot open file". 我无法运行类或jar文件,它给了我“错误无法打开文件”。

I'm using the following commands: 我正在使用以下命令:

javac src/*.java

jar cfe MyJar.jar src.Main src/*.class

java -jar MyJar.jar

Output: 输出:

javac src/*.java
jar cfe MyJar.jar src.Main src/*.class
java -jar MyJar.jar
Error cannot open file
C^%    

I'm using linux/ubuntu and java: 我正在使用linux / ubuntu和java:

java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

Content of MANIFEST.MF: MANIFEST.MF的内容:

Manifest-Version: 1.0
Created-By: 1.6.0_24 (Sun Microsystems Inc.)
Main-Class: src.Main 

The error was actually output from the FileHandler class I made. 错误实际上是从我制作的FileHandler类输出的。 I feel kinda ashamed now. 我现在有点as愧。 I'm going to look into it why it didn't print more than the caught exception. 我将研究它为什么没有比捕获的异常打印更多的内容。 Thank you for taking your time and make me notice. 感谢您抽出宝贵的时间,并通知我。

I'm not convinced the error is actually on the java -jar command. 我不认为该错误实际上在java -jar命令上。 I suspect it's the jar command having a problem finding src.Main . 我怀疑这是jar命令在查找src.Main遇到问题。 Try jar cfe MyJar.jar src/*.class instead. 请尝试使用jar cfe MyJar.jar src/*.class

I am quite sure the error message should read: 我很确定错误消息应该显示为:

Error: Unable to access jarfile MyJar.jar

In any case, the actual file name would be printed. 无论如何,都将打印实际的文件名。

hence, I guess it is simply the code in the jar files that prints the error. 因此,我猜这只是jar文件中的代码会显示错误。

An easy test: 一个简单的测试:

jar -jar MyJar.jar "this is so stupid"

Is the output then 是输出

Error: cannot open file this is so stupid

If so, you consult your source code. 如果是这样,请查阅源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM