简体   繁体   English

如何在jar中导出项目的库?

[英]How can I export the libs of a project in the jar?

I'm making an Android library to implement generalized OAuth Authentication(both 1.0a and 2.0). 我正在制作一个Android库来实现通用OAuth身份验证(1.0a和2.0)。 I'm using the signpost libraries for signing the Http Requests. 我正在使用路标库对Http请求进行签名。 Now when I try to export my project as a .jar file(using Eclipse, right click on Project->Export->Java->Jar file), the jar gets created successfully, but it hasn't exported the signpost libraries. 现在,当我尝试将项目导出为.jar文件时(使用Eclipse,右键单击Project-> Export-> Java-> Jar文件),将成功创建jar,但尚未导出路标库。

When I open the .jar file, I find that the libraries are present, but they aren't visible to the project I'm importing it in. How can I expose these libraries from the jar? 当我打开.jar文件时,发现存在这些库,但是它们对我要导入的项目不可见。如何从jar中公开这些库?

EDIT: Once I import the library into my test application and call the function, OAuthFactory#authorize() (A custom class that handles OAuth authentication), I get the following compile error: The type oauth.signpost.exception.OAuthCommunicationException cannot be resolved. It is indirectly referenced from required .class files 编辑:将库导入我的测试应用程序并调用函数OAuthFactory#authorize() (处理OAuth身份验证的自定义类)后,出现以下编译错误: The type oauth.signpost.exception.OAuthCommunicationException cannot be resolved. It is indirectly referenced from required .class files The type oauth.signpost.exception.OAuthCommunicationException cannot be resolved. It is indirectly referenced from required .class files . The type oauth.signpost.exception.OAuthCommunicationException cannot be resolved. It is indirectly referenced from required .class files

this question has also been discussed here. 这个问题也在这里讨论。

How to combine library with my jar? 如何结合我的罐子图书馆?

Of course, you can extract the library-jars and add the extracted class-files into your own jar, but you would lose the clear view to the external lib's versions this way. 当然,您可以提取库jar并将提取的类文件添加到自己的jar中,但是这样会使外部lib版本失去清晰的视野。

The solution that works best for me is to ship your JAR-file with an additional folder that contains all external JAR-Files and then refer to them in your /META-INF/MANIFEST.MF: 最适合我的解决方案是将JAR文件与包含所有外部JAR文件的其他文件夹一起运送,然后在/META-INF/MANIFEST.MF中引用它们:

Class-Path: lib/kxml2-2.3.0.jar lib/log4j-1.2.16.jar

You can leave the JAR-Files external this way and won't have to blow up your own JAR-file. 您可以通过这种方式将JAR文件保留在外部,而不必炸毁自己的JAR文件。

Greetings 问候

Christopher 克里斯托弗

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

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