Access java properties from C++/JNI program

Hello all,
Is it possible to access the Java properties of a JNI VM from a C++ program?
If so, could the code or process be explained to me.
I want to be able to identify a specific VM that is retrieved by the JNI_GetCreatedJavaVMs
call. I set a user property when the VM was created, and would like to verify its value
before calling AttachCurrentThread.
Thanks in advance.
Mark

Are you saying that you set a system property (via System.setProperty() or -D)?
If so, just use the JNI invocation API to call System.getProperty().
Without error checking, that looks something like this:bool isMySystem( JNIEnv* env ) {
  const string PropertyName = "IsMySystem";
  jclass systemClass = env->FindClass( "java/lang/System" );
  jmethodID getPropertyMethod = env->GetStaticMethodID( systemClass, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;" );
  jstring propertyNameString = env->NewStringUTF( PropertyName.c_str() );
  jstring propertyString = env->CallStaticObjectMethod( systemClass, getPropertyMethod, propertyNameString );
  if ( propertyString == 0 ) {
    return false;
  const char* property = env->GetStringUTFChars( propertyString, 0 );
  boolean isMine = ! strcmp( property, "Yes" );
  env->ReleaseStringUTFChars( propertyString, property );
  return isMine;
}Using Jace, http://jace.reyelts.com/jace (a free, open-source toolkit), this would look more like:bool isMySystem() {
  String property = System::getProperty( "IsMySystem" );
  return property.isNull() ? false : prop == "Yes";
}In the end, Jace ends up making all of the exact same calls, but you can see how much easier it is to use.
God bless,
-Toby Reyelts

Similar Messages

  • Calling a Java Subpackage from a C program.... fails

    I am having alittle bit of trouble calling a java subpackage from my C program. I can call a package ok but not a subpackage.
    My directory path is c:\com\phoenix_systems_inc
    My CLASSPATH=.;c:\com;
    In the c:\com\phoenix_systems_inc directory is my FundsgClient.class
    The fundsgClient.java has a package declaration of
    package com.phoenix_systems_inc;
    within the fundsgClient.java is class:
         public synchronized static String setValue (String str) {
         String a = "You passed: " + str;
         return a;
    ======================================
    in my C program I have
    options[0].optionString = "-Djava.class.path=c:\\com\\";
    cls = env->FindClass("/phoenix_systems_inc/com.phoenix_systems_inc.FundsgClient");
    I think that I am over declaring the path in FindClass.

    nope;; that is what I had initially;
    My CLASSPATH is CLASSPATH=.;c:\com;
    ==================================C program code
    memset (&vm_args, 0, sizeof(vm_args));
    vm_args.version=JNI_VERSION_1_2;
    vm_args.options = options;
    vm_args.nOptions = 1;
    options[0].optionString = "-Djava.class.path=c:\\com";
    vm_args.ignoreUnrecognized = TRUE;
    res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
    if (res < 0)
    fprintf(stderr, "Can't create Java VM\n");
         return 0;
    cls = env->FindClass("com/phoenix_systems_inc/FundsgClient");
    ===== is the java class code ==========
    package com.phoenix_systems_inc;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    import gnu.cajo.invoke.Remote;
    import gnu.cajo.utils.extra.Xfile;
    * Fundsg RMI Client
    * @author agesite
    * @version 1.0
    public class FundsgClient {
    static {
    PropertyConfigurator.configure("FundsLog.properties");
    // Log4j logger
         private static Logger log = Logger.getLogger("PhoenixClient");
    // Get RMI Server Hostname
    private static final String host = PhoenixClientProperties.getInstance().
    getProperty("PhoenixRMIServer");
    private static String port = "1198";
         * request
         * @param requestStr Request String
         * @return String Response String
         * @throws Exception
         public synchronized static String request (String requestStr) throws Exception {
              // Serialized object
              RequestObject requestObj = new RequestObject();
              requestObj.setRequest(requestStr);
              if (log.isDebugEnabled()) {
                   log.debug("Client Request: " + requestStr);
              System.out.println("//" + host + ":" + port + "/fundsgServer");
              Object object = Remote.getItem("//" + host + ":" + port + "/fundsgServer");
              String response = (String) Remote.invoke(object, "nativeFundsg", requestObj.getRequest());
              if (log.isDebugEnabled()) {
                   log.debug("Server Response: " + response);
              return response;
         * xferFile
         * @param sourceFile
         * @param destFile
         * @throws Exception
         public synchronized static void xferFile (String sourceFile, String destFile) throws Exception {
              try {           
                   Object xf = Remote.getItem("//" + host + ":" + port + "/xfileFunds");
                   // remoteInvoke = true means transfer can be performed from
    // server to client and vice versa
    Xfile.remoteInvoke = true;
                   Xfile.fetch(xf, sourceFile, destFile);
              } catch (Exception e) {
                   if (log.isDebugEnabled()) {
                        log.debug("Xfile.fetch exception: " + e);
         public synchronized static String setValue (String str) {
         String a = "You passed: " + str;
         return a;
    }

  • (how) can I access Java APIs from web-page-hosted JavaScript?

    Can I access Java APIs from a web-page via JavaScript if I have a JRE installed on the client machine? And if so, how?
    Thanks in advance for your time and consideration.

    John L. wrote:
    Can I access Java APIs from a web-page via JavaScript if I have a JRE installed on the client machine? And if so, how?As far as I can remember that was actually possible in the very first versions of Netscape because Netscape really wanted to pretend Javascript and Java were meant to be used together. But they soon removed that functionality. Can you guess why?
    Because people were using the File/IO classes to easily steal or remove files on the harddrive, among other such niceties. You do NOT want to have such control from a web application. People will abuse it.

  • Accessing java objects from within javascript

    Hello,
    Anyone with an idea of a useful toolkit for accessing java objects from within javascript will be much appreciated.
    Thanks in advance,
    Antana.

    What do you mean by accessing Java objects? Do you mean interacting with an applet via JavaScript? Something else?

  • How can I call a java class from within my program?

    I was wondering if there's a platform independent way to call a java class from my program.

    Here's my scenario. I'm working on a platform independent, feature rich, object-oriented command prompt program. The way I'm designing it is that users can drop classes they write into my bin directory and gain access to the class through my program. For example, they drop a class named Network.class in the bin directory. They would type Network network at my command prompt and gain access to all the methods available in that class. They can then type system.echo network.ipaddress() at my prompt and get the system's ip address. I have it designed that there's a server running in the background and the clients connect to my port. Once connected the end-user can enter their user name and password and gain access to the system. When they type a command they actually call another java program which connects to my server using a seperate thread. They can then communicate back and forth. I have it set that everything has a process id and it's used to keep track of who called what program. Once the program is done it disconnects and closes. Rather than getting into the nitty gritty (I didn't want to get into heavy detail, I know how everything will work) I'm really interested in finding out how I can call a java program from my program. I don't want it to be part of the app in any way.

  • How do I start and suspend Java Application from say C++ program

    I want to start a Java application via C++ and on some condition i want to suspend the same program not terminate , but suspend

    Have you tried running the virtual machine from your C++ application ? You can start Java applications from your C++ application using JNI after starting the Virtual machine from within your C++ application. According to the Java documentation you can even now stop the virtual machine from within your C++ program.
    I haven't looked at the 'suspend' detail but I suppose it will not be a problem to call a method via JNI to set a flag to suspend a thread etc.
    There is a tutorial: 'Invoking the Java Virtual Machine' at the following URL: http://java.sun.com/docs/books/tutorial/native1.1/invoking/invo.html.
    This example seems to work only for version1.1 of the JDK. For JDK1.3, version 1.2, (I am not so sure whether I fully understand Sun's version numbers for Java yet) there is some updates on the JNI for starting the VM from C++. This article is called 'JNI Enhancements'. The URL for this article is:
    http://java.sun.com/j2se/1.3.0/docs/guide/jni/jni-12.html
    You have to set version to: JNI_VERSION_1_2
    There is only one problem. I get an error when calling JNI_CreateJavaVM from C++. I could not find any documentation that indicates how you can go about diagnosing what is causing the problem. Normally in Visual C++ you can just get the probable cause by inspecting GetLastError() or the function itself can return helpful diagnostic (error) codes.
    If you manage to start the VM correctly from within Visual C++ please let me know. My email address is [email protected]
    good luck
    Henko

  • Accessing Java Classes from Forms

    Is is possible to access a Java class from Forms? I have been
    creating an Active X control that returns a Java object, and from
    that I can call methods on that object, but I would really like
    to do that without having and Active X control in the mix. Any
    suggestions?
    null

    Oracle Developer Team wrote:
    : Robert Nocera (guest) wrote:
    : : Oracle Developer Team wrote:
    : : : hey robert -
    : : : Developer 6.0 provides this ability for web deployment.
    You
    : : can
    : : : insert your own custom Java components into your
    application
    : : and
    : : : they will appear in the application when it is run via the
    : web.
    : : : If you look at the documentation for 6.0, there are a few
    : : : section son Pluggable Java Components and JavaBeans that
    : : : describes what is provided and how you use the interfaces
    : and
    : : : classes we provide.
    : : : A whitepaper on this topic will be posted to the OTN
    : shortly,
    : : as
    : : : well as some samples that illustrate how to go about doing
    : it.
    : : : cheers!
    : : : -Oracle Developer Team-
    : : Thanks for the quick response. Is there any way to access
    : those
    : : classes without being in a web deployment. That's probably
    : not
    : : totally out of the question, but what we had in mind was
    : adding
    : : some Java Functionality (actually connectictivity to some
    EJBs
    : : that we have) to existing forms. Currently there forms are
    : not
    : : deployed in a "web" environment and are just run from the
    : forms
    : : runtime engine.
    : : -Rob
    : hey again robert -
    : there's no easy way (yet!) to call out from forms runtime
    : process to a Java application.
    : We've played around some with creating an ORA_FFI interface to
    : JNI and then wrappering this with PL/SQL code. We've been able
    : to make calling into an EJB running in 8i from a forms runtime
    : work using this approach.
    : Let me know if this is of interest to you and I can post the
    : stuff we've currently got. It's no more than a simple demo and
    : is not complete. It requires quite a bit of manual coding on
    : the PL/SQL side since the interface emulates JNI (FindClass,
    : GetMethodID, CallMethodID, etc.).
    : cheers!
    : -the Oracle Developer Team-
    I'd be interested in this ORA_FFI doc you've been playing with.
    Would you please email it to me or post it.
    null

  • Accessing java classes from javascript

    Hi,
    I have the following javascript function
    function testjava {   
        var myString = new java.lang.String("Hello world"); // line 1
        alert("len:"+myString.length()); // line 2
    }It gives me a error at line 1 saying "'java' is undefined" in IE browser 5.5 sp2. But, both the lines execute correctly in netscape 6.
    Can someone please help..
    Thanks,
    Vijay.

    It seems that IE 5.5 doesn't support accessing java classes in JavaScript, so try to install IE 6 to see if it works or maybe, you doesn't have installed propertly support for JVM in IE.

  • WPC: Access Java beans from XSL

    Hi,
    How can we access custom Java beans from within the XSLs used to render WPC webforms? Do we have to implement a custom XSLT Helper? I am able to access standard Java classes using the <xmlns> tag but when I try to reference our custom classes the WPC editor throws a ClassNotFound exception. Any help will be appreciated.
    Thanks and Regards,
    Shibendra

    Hi,
    How can we access custom Java beans from within the XSLs used to render WPC webforms? Do we have to implement a custom XSLT Helper? I am able to access standard Java classes using the <xmlns> tag but when I try to reference our custom classes the WPC editor throws a ClassNotFound exception. Any help will be appreciated.
    Thanks and Regards,
    Shibendra

  • Access Java object from Javascript

    Hi
    I'm trying to invoke a Java object from Javascript (scriptengine and all that).
    I want to add scripting features to a GeneXus Java generated app... and I have very basic skills on java too. Sorry for that ;o).
    This is the java code to pass "params" to the scriptengine:
    engine.put("remoteHandle",remoteHandle);
    engine.put("context", context); The remoteHandle (int) and context (com.genexus.ModelContext) pass trough all the gx-java generated programs.
    This javascript works fine:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle).execute( ) ;The remoteHandle conversion is ok (javascript-number to int). The context is optional.
    But if I want to pass context:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle, context).execute( ) ;Fails with this:
    "javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Java constructor for 'uftestjs' with arguments 'number,javax.script.SimpleScriptContext' not found."
    Obviously, no conversion is possible with context (javax.script.SimpleScriptContext to com.genexus.ModelContext).
    There is some way to reference de original context, by the object Id??? or something like that???
    Thanks in advance for any replies!!!
    Greetings from Chile. (I hope you can understand my english!)

    Hi
    Well, since this topic is about java programming I think the place is right here.
    (I use some tricks to embed java statements in genexus objects...)
    I will try to get some help at Artech (GX) on how to build something... to get the conversion needed.
    But they are not focussed on support this kind of questions.
    Anyway, I want to know: do I can to reference an object by the objId?
    I want to code something like this:
    com.genexus.ModelContext context =
                     (com.genexus.ModelContex)getTheObjectFromTheJVM(theObjectId);(powered by google translator, ha!)

  • Accessing Java objects from C++ client

    I have a number of Java CORBA server objects that I have deployed to an 8.1.7 database.
    I can invoke these objects from a Java client with no problem, but I also need to access them from a C++ client.
    I have used idl2cpp from VisiBroker for C++ (version 4.5) to generate the client stubs, and I've downloaded the interop.tar file from http://technet.oracle.com/products/oracle8i/htdocs/jserver_faq/interop.tar
    The problem that I have is that I have not been able to build a client program because login.lib from interop.tar generates conflicts at link time. I've tried everything that I can think of, but I always end up with either missing references or multiply defined symbols. I've tried building using both MS Visual C++ and Borland C++Builder, but with no success.
    Has anybody succeeded in building a C++ client? Surely it shouldn't be this difficult?
    Thanks,
    Tony

    Thank u for taking care of me
    But the hint given by u is not apt to my query.
    If any new suggestion pls send again

  • Accessing  java service from c++ client through wsdl

    Java service is deployed in SOAP. It has to be accessed by the client program written in c++ language. It should be done through WSDL.
    If anyone had previously faced or came to know abt this problem.
    Pls inform me abt the process.

    Thank u for taking care of me
    But the hint given by u is not apt to my query.
    If any new suggestion pls send again

  • Accessing java fields from c++

    I have created a JNI app that needs to access the fields of the java object but when I try to access them I get an error message saying "no such field."
    When I created my header file with javah I got (JNIEnv *, jclass and jobject) as my parameter list not JNIEnv * and jobject like all the documentation does.
    then i try to access the fields with :
    fidZone = env->GetFieldID(cls, "zone","I");
    which generates the error mentioned.
    Any suggestions will be greatly appreciated.
    Cheers.

    1. Here is the native code:
    #include <jni.h>
    #include <stdio.h>
    #include "worldfl.h"
    //header for external DLL I want to access
    #include "GDAit.h"
    JNIEXPORT jlong JNICALL
    Java_worldfl_TransProjectPt(JNIEnv *env, jclass cls, jobject obj)
    jfieldID fidx, fidy, fidStr, fidZone, fidTrDir;
    long zone, agd2gda, iResult = 0;
    double transX, transY, newX, newY, accX, accY;
    /* GET the X & Y values of the coords in the world file */
    cls = env->GetObjectClass(obj);
    printf("%ld\n", cls);
    if (cls != NULL)
    fidZone = env->GetFieldID(cls, "zone","I");
    fidTrDir = env->GetFieldID(cls, "agd2gda","I");
    fidx = env->GetFieldID(cls, "transX","D");
    fidy = env->GetFieldID(cls, "transY","D");
    /*fidStr = env->GetFieldID(cls, "filename","Ljava.lang.String");*/
    transX = env->GetDoubleField(obj, fidx);
    transY = env->GetDoubleField(obj, fidy);
    zone = env->GetDoubleField(obj, fidZone);
    agd2gda = env->GetDoubleField(obj, fidTrDir);
    iResult = 0;//TransProjPt("f:\\coordcalcs\\A66 National (13.09.01).gsb", agd2gda, transX, transY, zone, &newX, &newY, &accX, &accY);
    else
    printf("Class is NULL\n");
    //env->GetDoubleField(obj, fidx) = newX;
    //env->GetDoubleField(obj, fidy) = newY;
    return(iResult);
    2. Yes it is defined as static
    private native static long TransProjectPt(worldRead wr);

  • Accessing Java Strings from C

    I use this as the docs say, to convert:
    JNIEXPORT jstring JNICALL
    Java_SpeedProcess_exec(JNIEnv *env, jobject obj, jstring prompt)
    char buf[128];
    const char str = (env)->GetStringUTFChars(env, prompt, 0);
    printf("%s", str);
    (*env)->ReleaseStringUTFChars(env, prompt, str);
    but when I try to compile, I get:
    Compiling...
    HelloWorldImp.cpp
    c:\java\NativeCode\HelloWorldImp.cpp(13) : error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
    c:\Program Files\j2sdk_nb\j2sdk1.4.2\include\jni.h(750) : see declaration of 'JNIEnv_'
    did you intend to use '.' instead?
    c:\java\NativeCode\HelloWorldImp.cpp(13) : error C2227: left of '->GetStringUTFChars' must point to class/struct/union
    type is 'JNIEnv'
    did you intend to use '.' instead?
    c:\java\NativeCode\HelloWorldImp.cpp(15) : error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
    c:\Program Files\j2sdk_nb\j2sdk1.4.2\include\jni.h(750) : see declaration of 'JNIEnv_'
    did you intend to use '.' instead?
    c:\java\NativeCode\HelloWorldImp.cpp(15) : error C2227: left of '->ReleaseStringUTFChars' must point to class/struct/union
    type is 'JNIEnv'
    did you intend to use '.' instead?
    c:\java\NativeCode\HelloWorldImp.cpp(50) : error C2561: 'Java_SpeedProcess_exec' : function must return a value
    c:\java\NativeCode\HelloWorldImp.cpp(9) : see declaration of 'Java_SpeedProcess_exec'
    Build log was saved at "file://c:\java\NativeCode\Debug\BuildLog.htm"
    NativeCode - 5 error(s), 0 warning(s)
    Anyone?

    I solved it, thanks

  • Accessing a webpage from inside a program

    Hi there,
    I have an html webpage with some statistics.
    I wish to write a program that:
    - downloads the webpage from the internet and saves it on my computer,
    - reads through it character by character like a text file, extracting the bits of interest
    - displays them in a nice little window.
    Ideally it would run as a "daemon" (I think) in the background, updating itself every x minutes.
    I have never written any internet related java programs before, can anyone explain to me how I could carry out the first part or point me in the direction of a suitable tutorial.
    I thought one possible (but definitely non-ideal) solution would be to use external command line ftp to download the html page, but that wouldn't be very portable. I had considered writing this program as a firefox extension but I would prefer it to be stand alone.
    Thanks for any help,
    Austin.

    can anyone explain to me how I could carry out the first part or point me in the direction of a suitable tutorial.Sun's Tutorial deals with reading a URL here: http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html Other sections deal with writing the output to a file (instead of just using System.out.println()).

Maybe you are looking for

  • Problem in Outbound Idoc Scenario with change pointers

    Hi All, I have a requirement where i have to create an outbound scenario, whenever i create or change in transaction PAL1 (Create Sales Representative), an idoc should be triggered. i have created - ZBasic idoc type - ZSegments And have assigned the

  • Insert date from YUI calendar into mysql table

    Is there a way to insert the date selected from the YUI calendar into a mysql table?

  • Change Purchasing Organization in a Contract

    Hi, it's possible to change the Purchasing Organization in a Contract? it looks for in the status fields and encounter this field not to put it like optional. With transaction MEMASSCONTRACT yes it lets to me modify the Purchsing Organization but wit

  • Media Player dumps content

    The win7 media player has suddenly dumped all of the albums and song lists I count on.  It appears that the music is still in the My Music folder but totally without organization and there are a lot of unknown and empty albums.   80% of the content i

  • No sound Satellite R15-S822

    After uninstalling Disney's Alice in Wonderland game, I no longer have sound. I am running XP-sp2. I also lost my keyboard and am using the input panel to type this. HELP! Chris Solved! Go to Solution.