Johan
Johan

Reputation: 3819

Exporting a Java Project as .jar with including .java source code and preserving external libraries dependecies

I know how to export a Java Project as a .jar including also .java source code (just export it as a plain .jar), and how how to export it as a runnable .jar including only .class files (just select the runnable .jar export style). If the project doesn't have dependecies on external libraries, I noticed that both .jar run correctly by command line.

Problem: if the project contains dependecies on some external library added in the Build Path, it results that the .jar exported as runnable correctly works while a plain .jar doesn't because the external libraries are not anymore found when launching from command line.

Annotation: external libraries are added as .jar in a folder "lib" in the project and from there added to the Build Path.

I want to be able to export the Java project while either including the .java source code and preserving the dependencies on external libraries so that it will run when launching it by command line. Any suggestion? All that I can find out is "just export it as runnable .jar", but this will hide the .java source codes.

EDIT: Can anyone explain why this happens?

Upvotes: 2

Views: 1455

Answers (1)

idengler
idengler

Reputation: 36

If you don't need an automated way you can achieve it with following manual steps:

  • First export it as runnable jar (a.jar)
  • Second export as jar with source (b.jar)
  • Use 7-zip or other archive tool to integrate the sources into the runnable jar. Open both jars and drag the folder containing the sources (first part of package name) from jar (b.jar) into the z-zip window of runnable jar (a.jar)

Upvotes: 1

Related Questions