It worth to mention that I am using maven as my build management tool. I have a jar (let's call it dep.jar
) which will be included into the final project (final.jar
) as dependency.
dep.jar
has a class with main method.
I need to have several entry points (classes with main methods) within my final.jar
's top level directory so I can use entry point depending on my need. Including one from dep.jar
.
I considered:
- Changing
META-INF/MANIFEST.MF
file within jar. As Oracle stated that is not possible to reference main classes inside jar's dependencies (BOOT-INF/lib
directory) -> https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html; - Uber jar - not an option, I am dependent on jar directory structure inside Java code base
- Using special class loader like this one http://www.jdotsoft.com/JarClassLoader.php. But it implies changing
final.jar
's main method which I cannot do due to project restrictions. - Using
maven-dependency-plugin
but it can unpack inner jar (dep.jar
) and copy classes to maven working directorytarget
which during packaging phase will be packed toBOOT-INF/classes
directory. Again, I cannot reference main classes from there. If I unpack and copy them somewhere different thantarget
- copied classes will not appear in myfinal.jar
Is there any other plugin or option how to add classes from final.jar
dependant jar dep.jar
during JAR build to final.jar
's top level?
EDIT:
final.jar
project looks like this:
final.jar
|_______BOOT-INF
|_______lib
| |_______dep.jar (contains main class I want to invoke)
|_______classes
|__________dir (directory I want to copy on demand with help of CLI)