我获得了一个脚本来编译源代码并将它们部署到Tomcat webserver。
如果我在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
答案 0 :(得分: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
您可以使用多个标签来指定多个类路径