Search code examples
javanetbeansantsplash-screen

Splash-Screen works in IDE but not as .jar - issue with ANT?


I'm attempting to add a splash-screen to a large Java project. The application is compiled into an executable .jar file using ANT.

I am able to get the splash screen working easily from NetBeans by simply adding -splash:src/com/.../.../image.PNG to my main project's VM options. However, adding SplashScreen-Image: com/.../.../image.PNG to my manifest file fails with "SplashScreen.getSplashScreen() returned null"

I have already opened up my .jar archive to confirm that things were set up correctly: my META-INF\MANIFEST.MF file includes the SplashScreen-Image line. I have tried moving it before or after Main-Class. My actual image.PNG is also in the archive, in the correct path location.

I compile this java project with ANT, which I can guess is the source of my problems (I was able to make a simple, "jar cmf ..." example work just fine).

I use the following to get the project elements ready for achiving:

   <target name="compile" depends="init"
        description="Compile the source">
    <!-- Compile the java code from ${src} into ${build} -->
    <path id="lib.path.ref">
      <fileset dir="${path_to_jre}" includes="*.jar"/>
    </path>
    <javac srcdir="${src}" destdir="${build}" source="${java_ver}" target="${java_ver}"
        includeantruntime="false">
      <!--compilerarg value="-Xbootclasspath/p:${toString:lib.path.ref}" compiler="javac1.7"/-->
      <compilerarg value="-Xlint:unchecked"/>
      <classpath>
        <fileset dir="${LibDir}">
          <include name="*.jar"/>
        </fileset>
        <pathelement path="${dependant_jar}"/>
        <pathelement path="${another_dependant_jar}"/>
      </classpath>
    </javac>
    <!-- Copy the .png files -->
    <copy todir="${build}">
      <fileset dir="${src}" casesensitive="false">
        <include name="**/*.PNG"/>
      </fileset>
    </copy>
  </target>

Notice that I use a copy to move .PNG files in with .class files. My image.PNG for the Splash Screen is just in with the others. I added it to my netbeans project by simply copying it there - nothing fancy.

My achieve target is as follows:

   <target name="archive" depends="compile"
        description="Generate the .jar file">
    <!-- Put everything in ${build} into the .jar file -->
    <jar jarfile="${jarfile}" basedir="${build}">
      <!-- Merge in contents of dependency .jars -->
      <zipfileset src="${LibDir}/snakeyaml.jar"/>
      <zipfileset src="${dependant_jar}"/>
      <zipfileset src="${another_dependant_jar}"/>
      <!-- Specify main class in manifest -->
     <manifest>
        <attribute name="SplashScreen-Image" value="com/../../image.PNG"/>
            <attribute name="Main-Class" value="${mainclass}"/>
         </manifest>
    </jar>
   </target>

So my manifest in the eventual .jar is created here, which is also where I eventually realized to add the splashscreen tag.

I am somewhat new to working with ANT, so any advice regarding how to handle this or what to look for is appreciated.


Solution

  • I have a solution, although I'm sure someone else will understand this better than I do.

    I was able to run, with a splash-screen, using the Java binary in ../jre/lib/Java.exe, however I had initially been working from ../lib/Java.exe.

    Looks like this is a known bug? Link here: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=7129420. I guess the path to the SplashScreen dll is hardcoded.

    Note: Thanks to user VGR for the exhaustive help.