在 Eclipse 中打包到 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15523046/
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
Package to jar in eclipse
提问by jsj
UPDATE: Don't worry. User Error. Would delete the question but cant with answers.
更新:别担心。用户错误。会删除问题,但不能提供答案。
I am trying to use eclipse to create a jar of packages, nota runnable jar, which I can import into another project.
我正在尝试使用 eclipse 创建一个包的jar,而不是一个可运行的 jar,我可以将其导入到另一个项目中。
So far I have done this:
到目前为止,我已经这样做了:
- Create a new project
- Create a package in that project (pkg.nme.with.dots)
- Create a class in that package
- Export -> Java -> Jar
- 创建一个新项目
- 在该项目中创建一个包 (pkg.nme.with.dots)
- 在该包中创建一个类
- 导出 -> Java -> Jar
The resultant .jar file has only one directory META-INF
, and three files .project
, .classpath
, and MyClass.class
.
得到的.jar文件只有一个目录META-INF
,和三个文件.project
,.classpath
和MyClass.class
。
If I try to import pkg.nme.with.dots.MyClass;
I get a package not found error, despite adding the full path of the jar to my CLASSPATH.
如果我尝试import pkg.nme.with.dots.MyClass;
,尽管将 jar 的完整路径添加到我的 CLASSPATH 中,我仍会收到未找到包的错误。
I tried adding the jar as an external lib in eclipse but it is still not recognised.
我尝试将 jar 添加为 eclipse 中的外部库,但仍然无法识别。
Obviously I have exported it into a format that can't be import
ed. How do I export it correctly?
很明显我已经导出成无法import
编辑的格式了。如何正确导出?
回答by greenkode
@trideceth12 I just tested exporting a sample package in my eclipse. and my folder structure works fine. not sure why yours is not working properly. you should check all your export settings. here's what mine looks like, and it exports fine.
@trideceth12 我刚刚测试了在我的 eclipse 中导出一个示例包。我的文件夹结构工作正常。不知道为什么你的不能正常工作。您应该检查所有导出设置。这是我的样子,而且出口很好。
回答by Mr.Cool
回答by Himanshu Bhardwaj
Look like your Java source is in Default package only. If you want to use this kind of import statement, considering moving the jar file to:
看起来您的 Java 源代码仅在默认包中。如果要使用这种导入语句,可以考虑将 jar 文件移动到:
pkg/nme/with/dots