JAR中的类文件似乎被忽略了;类文件是从classpath上的目录中挑选的
我正在尝试在CLI上执行一个简单的JAR文件(没有清单)。文件夹结构如下:
mods\un.jar
out\test\Main.class
src\test\Main.java
这是main.java
:
package test;
public class Main{
public static void main(String []args){
System.out.println("Unnamed module...");
}
}
这是来自根文件夹的命令:
javac -d out src\Main.java
java -cp out test.Main - this works
jar -cvf mods\un.jar out\test\Main.class
java -cp mods\un.jar;out test.Main - works (when 'out' is in classpath)
java -cp mods\un.jar test.Main - ERROR
最后一行生成错误:
Error: Could not find or load main class test.Main
Caused by: java.lang.ClassNotFoundException: test.Main
我已经查看了罐子拉链,看起来还可以。 ustest.mf是默认一个,但这是可以的,因为我明确地告诉java从shot(main()类)开始。内容是:
META-INF\MANIFEST.MF
out\test\Main.class
清单本身是:
,
Manifest-Version: 1.0
Created-By: 11 (Oracle Corporation)
因此看起来罐子中的类文件根本没有被捡起。如果我在运行java
时省略out
文件夹,或者如果我在out
out 文件夹中重命名.class
文件),我发现没有发现错误。我想在没有明显的情况下使它起作用。
有什么想法吗?
谢谢, seán。
I am trying to get a simple JAR file executing on the CLI (without a manifest). The folder structure is as follows:
mods\un.jar
out\test\Main.class
src\test\Main.java
Here is Main.java
:
package test;
public class Main{
public static void main(String []args){
System.out.println("Unnamed module...");
}
}
Here are the commands from the root folder:
javac -d out src\Main.java
java -cp out test.Main - this works
jar -cvf mods\un.jar out\test\Main.class
java -cp mods\un.jar;out test.Main - works (when 'out' is in classpath)
java -cp mods\un.jar test.Main - ERROR
The last line generates the errors:
Error: Could not find or load main class test.Main
Caused by: java.lang.ClassNotFoundException: test.Main
I have looked at the JAR zip and it looks ok. The MANIFEST.MF is the default one but that is okay as I am explicitly telling Java what class to start with (the class with main()). The contents are:
META-INF\MANIFEST.MF
out\test\Main.class
The manifest itself is:
Manifest-Version: 1.0
Created-By: 11 (Oracle Corporation)
So it looks like the class file in the JAR is not being picked up at all. If I omit the out
folder when I run java
or if I rename the .class
file in the out
folder), I get the class not found error. I would like to get it working without a manifest.
Any ideas?
Thanks,
Seán.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更改为“ OUT”目录,以使您的软件包在JAR中正确正确:
You need to change to the 'out' directory to get your package root correct in the jar: