【问题标题】:ANT - javac compile failure due to cannot find symbolANT - 由于找不到符号而导致 javac 编译失败
【发布时间】:2010-10-02 02:01:37
【问题描述】:

我正在尝试编译 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.

【问题讨论】:

    标签: ant compilation javac


    【解决方案1】:

    看起来您只为“javac”指定了一个“源路径”——而不是两者。也许你应该这样做

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

    【讨论】:

      【解决方案2】:
      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"/>
      

      【讨论】:

        猜你喜欢
        • 2016-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-09
        • 1970-01-01
        • 1970-01-01
        • 2011-09-23
        相关资源
        最近更新 更多