#1104 classpath for JarDist()

liamstask Mon 31 May 2010

I've been poking around to see if I can get some fantom code running on appengine, and have run into a problem with the following code: http://pastebin.com/VYYFamK8

I'm still not sure what the appropriate workflow will be, but for the time being my hack-y strategy is to create a pod for my app, and then run a JarDist() task to create a bundle to drop into the appengine WAR. Suggestions gladly accepted for a better approach!

In the meantime, I'm able to the code above as a pod, but when I run JarDist() and include that pod, I get

Exception in thread "main" sys::Err: Cannot map Fantom type to Java class: [java]javax.servlet.http::HttpServlet
at fan.sys.Err.make(Err.java:78)
at fan.sys.Err.make(Err.java:68)
at fan.sys.JavaType.toClass(JavaType.java:127)
at fan.sys.JavaType.initSlots(JavaType.java:178)
at fan.sys.JavaType.slots(JavaType.java:91)
at fan.sys.ClassType.merge(ClassType.java:335)
at fan.sys.ClassType.doReflect(ClassType.java:289)
at fan.sys.ClassType.reflect(ClassType.java:258)
at fan.sys.ClassType.emitToClassFiles(ClassType.java:643)
at fanx.tools.Jstub.stub(Jstub.java:57)
at fanx.tools.Jstub.run(Jstub.java:140)
at fanx.tools.Jstub.main(Jstub.java:165)

I've had to add the path to the appengine J2EE stuff in order to use the fan launcher thus far, so my first suspicion is that perhaps the jstub tool doesn't inherit the classpath from the initial fan launcher? Any thoughts?

Edit: I see that JarDist::podClasses() specifies only sys.jar on the classpath, which looks problematic in this case. Not sure what the suggested approach to this is.

brian Tue 1 Jun 2010

I am pretty sure it just does a normal Class.forName based on the classes available in the classpath used to run jstub. Try sticking the the servlet jar into either the JRE ext or Fantom lib/java/ext directory?

liamstask Tue 1 Jun 2010

OK, in this case I think something is either wrong with my installation (1.0.53 download) or there's a bug. Adding any of the jars to lib/java/ext doesn't seem to add them to the classpath - even a normal fan build.fan fails in this case with:

/Users/liam/Documents/mtcode/GAE/GaeTester/src/fan/FanServlet.fan(2,1): Java package 'javax.servlet' not found

In my hacking around, I found that if in fanlaunch, I changed FAN_CP=$FAN_HOME/lib/java/sys.jar to FAN_CP=$FAN_HOME/lib/java/* then the jars got picked up on the classpath for a normal build, resolving the error above, but not for a JarDist().

Is there a good way to verify that my setup is not broken in some way that would prevent this from working?

tcolar Tue 1 Jun 2010

I believe to hgave the same issue last week as well. Had to put the jar in jdk folder. All jars in fantom lib/java/ext should be added to the fantom urlclassloader for this to work. Don't think they are.

liamstask Tue 1 Jun 2010

Confirmed that when I run fan compilerJava::ClassPath as shown in the JavaFFI doc, .jars in lib/java/ext are not found.

brian Tue 1 Jun 2010

Confirmed that when I run fan compilerJava::ClassPath as shown in the JavaFFI doc, .jars in lib/java/ext are not found.

Actually I think that is an oversight from when Fantom exts got moved from JDK classpath to being handled via FanClassLoader. I will take a look at a fix.

@liamstask - were you able to get the DistJar to build putting the classes into the JDK ext directory? Let me know your status and I will take a look at that too.

liamstask Wed 2 Jun 2010

Yep - dropping them into the JDK ext does the trick - they show up in compilerJava::ClassPath, and both a pod build and JarDist() succeed.

brian Wed 2 Jun 2010

I fixed it so that Fantom's lib/java/ext directory is included in the Java FFI classpath. Now the compile classpath is:

  1. jars found in "sun.boot.class.path"
  2. {java}lib/rt.jar (only if step above fails to find anything)
  3. {java}lib/ext/*.jar
  4. {fan}lib/java/ext/*.jar
  5. {fan}lib/java/ext/{Env.platform}/*.jar
  6. jars found in "java.class.path" system property

Login or Signup to reply.