1

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 ?

TheFrancisOne
  • 2,477
  • 7
  • 33
  • 56

3 Answers3

1

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.

nfechner
  • 16,559
  • 7
  • 43
  • 63
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.

adarshr
  • 57,189
  • 21
  • 133
  • 158
  • Thanks, that answer my question about jar organization. So, I will make my application call every .jar I developed ! Thanks. – TheFrancisOne Mar 07 '11 at 12:45
0

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

Community
  • 1
  • 1
sgsg
  • 1