2015-09-10 43 views
1

我写了下面的Ant目标:使用Ant和genJar创建一个可运行的jar

<target name="approval_request_parser_compile"> 
     <taskdef resource="genjar.properties" classpath="GenJar.jar"/> 
     <genjar jarfile="prod/lib/approvalRequestParser.jar"> 

      <class> 
       <fileset dir="."> 
       <include name="com.bet.Check.class"/> 
        <include name="com.bet.Approve.class"/> 
        <include name="com.bet.CheckText.class"/> 
        <include name="com.bet.Request.class"/> 
        <include name="com.bet.ApprovalRequestParser.class"/> #contains the main method 
       </fileset> 
      </class> 
      <classpath> 
       <fileset dir="lib"> 
        <include name="*.jar" /> 
       </fileset> 
       <pathelement path="."/> 
      </classpath> 
     </genjar> 
    </target> 

罐子创建成功,但是当我去/生产/ lib和I型:

java -jar approvalRequestParser.jar 

引发此错误:

no main manifest attribute, in approvalRequestParser.jar 

任何想法?

回答

0

我不使用genjar,但你需要创建清单文件,请参见下面

<target name="buildJAR" depends="compile"> 
    <tstamp> 
    <format property="BUILD.TSTAMP" pattern="MMMM dd yyyy hh:mm:ss" locale="en"/> 
    </tstamp> 
    <buildnumber file="build.number"/> 
    <mkdir dir="classes/META-INF"/> 
    <echo file="classes/META-INF/version.txt">Version: ${VERSION} (build #: ${build.number}, ${BUILD.TSTAMP})</echo> 
    <manifest file="classes/META-INF/MANIFEST.MF"> 
     <attribute name="Specification-Title" value="ANY TEXT CAN GO HERE"/> 
     <attribute name="Specification-Version" value="${VERSION}"/> 
     <attribute name="Specification-Vendor" value="COMPANY NAME"/> 
     <attribute name="Implementation-Title" value="WHAT CODE DOES"/> 
     <attribute name="Implementation-Version" value="${VERSION} (build #: ${build.number}, ${BUILD.TSTAMP})"/> 
     <attribute name="Implementation-Vendor" value="WHO DOES IT"/> 
    </manifest> 
    <jar destfile="JAR FILE" basedir="classes" 
     includes="${CORE_CODE}" manifest="classes/META-INF/MANIFEST.MF"/> 
</target> 

一个例子,我认为你可以将相同的genjar任务

相关问题