title: SWIG Importing generated class from a different module and package into the current class
body: <p>I'm having difficulty getting the SWIG <a href="http://www.swig.org/Doc1.3/Java.html#java_directors_typemaps" rel="nofollow">typemap(javapackage)</a> to work properly. I tried making a simple version of the problem, and even that seems to fail.</p>
  
  <p>foo.h:</p>
  
  <pre><code>#ifndef FOO_H
  #define FOO_H
  
  class Foo
  {
  public:
      Foo() {};
      int doSomething() { return 1 };
  };
  
  #endif
  </code></pre>
  
  <p>bar.h:</p>
  
  <pre><code>#ifndef BAR_H
  #define BAR_H
  
  #include "foo.h"
  
  class Bar
  {
  public:
      Bar() {};
      int doSomething(Foo foo) { return foo.doSomething(); };
  };
  
  #endif
  </code></pre>
  
  <p>Foo.i</p>
  
  <pre><code>%module FooMod
  
  %include "typemaps.i"
  %include "stdint.i"
  
  %{
  #include "../header/foo.h"
  %}
  
  %include "../header/foo.h"
  </code></pre>
  
  <p>Bar.i</p>
  
  <pre><code>%module BarMod
  
  %import "Foo.i"
  
  %typemap("javapackage") Foo, Foo *, Foo &amp; "com.me.t.foo";
  
  %include "typemaps.i"
  %include "stdint.i"
  
  %{
  #include "../header/bar.h"
  %}
  
  %include "../header/bar.h"
  </code></pre>
  
  <p>Running these with this the following commands:</p>
  
  <pre><code>swig -c++ -java -package com.me.t.foo -outdir ../../src/com/me/t/foo -o ../src/Foo.cpp Foo.i
  swig -c++ -java -package com.me.t.bar -outdir ../../src/com/me/t/bar -o ../src/Bar.cpp Bar.i
  </code></pre>
  
  <p>And I get this output:</p>
  
  <pre><code>package com.me.t.bar;
  
  public class Bar {
    private long swigCPtr;
    protected boolean swigCMemOwn;
  
    protected Bar(long cPtr, boolean cMemoryOwn) {
      swigCMemOwn = cMemoryOwn;
      swigCPtr = cPtr;
    }
  
    protected static long getCPtr(Bar obj) {
      return (obj == null) ? 0 : obj.swigCPtr;
    }
  
    protected void finalize() {
      delete();
    }
  
    public synchronized void delete() {
      if (swigCPtr != 0) {
        if (swigCMemOwn) {
          swigCMemOwn = false;
          BarModJNI.delete_Bar(swigCPtr);
        }
        swigCPtr = 0;
      }
    }
  
    public Bar() {
      this(BarModJNI.new_Bar(), true);
    }
  
    public int doSomething(Foo foo) {
      return BarModJNI.Bar_doSomething(swigCPtr, this, Foo.getCPtr(foo), foo);
    }
  
  }
  </code></pre>
  
  <p>BarModJNI.java:</p>
  
  <pre><code>package com.me.t.bar;
  
  public class BarModJNI {
    public final static native long new_Bar();
    public final static native int Bar_doSomething(long jarg1, Bar jarg1_, long jarg2, Foo jarg2_);
    public final static native long Bar_getFoo(long jarg1, Bar jarg1_);
    public final static native void delete_Bar(long jarg1);
  }
  </code></pre>
  
  <p>The files are generated properly, but notice that there is <strong>no import statement</strong>, so <strong>Foo</strong> can't be found from either of the Bar Java classes. This is a simple example, but just hard-coding an import statement isn't an option for me since the generated source files containing the C JNI code might have the wrong locations of the "Foo" class files.</p>
  
  <p>This seems like a very simple and common problem, so, what I'm wondering is if I'm missing something or if I'm doing something wrong.</p>
  
  <p>Thanks for the help!</p>