[graalvm-users] Failed to retrieve RMIServer stub: Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: when trying to invoke JMX

Aleksandar Ivanisevic aleksandar.ivanisevic at 2e-systems.com
Sat May 15 00:35:43 PDT 2021


Hi,

I'm trying to native compile a simple JMX method invoke and it works
when run in a VM, but native-image compiled version complains about
failing to retrieve RMIServer stub. I'm not really a Java programmer
but just a poor old-school sysadmin who has religious objections
spawning a full JVM unnecessarily thousands of times, so I'm kinda
stuck here.

Any hints for me?

Thank you.


[root at cjmx-builder ~]# echo $JAVA_HOME
/root/graalvm-ce-java11-21.1.0/
[root at cjmx-builder ~]# java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05)
OpenJDK 64-Bit Server VM GraalVM CE 21.1.0 (build
11.0.11+8-jvmci-21.1-b05, mixed mode, sharing)
[root at cjmx-builder ~]# cat JmxInvoke.java
import javax.management.*;
import javax.management.remote.*;

public class JmxInvoke {

    public static void main(String... args) throws Exception {
        JMXConnectorFactory.connect(new JMXServiceURL(args[0]))
            .getMBeanServerConnection().invoke(new
ObjectName(args[1]), args[2], new Object[]{}, new String[]{});
    }

}
[root at cjmx-builder ~]# javac JmxInvoke.java
[root at cjmx-builder ~]# java -cp . JmxInvoke
service:jmx:rmi:///jndi/rmi://swrint:30241/jmxrmi
'java.lang:type=Memory' gc
[root at cjmx-builder ~]# native-image -cp . JmxInvoke
[jmxinvoke:2245]    classlist:   2,033.69 ms,  0.96 GB
[jmxinvoke:2245]        (cap):     765.44 ms,  0.96 GB
[jmxinvoke:2245]        setup:   2,700.31 ms,  0.96 GB
[jmxinvoke:2245]     (clinit):     381.67 ms,  2.30 GB
[jmxinvoke:2245]   (typeflow):  16,705.65 ms,  2.30 GB
[jmxinvoke:2245]    (objects):  13,931.55 ms,  2.30 GB
[jmxinvoke:2245]   (features):     783.83 ms,  2.30 GB
[jmxinvoke:2245]     analysis:  32,352.79 ms,  2.30 GB
[jmxinvoke:2245]     universe:     962.89 ms,  2.30 GB
[jmxinvoke:2245]      (parse):   4,555.95 ms,  2.30 GB
[jmxinvoke:2245]     (inline):   2,947.74 ms,  2.38 GB
[jmxinvoke:2245]    (compile):  25,308.87 ms,  2.99 GB
[jmxinvoke:2245]      compile:  34,305.88 ms,  2.99 GB
[jmxinvoke:2245]        image:   2,918.10 ms,  2.97 GB
[jmxinvoke:2245]        write:     395.00 ms,  2.97 GB
# Printing build artifacts to: jmxinvoke.build_artifacts.txt
[jmxinvoke:2245]      [total]:  75,905.88 ms,  2.97 GB
[root at cjmx-builder ~]# ./jmxinvoke
service:jmx:rmi:///jndi/rmi://swrint:30241/jmxrmi
'java.lang:type=Memory' gc
Exception in thread "main" java.io.IOException: Failed to retrieve
RMIServer stub: javax.naming.NoInitialContextException: Need to
specify class name in environment or system property, or in an
application resource file: java.naming.factory.initial
        at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:370)
        at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
        at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:229)
        at JmxInvoke.main(JmxInvoke.java:7)
Caused by: javax.naming.NoInitialContextException: Need to specify
class name in environment or system property, or in an application
resource file: java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:702)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:342)
        at javax.naming.InitialContext.lookup(InitialContext.java:409)
        at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1839)
        at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1813)
        at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:302)
        ... 3 more



More information about the GraalVM-Users mailing list