简体   繁体   中英

Add additional .jar libraries when creating a runnable .jar via command line

Am working to reproduce the "export runnable .jar file" functionality of Eclipse with command-line calls directly from the java program itself. So those commands shall execute after Eclipse has compiled the project. I need this for better control what files are ending up in the .jar and to speed up the development process.

The following command successfully packs the structure and classes from the "bin" directory and also creates a manifest.mf file with the correct main class so the myjar.jar is runnable.

ProcessBuilder builder = new ProcessBuilder("jar", "cvfe", "myjar.jar", "main.MainControler", "-C", "bin", "/");

Process process = builder.start();

However my project has several libraries (.jar files) added to the classpath via the class-path dialogues of Eclipse. For example I'm using the pi4j library. I expected that that its internal directory and class structure (something like "com.pi4j.***.class") would be added to the "bin" directory when eclipse compiles and executes the program. However it is not there and therefore that never ends up in the "myjar.jar" either (and I get class-missing errors when running the .jar).

When I use Eclipse' export function, the files are there though.

What do I need to do to have the .class files from the additional .jar libraries exported so they can be added?

Huge thanks in advance :)

Your problem statement is not very clear and gives me the impression that you are trying to do something that should not be done.

First of all: if you don't want to use Eclipse to build the project then avoid using it to perform the first part of the work (ie compilation): you can perform the whole process from command line and this will give you even more control on the build process.

Second suggestion: do not reinvent the wheel. If you want to build from command line you can use Ant or Maven . In particular you can use Eclipse to generate an Ant build script that performs like "export runnable .jar file" then you can customize that script as you want: in Eclipse right-click on the project then select

Export / General / Ant Buildfiles

and you'll get a build.xml script to be used with Ant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM