Reputation: 13947
I was given a script to compile sources and deploy them to Tomcat webserver.
If i compile the sources in Eclipse, they compile just fine.
But with the script I get the following output:
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
Upvotes: 1
Views: 1116
Reputation: 1741
This is because while compiling the CLASSPATH is incorrect. You can mitigate this by doing the following:
Add a property like this
<path id="compile.classpath">
<fileset dir="WEB-INF/lib">
<include name="*.jar" />
</fileset>
</path>
Assuming that the libraries you need to compile the code lives under WEB-INF/lib ... if it resides somewhere else ... enter the path to that directory relative to your build.xml file
Now when compiling do the following:
<target name="compile" depends="copyfiles">
<javac destdir="WEB-INF/classes" debug="true" srcdir="WEB-INF/src" includeantruntime="false">
<classpath refid="compile.classpath" />
</javac>
</target>
which is saying ... compile the java code in WEB-INF/src and put the class files in WEB-INF/classes ... and add the WEB-INF/lib (references by compile.classpath) to the CLASSPATH
you can use multiple tags to specify multiple classpaths
Upvotes: 1