Java: splash screen in a jar file run with the -cp option?

command-line, jar, java

Solution

I don't find your justification for doing this persuasive, but here's the way to make it work.

Set the environment variables `_JAVA_SPLASH_JAR` to the file system path to the JAR that contains the splash screen image, and `_JAVA_SPLASH_FILE` to the name of the splash screen file within that JAR. For example, in a `bash` or `sh` shell,

(export _JAVA_SPLASH_JAR=app.jar; \
 export _JAVA_SPLASH_FILE=META-INF/splash.jpg; \
 java -cp app.jar com.y.app.Main )

I think this approach is bad, because the environment variables are not documented as part of the `java` launcher interface, and implementation changes could break the splash screen or the entire launcher.

The explanation for using it is flimsy. Of course you wouldn't want any circular dependencies between the common library and the applications. But this has nothing to do with the archive structure. Why go to the trouble of removing the compile-time dependencies from the combo main class on the applications, when it has a strong runtime dependency on them?

This "common" main class is not part of the common library. It's another application. It would make more sense to allow it to have static dependencies on the applications, and to package it in a separate archive, with appropriate `Main-Class`, `Class-Path`, and `SplashScreen-Image` so that it can be launched with the `-jar` option. Then when your other applications are deployed individually, their common library won't contain the unnecessary combo application. And when a new version of Java is installed, the splash screen will display correctly instead of crashing the launcher.

Problem

Is it possible to put the splash screen image in the jar file and use the `-splash` option on the command line? Background: I have 3 jar files that have a fun dependency tree, where the main class I want to run is in the "common" jar (and it reflectively calls the main classes of the two other jars). So using the -jar command line is kind of out of the question. Yes, I know you can use the `SplashScreen-Image` line in the manifest, but all manifests seem to be ignored when using the -cp option of the java command line. I kind of want to keep resources self contained in the jars if possible, so I want one of the jars to hold the splash screen in question. But paths for the `splash` that follow "xx.jar!path", or "xx.jar/path" seem not to work. Is it possible, and how? EDIT: okay, let me try this again. I have three jars. One has graphics logic in it, let's call it the "UI", one has business logic in it, let's call it the "Core", and one has common classes between the two. Both the Core component and the UI component can be run as their own app, and they have their own main classes and their jars are set up to include the common jar on the class path. But the common jar has a class with a main method which calls both main classes. The common jar, being a library between the two, is not supposed to have the UI or Core jar as a dependency because either one of them could be missing if the components are run separately. All I want is a way to reference a splash screen packed in the UI jar when calling the main class in the common jar. I've already worked out the logistics of calling this common jar's main with the `-cp` option. It just doesn't have a proper splash screen yet. Is it possible, and how? (I was hoping to make this question generic and not include all that info, but whatever.)

Original source