1

我得到了一个脚本来编译源代码并将它们部署到 Tomcat 网络服务器。

如果我在 Eclipse 中编译源代码,它们编译得很好。

但是使用脚本我得到以下输出:

Buildfile: C:\Dev\workworkspace\myapp\build.xml
     [echo] website root dir is C:/Dev/ServerXamp/tomcat/myapp/myapp line sepa
rator is

clean-build:

compile:
    [mkdir] Created dir: C:\Dev\workworkspace\myapp\build\classes
    [javac] Compiling 86 source files to C:\Dev\workworkspace\myapp\build\c
lasses
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclass.java:6: error: package org.apache.catalina.websocket does
 not exist
    [javac] import org.apache.catalina.websocket.*;
    [javac] ^
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclass.java.java:7: error: package org.apache.catalina.websocket does
 not exist
    [javac] import org.apache.catalina.websocket.*;
    [javac] ^
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclass.java:14: error: cannot find symbol
    [javac] public class problemclass extends MessageInbound
    [javac]                                                   ^
    [javac]   symbol: class MessageInbound
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclass.java:25: error: cannot find symbol
    [javac]     private WsOutbound _out;
    [javac]             ^
    [javac]   symbol:   class WsOutbound
    [javac]   location: class problemclass
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclass.java:83: error: cannot find symbol
    [javac]     protected  void onOpen(WsOutbound outbound) {
    [javac]                            ^
    [javac]   symbol:   class WsOutbound
    [javac]   location: class problemclass
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclass.java:15: error: package org.apache.catalina.websocket does not
 exist
    [javac] import org.apache.catalina.websocket.StreamInbound;
    [javac]                                     ^
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclass.java:37: error: cannot find symbol
    [javac]     protected StreamInbound createWebSocketInbound(String subProtoco
l, HttpServletRequest request)
    [javac]               ^
    [javac]   symbol:   class StreamInbound
    [javac]   location: class problemclass
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclassServer.java:795: error: bad operand types for binary operator '!='
    [javac]             if (userInfo.websocket != null)
    [javac]                                    ^
    [javac]   first type:  problemclass
    [javac]   second type: <null>
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclassServer.java:4593: error: bad operand types for binary operator '!='
    [javac]         if (userInfo.websocket != null)
    [javac]                                ^
    [javac]   first type:  problemclass
    [javac]   second type: <null>
    [javac] C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclassServer.java:4907: error: bad operand types for binary operator '!='
    [javac]             if (userInfo.websocket != null)
    [javac]                                    ^
    [javac]   first type:  problemclass
    [javac]   second type: <null>
    [javac] Note: C:\Dev\workworkspace\myapp\main\src\com\myapp\problempackage\problemclassServer.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] 10 errors

BUILD FAILED
C:\Dev\workworkspace\myapp\build.xml:96: Compile failed; see the compiler e
rror output for details.

Total time: 7 seconds
4

1 回答 1

1

这是因为在编译 CLASSPATH 时不正确。您可以通过执行以下操作来缓解这种情况:

添加这样的属性

<path id="compile.classpath">
    <fileset dir="WEB-INF/lib">
        <include name="*.jar" />
    </fileset>
</path>

假设您需要编译代码的库位于 WEB-INF/lib 下...如果它位于其他位置...输入该目录相对于您的 build.xml 文件的路径

现在在编译时执行以下操作:

<target name="compile" depends="copyfiles">
    <javac destdir="WEB-INF/classes" debug="true" srcdir="WEB-INF/src" includeantruntime="false">
        <classpath refid="compile.classpath" />
    </javac>
</target>

也就是说...编译 WEB-INF/src 中的 java 代码并将类文件放入 WEB-INF/classes ...并将 WEB-INF/lib(compile.classpath 引用)添加到 CLASSPATH

您可以使用多个标签来指定多个类路径

于 2013-09-03T04:18:24.330 回答