4
votes

I have some Java classes that are generated at runtime and compiled using a

JavaCompiler.CompilationTask.

The generated code references classes that are in other projects that are maven dependencies of my project. Everything runs fine locally, but when I deploy to our dev Tomcat server, I get a bunch of

"package xxx does not exist"

and

"cannot find symbol"

errors in the compilation task. I checked the WEB-INF/lib directory of the Tomcat-deployed webapp project, and all of the jars are there, including the project dependencies. Isn't everything in the WEB-INF/lib dir supposed to be available to a Tomcat project at runtime?

EDIT: Here is my context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
        virtualClasspath="${catalina.home}/webapps/kdweb/WEB-INF/lib/acommons-0.0.1-SNAPSHOT.jar;${catalina.home}/webapps/kdweb/WEB-INF/lib/abizcommons-0.0.1-SNAPSHOT.jar;${catalina.home}/webapps/kdweb/WEB-INF/lib/kd_market_data-common-0.0.1-SNAPSHOT.jar;${catalina.home}/webapps/kdweb/WEB-INF/lib/aggregation-0.0.1-SNAPSHOT.jar;${catalina.home}/webapps/kdweb/WEB-INF/lib/apods-client-0.0.1-SNAPSHOT.jar;${catalina.home}/webapps/kdweb/WEB-INF/lib/framework-common-0.0.1-SNAPSHOT.jar" />
</Context>
2

2 Answers

1
votes

you can use the Loader and set the reloadable to true.(This might be related as well)

1
votes

It turns out that I needed to pass an explicit classpath to the JavaCompiler.CompilationTask in the code. Here is how I got it to work:

String classPath = "webapps/WEB-INF/lib/jar1.jar;webapps/WEB-INF/lib/jar2.jar";
List<String> options = new ArrayList<String>();
options.addAll(Arrays.asList("-classpath", classPath));
final JavaCompiler.CompilationTask task = compiler.getTask(null, manager, null, options, null, Arrays.asList(source));