I want to make use of the jenv structure in order that I can log directly to the log4j objects that my calling Java app uses.  I can get a proof of concept working by hacking the JAVA_wrap.cxx code that swig makes.  I hope to complete the exercise in a way that doesn't require manual tweaking of the swig outputs, or relies on a platform dependent sed-like text replacement.


My c++ API .h looks like this:

   EXPORT_DEF_MARK vecOutputType  *callApp(
#ifdef AppJava_EXPORTS
   JNIEnv *jenv,
#endif
      std::string a,
      std::string s1,
      std::string s2,
      std::string s3,
      int count,
      bool combinatorics
   );

My interface looks like this:
%module AppJava
%{
#include "API.h"
%}

%include "std_string.i"
%include "std_vector.i"
%include <windows.i>
%include "boost_shared_ptr.i"

%shared_ptr(sciOutput );
%template(VectorOutput) std::vector < boost::shared_ptr<sciOutput > >;

%newobject callApp(std::string a, std::string s1, std::string s2,
      std::string s3, int count, bool combinatorics);
%include "API.h"


Then all I need to do is change this line in my appJAVA_wrap.cxx file:
result = (vecOutputType *)ns::callApp(arg1,arg2,arg3,arg4,arg5,arg6);

to this:
result = (vecOutputType *)ns::callApp(jenv,arg1,arg2,arg3,arg4,arg5,arg6);



Then everything works and I can have logging to Java via:

#ifdef AppJava_EXPORTS
   jclass loggerClass = jenv->FindClass("org/apache/log4j/Logger");
   jmethodID getLogger = jenv->GetStaticMethodID(loggerClass, "getLogger", "(Ljava/lang/String;)Lorg/apache/log4j/Logger;");
   jmethodID info = jenv->GetMethodID(loggerClass, "info" ,"(Ljava/lang/Object;)V");
   jstring msg = jenv->NewStringUTF("log this");
   jobject logger = jenv->CallStaticObjectMethod(loggerClass, getLogger,  jenv->NewStringUTF("com.app.HelloWorldApp"));
   jenv->CallVoidMethod(logger, info, msg);  
#endif


So, again, is there a way that I can accomplish this without the manual edit between Swig and the compilation. 

Thanks very much!