java - How do I get an error message when failing to load a JVM via JNI? -


I would like to receive an error message that states why jvm failed to load. From the examples given here:

I have removed this example:

/ * Java VM * / res = JNI_CreateJavaVM (& jvm) Create, (zero **) and NV, and VM_arg); If (RAS <0) {// Verbose error is retrieved? Fprintf (stderr, "can create java vm \ n"); Exit (1); }

In my specific case I am providing invalid arguments in vm_args and I would expect to see what I get on the command line: "Unknown option: -foo = bar"

On the further testing it seems like putting a jvm message that I want to stdout or stderr. I believe I will need to capture the stadout and the stadder so that I can get that error (unless there is no easy way). I am coding in C ++ so that I can show how to capture an error in a stringstream that would be ideal.

Thanks, Randy

I use the "vfprintf" option described here What was required:

However, this code snippet of the Jdk1.2 option summarizes my solution:

  Fixed string jniErrors; Fixed j int JNICALL my_vfprintf (FILE * fp, const char * format, va_list args) {four buff [1024]; Vsnprintf (buf, sizeof (buf), format, args); JniErrors + = buf; Return 0; } ... Optional Option Option [1]; Option [0] .optionString = "vfprintf"; Option [0] .extraInfo = my_vfprintf; JavaVMInitArgs vm_args; Memos (& amp; vm_args, 0, size (vm_args)); Vm_args.nOptions = 1; Vm_args.options = Option; Vm_args.version = JNI_VERSION_1_4; Vm_args.ignoreUnrecognized = JNI_FALSE; JNIEnv env; Javvama JVM; Jint res = JNI_CreateJavaVM (and jvm, (void **) and nv, & amp; vm_args); If (res! = JNI_OK) setError (jniErrors); JniErrors.clear ();  

It was also interesting that I could not capture stdout or stderr correctly with any freepay or duplicate 2 tricks for my life. I can load my self DLL and redirect it properly but JVM does not. Anyway, this is better than this because I wanted errors in the memory instead of a file.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -