antでJavaプログラムをビルドでき、正しく構成されています。しかし、Antを使用してコンソールでSystem.out.println / System.out.printをどのように表示するのでしょうか?
注:私はantを使用したことがなく、探索しようとしています。私の質問が愚かではないことを願っていますか?
シンプルなプログラム
package antTesting;
public class Helloworld
{
/**
* @param args
*/
public static void main( String[] args )
{
System.out.println( " hello there !!!! " );
}
}
同じためのbuild.xml
<?xml version="1.0"?>
<project name="Ant-Test" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}">
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\de.vogella.build.test.ant.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="test.Main" />
</manifest>
</jar>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
</target>
</project>
私がrun > ant
CMDで
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:C:\PROGRA~2\HP\Sprinter\
bin\JAVA_S~1\classes;C:\PROGRA~2\HP\Sprinter\bin\JAVA_S~1\classes\jasmine.jar
Buildfile: C:\Users\ms025226\workspace\TestingWorld\build.xml
clean:
[delete] Deleting directory C:\Users\ms025226\workspace\TestingWorld\build
[delete] Deleting directory C:\Users\ms025226\workspace\TestingWorld\docs
[delete] Deleting directory C:\Users\ms025226\workspace\TestingWorld\dist
makedir:
[mkdir] Created dir: C:\Users\ms025226\workspace\TestingWorld\build
[mkdir] Created dir: C:\Users\ms025226\workspace\TestingWorld\docs
[mkdir] Created dir: C:\Users\ms025226\workspace\TestingWorld\dist
compile:
[javac] C:\Users\ms025226\workspace\TestingWorld\build.xml:26: warning: 'inc
ludeantruntime' was not set, defaulting to build.sysclasspath=last; set to false
for repeatable builds
[javac] Compiling 1 source file to C:\Users\ms025226\workspace\TestingWorld\
build
jar:
[jar] Building jar: C:\Users\ms025226\workspace\TestingWorld\dist\de.vogel
la.build.test.ant.jar
docs:
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
[javadoc] Loading source file C:\Users\ms025226\workspace\TestingWorld\src\Hel
loworld.java...
[javadoc] Constructing Javadoc information...
[javadoc] Standard Doclet version 1.6.0_31
[javadoc] Building tree for all the packages and classes...
[javadoc] Building index for all the packages and classes...
[javadoc] Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
[javadoc] Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:C:\PROGRA~2\
HP\Sprinter\bin\JAVA_S~1\classes;C:\PROGRA~2\HP\Sprinter\bin\JAVA_S~1\classes\ja
smine.jar
[javadoc] Building index for all classes...
main:
BUILD SUCCESSFUL
Total time: 2 seconds
クラスパスのターゲットを定義すると、エラーが発生します
<!-- to printoutputs -->
<target name="Helloworld" description="Hello world">
<java classname="antTesting.Helloworld">
<arg value="arg1"/>
<arg value="arg2"/>
</java>
</target>
<target name="main" depends="compile, jar, docs, Helloworld">
<description>Main target</description>
</target>
エラー:
Helloworld:
[java] Could not find antTesting.Helloworld. Make sure you have it in your classpath
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:138)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:597)
[java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[java] at org.apache.tools.ant.Task.perform(Task.java:348)
[java] at org.apache.tools.ant.Target.execute(Target.java:357)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[java] at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[java] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:423)
[java] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:137)
[java] Java Result: -1