ANT - 由于找不到符号而导致javac编译失败

时间:2010-10-02 02:01:37

标签: ant compilation javac

我正在尝试编译ActionFactory.java文件,该文件导入我的一个包,RegisterAction.java

这是文件结构:

/com/masatosan/actions/register/RegisterAction.java

/com/masatosan/redirector/ActionFactory.java

根据ANT输出,我认为ANT找不到在ActionFactory.java中导入的RegisterAction.java

当我在控制台上手动运行javac时它会成功编译,所以这必须是ANT没有看到的一些类路径设置。

我知道我可以在ANT_HOME / lib中添加一些jar但在我的情况下,ANT似乎无法找到ActionRegister.java,而不是jar或其他东西。任何人都可以帮我找出问题所在吗?

ANT脚本

<project name="CompileMasatosan"  default="main"
    basedir="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan">
    <description>
        masatosan compiler
    </description>

    <!-- this invokes all targets -->
    <target name="main" depends="compileAll" />

     <!-- properties -->
    <property name="srcMasatosan" 
        location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan" />

    <property name="dest"
    location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes" />

    <property name="redirectorSrc" location="${srcMasatosan}\redirector" />

     <!-- complie -->
    <target name="compileAll">
        <javac target="1.5" source="1.5" srcdir="${redirectorSrc}" destdir="${dest}" />
    </target>

</project>

环境变量

ANT_HOME=C:\apache-ant-1.8.1-bin\apache-ant-1.8.1

 CLASSPATH=C:\Program Files\Java\jre6\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib;C:\Program Files\Java\jre6\bin;C:\P
rogram Files\Apache Software Foundation\Tomcat 6.0\lib\mail.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib;C:\Program F
iles\Java\jre6\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\actions\register;

ActionFactory.java

package com.masatosan.redirector;
import com.masatosan.actions.register.RegisterAction;

public class ActionFactory {
//some code here...

}

ANT输出

C:\apache-ant-1.8.1-bin\javac_masatosan\debug>ant
Buildfile: C:\apache-ant-1.8.1-bin\javac_masatosan\debug\build.xml

compileAll:
    [javac] C:\apache-ant-1.8.1-bin\javac_masatosan\debug\build.xml:47: warning: 'includeantruntime' was not set, defaulting to build.s
ysclasspath=last; set to false for repeatable builds
    [javac] Compiling 4 source files to C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes
    [javac] C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\redirector\ActionFactory.java:1
5: cannot find symbol
    [javac] symbol  : class RegisterAction
    [javac] location: package com.masatosan.actions.register
    [javac] import com.masatosan.actions.register.RegisterAction;
    [javac]                                      ^
    [javac] C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\redirector\ActionFactory.java:2
4: cannot find symbol
    [javac] symbol  : class RegisterAction
    [javac] location: class com.masatosan.redirector.ActionFactory
    [javac]             actions.put("POST/process_register.do", new RegisterAction());
    [javac]                                                         ^
    [javac] 2 errors

BUILD FAILED
C:\apache-ant-1.8.1-bin\javac_masatosan\debug\build.xml:47: Compile failed; see the compiler error output for details.

2 个答案:

答案 0 :(得分:10)

看起来你只指定了一个“javac”的“sourcepath” - 而不是两者。也许你应该做

<target name="compileAll">
  <javac target="1.5" source="1.5" destdir="${dest}">
    <src path="${redirectorSrc}"/>
    <src path="${srcMasatosan}"/>
  </javac>    
</target>

答案 1 :(得分:0)

Make it point to your exact jar files directory where jars are present
<path id="classpath">
<fileset dir="${main.jar}" includes="**/*.jar"/>
<!-- <pathelement location="${src.dir}" />-->
</path>

----in my case jar files present in ----
<property name="main.jar"     value="jar"/>