简体   繁体   中英

Set java entrypoint to a class that's in a JAR inside another JAR

I have a JAR that's packaged with One Jar, so it contains multiple dependencies inside itself(using the JAR URL notation):

<one.jar>!/lib/<deps1.jar>
<one.jar>!/lib/<deps2.jar>
...

Is it possible to run main() from a class com.example.A that lives in deps2.jar ?

I tried java -cp one.jar!/lib/deps2.jar com.example.A , but that doesn't work.

You can include a main() somewhere in your primary .jar that delegates to com.example.A.main(). This will give you the behavior you seek with just a few additional lines of code...a small additional class definition file. For example:

package foo.bar;

import com.example.A;

class MainEntryDelegate {
    public static void main(String... args) {
        com.example.A.main(args);
    }
}

So your app will then be runnable via the obvious:

java -cp one.jar foo.bar.MainEntryDelegate

or if you've set up your manifest correctly:

java -jar one.jar

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