主类不能设置为现有类
我有一个构建设置,要求将我的类放入当前目录的子目录中的文件夹中。 IE,如果我位于“.”,那么类可能位于“./somewhere_else/”中。
问题是,当我这样做时,我无法为可以找到主类的 Main-Class 设置值。当我从“.”处的文件构建 jar 时,我没有问题,但以下所有主类尝试都会导致 java.lang.NoClassDefFoundError's:
Main-Class: ClassName
Main-Class: FolderName.ClassName
Main-Class: FolderName/ClassName
我应该使用什么?
I have a build setup that requires that my classes be put into a folder in a subdirectory of my current directory. I.E., if I'm at '.', then the classes could be in './somewhere_else/'
The problem is that when I do this I can't set a value for Main-Class that can find the main class. I have no problem when I build the jar from files at '.', but all the following attempts for main class result in java.lang.NoClassDefFoundError's:
Main-Class: ClassName
Main-Class: FolderName.ClassName
Main-Class: FolderName/ClassName
What should I be using?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
jar 中的类必须与包结构位于相同的目录结构中。
ClassName
(没有任何包)成为主类,它必须位于你的jar的根目录中。FolderName
中,则该名称必须是包名称,这意味着源文件的第一行(非空非注释)应该是包文件夹名称;
。如果您的问题只是构建设置 - 这不是问题,jar 外部目录的文件夹布局不一定与 jar 内部的布局相同。但如果文件夹结构适合包结构(可能还有上面的目录),它仍然有帮助。
The classes inside your jar have to be in the same directory structure as your package structure.
ClassName
(without any package) to be the main class, it has to be in the root directory of your jar.FolderName
, this same name has to be the package name, meaning the first (non-empty non-comment) line of your source file should bepackage FolderName;
.If your problem is only the build setup - this is not a problem, the folder-layout of your directories outside the jar does not necessarily have to be the same as the layout inside your jar. But it still helps if the folder-structure fits to the package-structure (with maybe additionally directories above).
我认为你应该简单地通过类名(没有目录结构)来引用Main-Class。将帮助您解决这个问题的是您放置的类路径。确保Main-Class目录位于类路径中。
I think you should reference Main-Class simply by the class name (without directory structure). What will help you solve this problem is what you put as the classpath. Make sure the directory of Main-Class is in the classpath.
如果您的
ClassName
位于包FolderName
中,那么它应该是:-顺便说一句,它们区分大小写。
If your
ClassName
resides in packageFolderName
, then, it should be:-They are case-sensitive, by the way.