繁体   English   中英

闪屏可以在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()返回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文件一起移动。 我的Splash Screen的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中的清单是在这里创建的,这也是我最终意识到要添加启动画面标签的地方。

我对使用ANT有点陌生,因此,任何有关如何处理此问题或查找内容的建议都将受到赞赏。

这与Ant无关。 问题是-splash选项采用文件名 ,但是SplashScreen-Image清单属性必须引用jar条目 如果com/example/brian/image.PNG不在.jar文件中,则SplashScreen-Image将无法使用它。 .jar文件的目的是充当独立的模块或应用程序,因此它应包括其所需的所有资源。

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

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

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

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

我可以在../jre/lib/Java.exe中使用Java二进制文件运行,但最初是从../lib/Java.exe运行的。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM