【问题标题】:Configuration required for ant xml to build correct jar using java 1.8.0_40 and ant 1.9.0ant xml 使用 java 1.8.0_40 和 ant 1.9.0 构建正确 jar 所需的配置
【发布时间】:2017-01-31 21:27:28
【问题描述】:

我正在尝试使用 jdk 1.8.0_40 和 ant 版本 1.9.0 为我的项目构建 jar,jar 正在构建,但是在将此 jar 转换为 .exe 时,它​​无法找到我正确提到的主类我的主要课程。我正在使用 eclipse Mar 版本:Mars.2 Release (4.5.2)。

之前我使用的是 jdk 1.7.0_79 版本和 ant 1.8.4,一切正常。

我在从 jdk 1.7.0_79 升级到 jdk 1.8.0_40 时遇到问题。

下面是用于构建我的 jar 的我的 ant xml。让我知道 java 1.8 构建正确的 jar 是否需要任何配置。

<property name="jar.name" value="SAFAL.jar" />
<property name="source.root" value="src" />
<property name="class.root" value="bin" />
<property name="lib.dir" value="lib" />
<property name="jar.dir" value="C:\D\SAFAL-Exe" />
<property name="Main-Class" value="com.sungard.ktt.main.SAFALEval" />
<property name="conf.pkj" value="com/sungard/ktt/business/configurations" />
<property name="img.pkj" value="com/sungard/ktt/business/images" />

<path id="project.class.path">
    <pathelement location="${class.root}" />
    <fileset dir="${lib.dir}">
        <include name="*.jar" />
    </fileset>
</path>

<target name="clean" description="cleans up build structures">
    <delete dir="${class.root}" />
    <delete file="${jar.dir}/${jar.name}" />
</target>

<target name="prepare" description="sets up build structures">
    <mkdir dir="${class.root}" />
</target>

<target name="compile" depends="prepare" description="Compiles all java classes">
    <javac srcdir="${source.root}" destdir="${class.root}" debug="on" optimize="off" deprecation="on" source="1.8" target="1.8" includeantruntime = "false">

        <classpath refid="project.class.path" />
    </javac>

    <mkdir dir="${class.root}/${conf.pkj}" />
    <mkdir dir="${class.root}/${img.pkj}" />

    <copy todir="${class.root}/${conf.pkj}">
        <fileset dir="${source.root}/${conf.pkj}" />
    </copy>

    <copy todir="${class.root}/${img.pkj}">
        <fileset dir="${source.root}/${img.pkj}" />
    </copy>

</target>

<target name="jar" depends="compile"> 

    <delete file="${jar.dir}/${jar.name}" quiet="true" failonerror="false" />

    <jar destfile="${jar.dir}/${jar.name}">

        <fileset dir="${class.root}" includes="**/*.*" />
        <fileset dir="${source.root}" includes="**/api/*.java,**/api/vo/*.java"/>

        <zipgroupfileset dir="${lib.dir}" />


        <manifest>
            <attribute name="Main-Class" value="${Main-Class}" />
            <attribute name="Class-Path" value="." />
        </manifest>

    </jar>


</target>


<target name="run">
    <java fork="true" classname="${Main-Class}">
        <classpath>
            <path location="./${jar.name}" />
        </classpath>
    </java>
</target>

【问题讨论】:

    标签: java eclipse ant jar exe


    【解决方案1】:

    在您的 java 任务中,您使用 ./${jar.name} 作为 jar 的位置 - 这取决于正确设置的当前目录。您的所有其余代码都使用 ${jar.dir}/${jar.name} 作为 jar 的路径,因此更改 java 任务以执行相同的操作:

    <target name="run">
        <java fork="true" classname="${Main-Class}">
            <classpath>
                <path location="${jar.dir}/${jar.name}" />
            </classpath>
        </java>
    </target>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-06
      • 2013-09-23
      相关资源
      最近更新 更多