4

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>
Jared
  • 2,043
  • 5
  • 33
  • 63

2 Answers2

1

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

Community
  • 1
  • 1
Scis
  • 2,934
  • 3
  • 23
  • 37
  • No luck. Edited original question with my context.xml – Jared Sep 19 '12 at 17:29
  • 1
    As I see it you did not set reloadable to true as suggested, please try that, if that doesn't work you might try and check whether the related question helps you or you can try Tomcat's suggestion regarding the Manager application to reload apps at run-time. – Scis Sep 20 '12 at 07:34
  • Correct me if I'm wrong, but doesn't `reloadable` simply watch the WEB-INF/lib and WEB-INF/classes directories for changes, and restart the application? I've undeployed and redeployed the app many times, so I don't think that's the issue. The runtime JavaCompiler is just not finding the required dependencies in its classpath. – Jared Sep 20 '12 at 14:06
1

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));
Jared
  • 2,043
  • 5
  • 33
  • 63