使用Ant编译源代码时,出错:xxxxx.java is not a directory。谁遇到过,知道怎么解决吗?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Ant编译源代码时,出错:xxxxx.java is not a directory。谁遇到过,知道怎么解决吗?相关的知识,希望对你有一定的参考价值。

xxxxx.java就是我想要Ant帮我编译的源文件,结果出了上面所说的错。为什么Ant非要认为xxxxx.java这是一个目录呢?源文件我就是用了一个fileset,加了几个include与exclude稍微改变了一下文件集,以前只要指定目录就会自动找java文件去编译的啊。不知如何解决,请高手指教,在这里先谢过了!

<javac srcdir="$src.dir" 。。。。。。
ant编译的源文件输入是 srcdir,dir顾名思义就是目录的意思。
你可以将你的xxxxx.java所在的目录替换$src.dir,然后试试
<property name="src.dir" value="C:\Program Files\Java\"/>
参考技术A 我编译都是这么整:
<target name="build" description="Compile main source tree java files">
<mkdir dir="$build.dir"/>
<javac destdir="$build.dir" source="1.5" target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="$src.dir"/>
<classpath refid="master-classpath"/>
</javac>
</target>
给你一个建议,ant的具体用法是不需要太深入的了解,会读会用会改会copy,就能基本应付工作中所有问题了。我以前还是自己写ant,到后来发现没什么必要,现在用的ant就是从hibernate中帮助文档里找来的,功能很全面,常用的都有了。

<?xml version="1.0"?>

<project name="springmvc" basedir="." default="usage">
<property file="build.properties"/>

<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="$web.dir/WEB-INF/classes"/>
<property name="name" value="springmvc"/>

<path id="master-classpath">
<fileset dir="$web.dir/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<fileset dir="$appserver.lib">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="$build.dir"/>
</path>

<target name="usage">
<echo message=""/>
<echo message="$name build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> Build the application"/>
<echo message="deploy --> Deploy application as directory"/>
<echo message="deploywar --> Deploy application as a WAR file"/>
<echo message="install --> Install application in Tomcat"/>
<echo message="reload --> Reload application in Tomcat"/>
<echo message="start --> Start Tomcat application"/>
<echo message="stop --> Stop Tomcat application"/>
<echo message="list --> List Tomcat applications"/>
<echo message=""/>
</target>

<target name="build" description="Compile main source tree java files">
<mkdir dir="$build.dir"/>
<javac destdir="$build.dir" source="1.5" target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="$src.dir"/>
<classpath refid="master-classpath"/>
</javac>
</target>

<target name="deploy" depends="build" description="Deploy application">
<copy todir="$deploy.path/$name" preservelastmodified="true">
<fileset dir="$web.dir">
<include name="**/*.*"/>
</fileset>
</copy>
</target>

<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="$name.war"
webxml="$web.dir/WEB-INF/web.xml">
<fileset dir="$web.dir">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="$deploy.path" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>

<!-- ============================================================== -->
<!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
<!-- ============================================================== -->

<path id="catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir="$appserver.lib">
<include name="catalina-ant.jar"/>
</fileset>
</path>

<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>

<target name="install" description="Install application in Tomcat">
<install url="$tomcat.manager.url"
username="$tomcat.manager.username"
password="$tomcat.manager.password"
path="/$name"
war="$name"/>
</target>

<target name="reload" description="Reload application in Tomcat">
<reload url="$tomcat.manager.url"
username="$tomcat.manager.username"
password="$tomcat.manager.password"
path="/$name"/>
</target>

<target name="start" description="Start Tomcat application">
<start url="$tomcat.manager.url"
username="$tomcat.manager.username"
password="$tomcat.manager.password"
path="/$name"/>
</target>

<target name="stop" description="Stop Tomcat application">
<stop url="$tomcat.manager.url"
username="$tomcat.manager.username"
password="$tomcat.manager.password"
path="/$name"/>
</target>

<target name="list" description="List Tomcat applications">
<list url="$tomcat.manager.url"
username="$tomcat.manager.username"
password="$tomcat.manager.password"/>
</target>

<!-- End Tomcat tasks -->

<property name="test.dir" value="test"/>

<target name="buildtests" description="Compile test tree java files">
<mkdir dir="$build.dir"/>
<javac destdir="$build.dir" source="1.5" target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="$test.dir"/>
<classpath refid="master-classpath"/>
</javac>
</target>

<target name="tests" depends="build, buildtests" description="Run tests">
<junit printsummary="on"
fork="false"
haltonfailure="false"
failureproperty="tests.failed"
showoutput="true">
<classpath refid="master-classpath"/>
<formatter type="brief" usefile="false"/>

<batchtest>
<fileset dir="$build.dir">
<include name="**/*Tests.*"/>
</fileset>
</batchtest>

</junit>

<fail if="tests.failed">
tests.failed=$tests.failed
***********************************************************
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
***********************************************************
</fail>
</target>
<!-- clean -->
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="$build.dir">
<include name="**/*.class"/>
</fileset>
</delete>
</target>

<target name="undeploy" description="Un-Deploy application">
<delete>
<fileset dir="$deploy.path/$name">
<include name="**/*.*"/>
</fileset>
</delete>
</target>
</project>本回答被提问者采纳

以上是关于使用Ant编译源代码时,出错:xxxxx.java is not a directory。谁遇到过,知道怎么解决吗?的主要内容,如果未能解决你的问题,请参考以下文章

Jmeter 导入Eclipse,如何编译

ant打包出错 antuild.xml:698: null returned: 1

带有Selenium的Apache ANT:完整教程

ANT build.xml 编译出错Error running javac.exe compiler,详细情况如下:

使用 PhoneGap/Cordova 为 Android 构建时,在 Mac OS X 10.9 Mavericks 上执行命令“ant”时出错

使用 Apache Ant 而不是 Oracle SQL Developer 执行 SQL 时出错