未通过ANT生成清单文件。从它的外观来看,应该生成一个oata.HelloWorld,我假设它是Manifest File。但是,它不在build / class文件夹或build / jar文件夹中。我也在通过eclipse运行ANT
SELECT @LDate = MAX('+QUOTENAME(@DateField)+')
这是我的xml代码。
Buildfile: C:\Users\dt208672\Perforce\depot\ebill\Automation\Selenium_eBill\MarketPower\build.xml
init:
prepare:
compile:
[javac] C:\Users\dt208672\Perforce\depot\ebill\Automation\Selenium_eBill\MarketPower\build.xml:18: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
jar:
run:
[java] Error: Could not find or load main class oata.HelloWorld
[java] Java Result: 1
答案 0 :(得分:2)
你的问题与你说的完全相反。 Jar文件只有 清单,如知道主类oata.HelloWorld
名称的错误消息所示。
您需要将已编译的.class文件添加到Jar文件中。
<jar destfile="build/jar/HelloWorld.jar">
<manifest>
<attribute name="Main-Class" value="oata.HelloWorld"/>
</manifest>
<fileset dir="${classes.dir}" includes="**/*.class"/>
</jar>
<强>更新强>
以下对我来说很好。
SRC \ oata \ HelloWorld.java :
package oata;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
的build.xml :
<project name="SeleniumProjectDataDriven" basedir="." default="run">
<target name="init">
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/class" />
<property name="jar.dir" value="${build.dir}/jar" />
</target>
<target name="compile" description="Compiles the code" depends="init">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" />
</target>
<target name="jar" description="Packages the code into jar" depends="compile">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/HelloWorld.jar" basedir="build/class">
<manifest>
<attribute name="Main-Class" value="oata.HelloWorld" />
</manifest>
</jar>
</target>
<target name="run" description="Run the jar file" depends="jar" >
<java jar="${jar.dir}/HelloWorld.jar" fork="true" />
</target>
</project>
输出:
compile:
Compiling 1 source file to C:\My\Workspaces\EMDRS\_test\build\class
jar:
Building jar: C:\My\Workspaces\EMDRS\_test\build\jar\HelloWorld.jar
run:
Hello World
BUILD SUCCESSFUL
Total time: 1 second