Java “没有主要清单属性”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26337100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:16:12  来源:igfitidea点击:

"no main manifest attribute"

javaeclipseant

提问by Ollikas

Hi I'm working on a project where i'm told to create dist ant target which creates JAR file and jrun target which depends on dist target ant should run dist created jar file. While ant jrun i get the folowing error : jrun [java]: no main manifest attribute in *\build\jar\navus.jar

嗨,我正在做一个项目,我被告知要创建 dist 目标,它创建 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>

采纳答案by kayakpim

Looking at google returns https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html. Maybe try something like this -

查看谷歌返回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>

回答by MaKR

You need to create a manifest file (MANIFEST.MF), which goes inside the META-INF folder inside your jar. It resembles this:

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

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