在Ant中输出java任务

时间:2021-05-07 18:34:50

I have a .java file and am compiling it using javac in ant. The .class file goes to output directory. A.class when ran, produces a.txt.

我有一个.java文件,并在ant中使用javac编译它。 .class文件转到输出目录。运行时的A.class,生成a.txt。

How to run the ant ´java´ task and where will the a.txt go, when ran? I mean which directory? Can I specify the direc. where the output files of java task should go?

如何运行ant'java'任务,a.txt将在何处运行?我的意思是哪个目录?我可以指定direc吗? java任务的输出文件应该去哪里?

1 个解决方案

#1


Take a look at this for reference:

看看这个参考:

http://ant.apache.org/manual/Tasks/java.html

It contains an example of using the Java task to run a specific class, e.g:

它包含使用Java任务运行特定类的示例,例如:

<target name="run">
     <java classname="A">
             <classpath>
               <pathelement location="output"/>
               <pathelement path="${java.class.path}"/>
             </classpath>
     </java>
</target>

It really depends on where you are writing the file out to from A.java. If it is in the current directory, e.g:

这实际上取决于你从A.java写出文件的位置。如果它在当前目录中,例如:

File f = new File("./test.txt");
f.createNewFile();

then it will output the file relative to where you ran the build file from.

然后它将输出相对于您运行构建文件的位置的文件。

Hope that helps.

希望有所帮助。

#1


Take a look at this for reference:

看看这个参考:

http://ant.apache.org/manual/Tasks/java.html

It contains an example of using the Java task to run a specific class, e.g:

它包含使用Java任务运行特定类的示例,例如:

<target name="run">
     <java classname="A">
             <classpath>
               <pathelement location="output"/>
               <pathelement path="${java.class.path}"/>
             </classpath>
     </java>
</target>

It really depends on where you are writing the file out to from A.java. If it is in the current directory, e.g:

这实际上取决于你从A.java写出文件的位置。如果它在当前目录中,例如:

File f = new File("./test.txt");
f.createNewFile();

then it will output the file relative to where you ran the build file from.

然后它将输出相对于您运行构建文件的位置的文件。

Hope that helps.

希望有所帮助。