问题
I developed two .jar for my application (LOG.jar and STRING.jar).
I use these jar, with import in .java :
import LOG.CLog
import STRING.CString
It's OK. But .jar is increasing in my project, so I would like to create only one .jar which includes all .jar developed.
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
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
This import cannot be resolved.
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 !
How can I fix it ?
回答1:
I use these jar, with import in .java :
import LOG.CLog import STRING.CString
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)
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.
回答2:
You cannot include jars in a jar file. If you want to deliver just one jar, check out tools like One-Jar. They can package a working jar for you.
回答3:
I use these jar, with import in .java :
import LOG.CLog import STRING.CString
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)
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.
Yes, you can do so. Have a look here - Build Java entire project jar using JDeveloper
来源:https://stackoverflow.com/questions/5218966/java-create-standalone-jar-with-external-jars