-2

I created a library which uses the bluecove library. It works well but when I export the library into jar, and include into the other project, it looks that it can't found the bluecove class files.

Exception in thread "main" 
    java.lang.NoClassDefFoundError: javax/bluetooth/LocalDevice

I think there is a problem about exporting the jar with the dependencies. How can I export my java library as jar including the bluecove as well in Eclipse?


please explain why downvoted this question? It would be great to give some reason, letting me improve my question.

icedwater
  • 4,701
  • 3
  • 35
  • 50
Gergely Fehérvári
  • 7,811
  • 6
  • 47
  • 74
  • 3
    Don't do that. It will ruin digital signatures & quite possibly the manifest of the 3rd party API. Simply ensure the dependent Jar is on the run-time class-path. – Andrew Thompson May 13 '13 at 09:35
  • Do as Andrew advices, or if you really want to include the library, see [Eclipse Java; export jar, include referenced libraries, without fatjar](http://stackoverflow.com/questions/528007/eclipse-java-export-jar-include-referenced-libraries-without-fatjar) or use the [Fat Jar plugin](http://fjep.sourceforge.net/) – Xavi López May 13 '13 at 09:36
  • Thank you, but why is it a bad question? Sorry for duplicate I didnt found that with google. – Gergely Fehérvári May 13 '13 at 09:45
  • Here is how to do that with Eclipse: http://stackoverflow.com/questions/11033603/how-to-create-a-jar-with-external-libraries-included-in-eclipse – hamid May 13 '13 at 09:51
  • Take a look at the fat-jar plugin for eclipse. It can help you to achieve what you are looking for [Link](http://fjep.sourceforge.net/) – Logard May 13 '13 at 09:38
  • You should use separeted jars and include them in your classpath. – mauretto May 13 '13 at 09:36

2 Answers2

2

If you want to have one big jar that contains your code and all your dependencies, you could use tools such as Jar Jar Links (https://code.google.com/p/jarjar/). This tool allows you to repackage multiple JARs in a single JAR.

But I would simply quote Andrew Thompson: "Don't do that. It will ruin digital signatures & quite possibly the manifest of the 3rd party API. Simply ensure the dependent Jar is on the run-time class-path"

Algiz
  • 1,258
  • 9
  • 20
0

If you use a build file like ant you can use the jar task to add all your jars dependencies into one which we have successfully done on a number of projects but as Algiz pointed out you will run into problems with some jars which require their manifest files.

There are ways around this.

Shawn Vader
  • 12,285
  • 11
  • 52
  • 61