1

在尝试构建我的 Struts 应用程序时,我收到以下错误:

compile:
    [javac] /media/Data/Struts 2/2012-05-02/Struts/src/Build.xml:5: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 2 source files
    [javac] MyAction.java:5: package org.apache.struts2.interceptor does not exist
    [javac] import org.apache.struts2.interceptor.SessionAware;
    [javac]                                      ^
    [javac] MyAction.java:7: package com.opensymphony.xwork2 does not exist
    [javac] import com.opensymphony.xwork2.ActionSupport;
    [javac]                               ^
    [javac] MyAction.java:10: cannot find symbol
    [javac] symbol: class ActionSupport
    [javac] public class MyAction extends ActionSupport implements SessionAware {
    [javac]                               ^
    [javac] MyAction.java:10: cannot find symbol
    [javac] symbol: class SessionAware
    [javac] public class MyAction extends ActionSupport implements SessionAware {
    [javac]                                                        ^
    [javac] MyAction.java:22: cannot find symbol
    [javac] symbol  : method addActionError(java.lang.String)
    [javac] location: class com.sp.action.MyAction
    [javac]         addActionError("invalid");
    [javac]         ^
    [javac] MyAction.java:47: cannot find symbol
    [javac] symbol  : method addActionError(java.lang.String)
    [javac] location: class com.sp.action.MyAction
    [javac]             addActionError("User Name ,pass cannot be error");
    [javac]             ^
    [javac] MyAction.java:43: method does not override or implement a method from a supertype
    [javac]     @Override
    [javac]     ^
    [javac] 7 errors

BUILD FAILED

我的包层次结构是src/com/sp/action/*.javasrc/com/sp/domain/*.java

我的构建文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project name="strutsComple" default="compile">
    <target name="compile">
        <fileset dir="/media/Data/Works/struts-2.3.1.2/lib/" includes="*.jar"/>
        <javac srcdir="./com/sp/"/>
    </target>
</project>

我已经将两个必需的 jar 添加到我的 Eclipse 文件夹中。

有人可以指出我所缺少的吗?

4

1 回答 1

1

你的 ant 构建文件简单了。将 struts jar 导入 eclipse 对您的 ant 构建没有任何作用。您需要在 build.xml 中为 javac 配置一个类路径。

<fileset dir="/media/Data/Works/struts-2.3.1.2/lib/" includes="*.jar"/>
<javac srcdir="./com/sp/"/>

应该成为

<javac srcdir="./com/sp/">
    <classpath>
        <fileset dir="/media/Data/Works/struts-2.3.1.2/lib/" includes="*.jar"/>
    </classpath>
</javac>

请参阅此答案以获取另一个示例让 Ant <javac> 识别类路径

另请参阅javac任务的文档。

于 2012-08-17T11:48:13.770 回答