#594 compiling using JavaFFI

cheeser Tue 12 May 2009

I'm having a bit of trouble and need a some help here. I have this source file:

using [java] javax.servlet

abstract class FanServlet {
    abstract Void service(ServletRequest servletRequest, ServletResponse   servletResponse)
}

compiling gives me the following output:

javaLibs = [../../../.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar]
compile [fan-servlet]
  Compile [fan-servlet]
    FindSourceFiles [2 files]
/Users/jlee/dev/personal/fan-servlet/src/main/fan/FanServlet.fan(1,1): Java package 'javax.servlet' not found

and my build.fan is:

using build

class Build : BuildPod
{
  override Void setup()
  {
    podName     = "fan-servlet"
    version     = Version("0.1")
    description = "Java Servlet bridge layer"
    depends     = ["sys 1.0"]
    srcDirs     = [`src/main/fan/`, `src/test/fan/`]
    javaLibs    = [ `../../../.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar` ]
    includeSrc  = true
    podFacets   = [:]
  }

  @target="compile fan source into pod"
  override Void compile(Bool full := true)
  {
    echo("javaLibs = ${javaLibs}")
    super.compile(full)
  }
}

What am I missing here? i tried explicitly having a using line for each type from the servlet api but it still complains about that package.

brian Tue 12 May 2009

Currently the jars you compile against have to be in the classpath used to run Fan.

See this section.

You dump the classpath the compiler is using:

fan compilerJava::ClassPath

I see you tried to using javaLibs in the build file - that makes perfect sense, but I am counting on reflection from the system classloader right now (I know very lame - I need to fix it eventually).

cheeser Tue 12 May 2009

yeah. andy just suggested dumping that jar in one of the ext directories. I did that and it worked. That's definitely a bug there... I might play with that compiler tonight and see about updating that classpath with the contents of javaLibs and see if I can't resolve that for you. But since I have a workaround, I might just finish the task at hand before I get too distracted. :)

brian Tue 12 May 2009

I might play with that compiler tonight and see about updating that classpath with the contents of javaLibs and see if I can't resolve that for you

The root problem is that I need to parse the bytecode in the jars myself and build up the Java class representations without using reflection.

My current approach has two major flaws:

  1. it requires the class be the compiler's classpath
  2. it won't let the compiler cross compile Java FFI while running on .NET

Reflection was just a quick hack to get everything working, but it isn't the long term solution.

Login or Signup to reply.