gpt4 book ai didi

java - list 文件不是通过 ANT 生成的

转载 作者:行者123 更新时间:2023-12-02 04:26:28 24 4
gpt4 key购买 nike

未通过 ANT 生成 list 文件。从它的外观来看,应该生成一个 oata.HelloWorld,我假设它是 list 文件。但是,它不在 build/class 文件夹或 build/jar 文件夹中。我还通过 eclipse 运行 ANT

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

这是我的 xml 代码。

<?xml version="1.0" ?>

<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="lib.dir" value="../JAR/MarketPower Jars" />
<property name="Common.dir" value="../Common" />
<property name="CommonBin.dir" value="${Common.dir}/bin" />
</target>

<target name="prepare" depends="init">
<mkdir dir="${classes.dir}" />
</target>

<target name="compile" description="Compiles the code" depends="prepare">
<javac srcdir="${src.dir}" destdir="${classes.dir}">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>

<target name="jar" description="Packages the code into jar" depends="compile">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/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="build/jar/HelloWorld.jar" fork="true"/>
</target>

最佳答案

你的问题和你说的完全相反。 Jar 文件 list ,如知道主类 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

关于java - list 文件不是通过 ANT 生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32082933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com