I got this error message when I was trying to use JMX into the WLP web server, when using the restConnector-2.0 interface in Liberty.
The documentation was not that helpful. Oneproblem was I suffered from the curse of cut and paste, and used a Windows environment variable %JAVA_HOME% instead of using the Linux $JAVA_HOME. Another problem was caused documentation saying add the jar to the class path, and then the class path was ignored.
True documentation.
When you use the -jar option, the JAR file is the source of all user classes, and other user class path settings are ignored. See here.
Unhelpful documentation
Configuring secure JMX connection to Liberty says
jconsole -J-Djava.class.path=...;%WLP_HOME%/clients/restConnector.jar
This was for Windows – on Linux it would be $WLP_HOME – except on my system $WLP_HOME was not set.
jconsole
Some of the jar files are in $JAVA_HOME, you can use the environment variable, or specify it yourself. Note %JAVA_HOME% is windows, so be careful when you use cut and paste.
- jconsole -J-Djava.class.path=$JAVA_HOME/lib/jconsole.jar:$JAVA_HOME/lib/tools.jar:/opt/mqm/web/clients/restConnector.jar
- jconsole -J-Djava.class.path=/usr/lib/jvm/java-8-openjdk-amd64/lib/jconsole.jar:/usr/lib/jvm/java-8-openjdk-amd64/lib/tools.jar:/opt/mqm/web/clients/restConnector.jar
If the window displays “Secure connection failed” restart jconsole and use the -debug option. For me this gave “java.io.IOException jmx.remote.credentials not provided. Set to a String[2] {user,password}”. I entered my userid and password, and this connected successfully.
I could not connect using my .jar file.
I was using JMXQuery to extract the data. I was getting the Error connecting to JMX endpoint: Unsupported protocol: rest message.
Adding the jar file to my class path did not help, as the class path is ignored when using java the -jar parameter.
How to fix it
There are two ways of fixing this.
- Put the required jar file in the extensions path, not the class path
- Use the java -classpath… instead of specifying java -jar
1. You need to have the jar for in the extensions path, not in the class path.
See How classes are found in the Java documentation. It says
- Bootstrap classes – Classes that comprise the Java platform, including the classes in
rt.jar
and several other important jar files. - Extension classes – Classes that use the Java Extension mechanism. These are bundled as
.jar
files located in the extensions directory. - User classes – Classes defined by developers and third parties that do not take advantage of the extension mechanism. You identify the location of these classes using the -classpath option on the command line (the preferred method) or by using the CLASSPATH environment variable.
There is a system property java.ext.dirs which gives the location of the Extension classes. On my system this was
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext:/usr/java/packages/lib/ext
- The /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext: is java dependent. You should not put your files in this directory
- /usr/java/packages/lib/ext This is for “user” extensions.
The directory /usr/java/packages/lib/ext did not exist on my system, so I had to do, create it, copy the web connection jar file to it, and grant permissions on it.
- sudo mkdir -p /usr/java/packages/lib/ext
- sudo cp /opt/mqm/web/clients/restConnector.jar /usr/java/packages/lib/ext/
- sudo chmod 444 /usr/java/packages/lib/ext/restConnector.jar
2. Use a -classpath – not a -jar
In a .jar file there is a META-INF/MANIFEST.MF file which includes information on the entry point.
Manifest-Version: 1.0 Main-Class: src.Client
Instead of using the -jar option to point to the jar, you can use the -classpath to point to the jar and explicitly specify the entry point. For example
java -cp ./Client.jar:/opt/mqm/web/clients/restConnector.jar src/Client service:jmx:rest://localhost:9443/IBMJMXConnectorREST
- java -cp ./Client.jar:/opt/mqm/web/clients/restConnector.jar – use the classpath option, and specify the needed jar files. Client.jar is my program. /opt/mqm/web/clients/restConnector.jar is the Liberty provided jar.
- src/Client – the “entry point” class to use
- service:jmx:rest://localhost:9443/IBMJMXConnectorREST – the url to use.
- note the absence of a -jar option.
In the manifest of the Client.jar file it had Main-Class: src.Client. This is for the the src/Client.java source file. This ties up with the src/Client.class as seen when you use the command jar -tvf Client.jar .
One thought on “Error connecting to JMX endpoint: Unsupported protocol: rest”