蚂蚁编译但不运行或创建jar

时间:2018-07-01 18:30:32

标签: java eclipse ant

下面的Ant构建成功编译。

不幸的是,尽管depends属性指定在编译步骤成功完成后执行运行目标,但它不会执行运行步骤。

它也不会在指定的类路径中创建jar文件。

build.xml

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

<project default="run" name="My Project">
<target name="run" depends="compile">
    <java classname="com.company.program.project">
        <classpath path="staging\" location="C:\my_work\Eclipse\3.6-64\plugins\"/>
    </java>
</target>

<target name="compile">
<javac includeantruntime="false" srcdir="./src" destdir="staging">
    <classpath>
        <fileset dir="C:\my_work\Eclipse\3.6-64\plugins">
            <!-- <include name="**/*.jar" /> -->
            <include name="org.eclipse.swt.*.jar" />
        </fileset>
    </classpath>
</javac>
</target>

<jar destfile="./build/jars/swtgui.jar" filesetmanifest="mergewithoutmain">
     <manifest>
      <attribute name="Main-Class" value="org.swtgui.MainGui" />
      <attribute name="Class-Path" value="." />
    </manifest>

    <fileset dir="./bin/com/company/program/project" includes="**/*.class" />
    <fileset dir="C:\my_work\Eclipse\3.6-64\plugins\" includes="org.eclipse.swt.win32.win32.x86_64_3.6.0.v3650b.jar" />

</jar>

<record name="./project.log" loglevel="verbose" action="start"/>

编辑:已运行。没有编辑build.xml,但是转到Project Explorer -> build.xml -> External Tool Configurations -> Build -> Targets,由于某种原因,未检查运行目标。

我检查了它,现在run目标运行了,但是在下面产生了错误日志。

run:
 [java] running com.company.project.program with default permissions     (exit forbidden)
     [java] Running in same VM Executing 'com.company.project.program'
The ' characters around the executable and arguments are
not part of the command.
     [java] Could not find com.company.project.program. Make sure you have it in your classpath
    at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:140)
    at org.apache.tools.ant.taskdefs.Java.run(Java.java:834)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:228)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:137)
    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:110)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
at         org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at     org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:36)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:460)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:142)
         [java] Java Result: -1
    run:  duration 0 seconds
    BUILD SUCCESSFUL

    BUILD SUCCESSFUL

我是否需要再对xml文件进行编辑以使其运行并创建jar?

1 个答案:

答案 0 :(得分:1)

您的jar步骤不在“目标”中。创建一个名为“ jar”的目标,该目标依赖于“ compile”,创建一个jar(您的“ jar”块应在此处工作),并具有目标“ run”。

您似乎还需要将创建的jar添加到“运行”“ java”类路径中。