Java使用外部jar创建独立jar [英] Java create standalone jar with external jars
问题描述
我为我的应用程序开发了两个.jar(LOG.jar和STRING.jar)。
I developed two .jar for my application (LOG.jar and STRING.jar).
我使用这些jar,在.java中导入:
I use these jar, with import in .java :
import LOG.CLog
import STRING.CString
没关系。但.jar在我的项目中正在增加,所以我想只创建一个包含所有.jar开发的.jar。
It's OK. But .jar is increasing in my project, so I would like to create only one .jar which includes all .jar developed.
所以我通过创建唯一一个来尝试这个.jar(名为TOOLS.jar):
So I tried this by creating the only one .jar (named TOOLS.jar) :
jar.exe cvmf MANIFEST.MF TOOLS.jar TOOLS\LOG.jar TOOLS\STRING.jar
但是,如果我在我的应用程序编译中只放置TOOLS.jar文件(Java在Eclipse中构建路径),当我想导入时出错:
But, if I put only TOOLS.jar file in my application compilation (Java build path in Eclipse), I get error when I want to import :
import TOOLS.LOG.CLog
无法解析此导入。
并且在Eclipse中引用库,我看到包含STRING.jar和LOG.jar的包PXTOOLS,但我没有看到STRING和LOG包!
And In Eclipse "referenced libraries", I see package PXTOOLS which includes both STRING.jar and LOG.jar, but I don't see STRING and LOG package !
我该如何解决?
推荐答案
我使用这些jar,导入.java
:
I use these jar, with import in .java :
import LOG.CLog import STRING.CString
import LOG.CLog import STRING.CString
Yo你通过用包名来限定类来导入类;不是直接来自JAR文件。我希望你的包被称为 LOG
,类是 CLog
这里(虽然使用大写包名称是一个错误的命名约定)
You import classes by qualifying them with package names; not directly from JAR files. I hope your package is called LOG
and class is CLog
here (though it's a bad naming convention to have uppercase package names)
其次,不建议将JAR文件合并为一个。最好将它们分开。如果您想要合并,则必须确保先提取所有类文件然后合并。
Secondly, merging JAR files into one isn't recommended. It's best to keep them separate. If at all you did want to merge, you must ensure that you extract all the class files first and then merge.
这篇关于Java使用外部jar创建独立jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!