Splash-Screen 在 IDE 中工作,但不能作为 .jar - ANT 的问题?

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

我正在尝试向大型 Java 项目添加启动画面。使用 ANT 将应用程序编译成可执行的 .jar 文件。

只需将 -splash:src/com/.../.../image.PNG 添加到我的主项目的 VM 选项中,我就可以从 NetBeans 轻松启动启动画面。但是,将 SplashScreen-Image: com/.../.../image.PNG 添加到我的清单文件失败并显示 "SplashScreen.getSplashScreen() returned null"

我已经打开我的 .jar 存档以确认设置正确:我的 META-INF\MANIFEST.MF 文件包含 SplashScreen-Image 行。我试过在 Main-Class 之前或之后移动它。我的实际 image.PNG 也在存档中,在正确的路径位置。

我用 ANT 编译了这个 java 项目,我猜这是我的问题的根源(我能够制作一个简单的 "jar cmf ..." 示例工作得很好)。

我使用以下方法准备好要实现的项目元素:

   <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>

请注意,我使用副本将 .PNG 文件与 .class 文件一起移动。我的启动画面 image.PNG 与其他的一样。我通过简单地将它复制到那里将它添加到我的 netbeans 项目中 - 没什么特别的。

我的实现目标如下:

   <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>

所以我在最终 .jar 中的清单是在这里创建的,这也是我最终意识到添加 splashscreen 标签的地方。

我对使用 ANT 有点陌生,所以任何关于如何处理这个问题或寻找什么的建议都将不胜感激。

这不是 Ant 的问题。问题是the -splash option takes a file name, but the SplashScreen-Image manifest attribute must refer to a jar entry。如果 com/example/brian/image.PNG 不在 .jar 文件中,则 SplashScreen-Image 将无法使用它。 .jar 文件的目的是充当 self-contained 模块或应用程序,因此它应该包含它需要的所有资源。

解决方案是将图像包含在您的 .jar 文件中:

<jar jarfile="${jarfile}" basedir="${build}">
    <fileset dir="${src}" includes="**/*.PNG"/>

更新:您的构建文件已经通过 <copy> 任务将图像添加到 .jar,但我没有注意到它。

我有一个解决方案,尽管我相信其他人会比我更了解这一点。

我能够 运行,使用 splash-screen,使用 ../jre/lib/Java.exe 中的 Java 二进制文件,但是我最初是从 . ./lib/Java.exe。

看起来这是一个已知错误? Link 这里:https://bugs.java.com/bugdatabase/view_bug.do?bug_id=7129420。我想 SplashScreen dll 的路径是硬编码的。

注意:感谢用户 VGR 提供的详尽帮助。