Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 17063 Details for
Bug 82518
[launcher] [RCP] Use JNI to launch Eclipse
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
First attempt to launch Eclipse with JNI on Windows
(text/plain), 5.11 KB, created by
Ed Burnette
on 2005-01-10 17:21:21 EST
(
hide
)
Description:
First attempt to launch Eclipse with JNI on Windows
Filename:
MIME Type:
Creator:
Ed Burnette
Created:
2005-01-10 17:21:21 EST
Size:
5.11 KB
patch
obsolete
>Index: eclipseWin.c >=================================================================== >RCS file: /home/eclipse/platform-launcher/library/win32/eclipseWin.c,v >retrieving revision 1.20 >diff -u -r1.20 eclipseWin.c >--- eclipseWin.c 10 Dec 2004 17:28:53 -0000 1.20 >+++ eclipseWin.c 10 Jan 2005 22:10:11 -0000 >@@ -25,9 +25,17 @@ > /* Global Variables */ > _TCHAR dirSeparator = _T('\\'); > _TCHAR pathSeparator = _T(';'); >+#define JNI_INVOKE 1 >+#ifdef JNI_INVOKE >+#include <jni.h> /* java native interface */ >+_TCHAR* consoleVM = _T("jni.dll"); >+_TCHAR* defaultVM = _T("jni.dll"); >+_TCHAR* shippedVMDir = _T("jre\\bin\\client\\"); >+#else > _TCHAR* consoleVM = _T("java.exe"); > _TCHAR* defaultVM = _T("javaw.exe"); > _TCHAR* shippedVMDir = _T("jre\\bin\\"); >+#endif > > /* Define the window system arguments for the Java VM. */ > static _TCHAR* argVM[] = { NULL }; >@@ -162,6 +170,48 @@ > return argVM; > } > >+#ifdef JNI_INVOKE >+static jstring newJavaString(JNIEnv *env, char *s) >+{ >+ int len; >+ jclass cls; >+ jmethodID mid; >+ jbyteArray ary; >+ jstring str = 0; >+ >+ if (s == NULL) >+ return 0; >+ len = strlen(s); >+ ary = (*env)->NewByteArray(env, len); >+ if (ary != 0) >+ { >+ (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s); >+ if (!(*env)->ExceptionOccurred(env)) { >+ cls = (*env)->FindClass(env, "java/lang/String"); >+ mid = (*env)->GetMethodID(env, cls, "<init>", "([B)V"); >+ str = (*env)->NewObject(env, cls, mid, ary); >+ } >+ (*env)->DeleteLocalRef(env, ary); >+ } >+ return str; >+} >+ >+static jobjectArray newJavaStringArray(JNIEnv *env, char **argv, int argc) >+{ >+ jarray cls; >+ jarray ary; >+ int i; >+ >+ cls = (*env)->FindClass(env, "java/lang/String"); >+ ary = (*env)->NewObjectArray(env, argc, cls, 0); >+ for (i = 0; i < argc; i++) { >+ jstring str = newJavaString(env, *argv++); >+ (*env)->SetObjectArrayElement(env, ary, i, str); >+ (*env)->DeleteLocalRef(env, str); >+ } >+ return ary; >+} >+#endif > > /* Start the Java VM > * >@@ -170,6 +220,90 @@ > */ > int startJavaVM( _TCHAR* args[] ) > { >+#ifdef JNI_INVOKE >+ HINSTANCE jvmLibrary; // Library handle >+ //displayMessage(_T("jni invoke\n")); >+ jvmLibrary = LoadLibrary(args[0]); >+ /* If the child library (JVM) would not start */ >+ if (jvmLibrary == 0) >+ { >+ /* Return the error number. */ >+ displayMessage(_T("child lib would not start\n")); >+ jvmExitCode = errno; >+ jvmLibrary = 0; >+ } >+ else >+ { >+ /* Get the function addresses */ >+ jint (JNICALL *createJavaVM)(JavaVM **pvm, JNIEnv **env, void *args); >+ jint (JNICALL *getDefaultJavaVMInitArgs)(void *args); >+ createJavaVM = (void *)GetProcAddress(jvmLibrary, "JNI_CreateJavaVM"); >+ getDefaultJavaVMInitArgs = (void *)GetProcAddress(jvmLibrary, "JNI_GetDefaultJavaVMInitArgs"); >+ if (createJavaVM == 0 || getDefaultJavaVMInitArgs == 0) >+ { >+ /* Return the error number. */ >+ displayMessage(_T("createJavaVM or getDefaultJavaVMInitArgs address not found\n")); >+ jvmExitCode = errno; >+ jvmLibrary = 0; >+ } >+ else >+ { >+ JavaVM *jvm; /* denotes a Java VM */ >+ JNIEnv *env; /* pointer to native method interface */ >+ // documented here: http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html#JNI_CreateJavaVM >+ JavaVMInitArgs vm_args = {0}; >+ JavaVMOption options[4]; >+ options[0].optionString = "-Djava.class.path=startup.jar"; >+ vm_args.version = JNI_VERSION_1_4; >+ vm_args.options = options; >+ vm_args.nOptions = 1; >+ vm_args.ignoreUnrecognized = JNI_TRUE; >+ >+ /* load and initialize a Java VM, return a JNI interface pointer in env */ >+ //displayMessage(_T("about to create vm\n")); >+ (*createJavaVM)(&jvm, &env, &vm_args); >+ if (jvm == NULL) >+ { >+ displayMessage(_T("createJavaVM failed\n")); >+ jvmExitCode = errno; >+ jvmLibrary = 0; >+ } >+ else >+ { >+ /* invoke the Main.test method using the JNI */ >+ //displayMessage(_T("about to FindClass\n")); >+ jclass cls = (*env)->FindClass(env, "org/eclipse/core/launcher/Main"); >+ if (cls == NULL) >+ { >+ displayMessage(_T("FindClass failed\n")); >+ jvmExitCode = errno; >+ jvmLibrary = 0; >+ } >+ else >+ { >+ //displayMessage(_T("about to GetStaticMethodID\n")); >+ jmethodID mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V"); >+ if (mid == NULL) >+ { >+ displayMessage(_T("GetStaticMethodID failed\n")); >+ jvmExitCode = errno; >+ jvmLibrary = 0; >+ } >+ else >+ { >+ //displayMessage(_T("about to call main\n")); >+ (*env)->CallStaticVoidMethod(env, cls, mid, >+ newJavaStringArray(env, NULL, 0)); >+ // shouldn't get here, but just in case... >+ displayMessage(_T("main complete, destroying vm\n")); >+ /* We are done. */ >+ (*jvm)->DestroyJavaVM(jvm); >+ } >+ } >+ } >+ } >+ } >+#else > MSG msg; > int index, length; > _TCHAR *commandLine, *ch, *space; >@@ -244,6 +378,7 @@ > KillTimer( topWindow, jvmExitTimerId ); > } > >+#endif > /* Return the exit code from the JVM. */ > return jvmExitCode; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 82518
:
17063
|
17091