java


Crash when spawning a JVM inside of a UWP C++ Application


First of: I don't know if this problem is rather related to UWP and it's strange security settings or rather me mis-using JNI's Invocation
Anyhow, I use this code to spawn a jvm inside a c++ static library (With /ZW, so compiling for UWP, but disabling it doesn't change a thing).
The following code is based upon Oracle's Notes and openjdk's code (exeinvoke.c, launcher.c, ...):
void JVM4UWP::loadVM(string vmOptions[], int numOptions, int jni_version) {
/* Copy the VM Options */
options = new JavaVMOption[numOptions];
for (uint8_t i = 0; i < numOptions; i++) {
options[i].optionString = new char[vmOptions[i].length() + 1]; // \0 takes the additional byte
strncpy_s(options[i].optionString, vmOptions[i].length() + 1, vmOptions[i].c_str(), vmOptions[i].length() + 1);
}
//options[0].optionString = "-Djava.class.path=/usr/lib/java";
vm_args = new JavaVMInitArgs();
vm_args->version = jni_version;
vm_args->nOptions = numOptions;
vm_args->options = options;
vm_args->ignoreUnrecognized = false;
/* load and initialize a Java VM, return a JNI interface
* pointer in env */
JNI_CreateJavaVM(&jvm, (void**)&env, vm_args);
delete options;
/* invoke the Main.test method using the JNI */
jclass cls = env->FindClass("Main");
jmethodID mid = env->GetStaticMethodID(cls, "main", "(I)V");
env->CallStaticVoidMethod(cls, mid, 100);
/* We are done. */
jvm->DestroyJavaVM();
}
Now the problem with this is: I added #include <jni.h>, I added lib/jvm.lib as static library (taken from oracle's jdk), however it seems that something is still incomplete.
When I run the application, I get an error upon loadup (App::App of the sample UWP application isn't even run).
The console returns:
Das Programm "[1892] TestJVM.exe" wurde mit Code -1073741515 (0xc0000135) 'Es wurde keine abhängige DLL gefunden' beendet.
Loosely translated it's: Could find no dependant dll.
Now this reminds me of this MSDN Article. I have to admit that I don't fully understand it's contents. Especially since jvm.lib cannot have any Manifests. I tried to add jvm.dll, java.dll and jli.dll to the folder of the .exe but for some reason it still doesn't work.
Since the above code should work without dlls, I think it might be related to UWP, maybe even to my code:
My Setup currently is like this: I have the JVM4UWP static library which in-turn is linked statistically against jvm.lib. This Library is then included into the Demo UWP Project, which I am trying to execute.
Note that only subset of usual Windows APIs is available for uwp applications and I doubt that jvm is compatible with these restrictions. "lib/jvm.lib" might actually be an export library, not static library.
Also you probably might want to get familiar with Using a Win32 DLL in a Universal Windows Platform App.
It looks like JVM library is missing.
Take a look here for a sample where JVM is executed from C code:
http://jnicookbook.owsiak.org/recipe-no-027/
This sample is little bit more complex (it uses POSIX threads) but still, basics are the same.
Make sure that all libraries are on PATH so they can be loaded by either C++ or JVM.
Have fun with JNI!

Related Links

which is best between string isEmpty and StringUtils.isNotBlank() [duplicate]
Running jconsole on JRE
Exception in thread “main” java.lang.NoClassDefFoundError: org/jsoup/nodes/Element
How to read a final string value in ASM?
Error : Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException [duplicate]
Does volatile propagate to instance members?
'aidl is missing' when trying to migrate a project created with eclipse to Android Studio
Communication between threads in Java without lock
What's wrong with my SQL update? Java [closed]
Java heap space error with Spark running K means on EC2 instance
Type mismatch: cannot convert from int to Comparable
Home button for going back to main activity from my other activities
wsimport creates unexpected rest code
How to acquire the Key/name of root level JSON Objects with JSONPath?
Java mutliple regular expression search
Can I use SimpleXML to parse XML whose structure is unknown?

Categories

HOME
sendgrid
testng
netbeans
activiti
gremlin
fluentd
single-sign-on
angular-material
react-virtualized
view
iterator
fft
analysis
amortized-analysis
jpeg
django-imagekit
node-pdfkit
quartz-scheduler
netflix
uitypeeditor
tostring
ef-migrations
ab-testing
emulator
visjs
tapestry
excel-2007
telerik-reporting
sqlcipher
saas
jaxb2
libssl
primitive
nat
instant-messaging
caret
file-format
adobe-premiere
android-browser
service-discovery
angularjs-factory
trim
avro4s
http-live-streaming
nand2tetris
long-polling
youcompleteme
worker-thread
typed-lambda-calculus
cudafy.net
titanium-android
redundancy
orthogonal
google-feed-api
file-writing
testng-dataprovider
wso2cloud
msys
iis-arr
responsive-images
composite
nsmutabledictionary
clicktag
jscript.net
fpml
nsbutton
mysql-error-1062
algebraic-data-types
monomac
gnu-smalltalk
commoncrypto
tidy
soundtouch
cos
back-stack
dataadapter
xamlparseexception
sqlperformance
orchardcms-1.7
smtp-auth
kyotocabinet
anonymous-methods
bitsharp
gil
quickdialog
wse3.0
fireworks
gnustep
doh
coredump
locationlistener
yetanotherforum
imac
mysql-error-1005
asp.net-mvc-areas
defensive-programming
zune

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile