"没有主要的清单属性"

时间:2014-10-13 09:50:00

标签: java eclipse ant

您好我正在开发一个项目,我被告知创建dist ant目标,它创建JAR文件和jrun目标,这取决于dist目标ant应该运行dist创建的jar文件。虽然ant jrun我得到了以下错误:jrun [java]: no main manifest attribute in *\build\jar\navus.jar

 <?xml version="1.0" encoding="UTF-8"?>

<project name="POS" default="build" basedir=".">

<!-- Project properties-->

<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main.class" value="ee.ut.math.tvt.navus.Intro"/>

<!-- Different classpaths form compiling and running-->

<path id="compile.classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
        </fileset>
</path>

    <path id="run.classpath">
            <pathelement location="${classes.dir}"/>
            <path refid="compile.classpath"/>
        </path>


<!-- Clean existing build-->
<target name="clean">
    <delete dir="${build.dir}" />


</target>



<!-- Builds Java code-->

<target name="build" depends="clean">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${classes.dir}"/>
    <copy file="${src.dir}/log4j.properties" todir="${classes.dir}" overwrite="true" />

    <javac 
        srcdir="${src.dir}" 
        destdir="${classes.dir}">
        <classpath refid="compile.classpath"/>
    </javac>
</target>

<!-- Creates jar file-->

<target name="dist" depends="build"> 
    <mkdir dir="${jar.dir}"/>
    <propertyfile file="version.properties">
        <entry key="build.revision.number" type="int" default="0" operation="+"/>
    </propertyfile>

    <jar jarfile="${build.dir}/jar/navus.jar"
         basedir="${build.dir}/classes">
        <manifest>
            <attribute name="mainClass" value="${main.class}"/>         
        </manifest>
        <fileset dir="${basedir}" includes="${src.dir}"/>

        </jar>
</target> 

<!-- Executes application via class Intro-->


    <target name="run"  depends="build"
    description="runs introUI via Intro" >
      <java classname="${main.class}"

        classpathref="run.classpath"
        fork="yes">

      </java>
    </target>


<!-- Runs application using JAR file-->

<target name="jrun" depends="dist"
    description=" Run JAR file">
    <java jar="${jar.dir}/navus.jar" 
    fork="yes"/>

</target>


</project>

2 个答案:

答案 0 :(得分:1)

看看谷歌返回https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html。也许尝试这样的事情 -

<target name="jar">
    <mkdir dir="build/jar"/>
    <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
        <manifest>
            <attribute name="Main-Class" value="oata.HelloWorld"/>
        </manifest>
    </jar>
</target>

答案 1 :(得分:0)

您需要创建一个清单文件(MANIFEST.MF),该文件位于jar内的META-INF文件夹中。它类似于:

Manifest-Version: 1.0
Application-Name: MyApp
Sealed: true
Main-Class: com.mysite.myappname.myMainClass
Codebase: www.mysite.com