connect Java VisualVM to a local application - java

When i try connect Java VisualVM to a local application via an explicit JMX connection with following cmd java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9898 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar javaws.jar it gives an error:
unable to access jarfile javaws.jar.
But, when i use another .jar file it works. But does not work for javaws.jar. What is the reason for this exception.

may be the command is not able to identify the jar file palce.
Try with this option
java -Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9898 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar "%JAVA_HOME%"\jre\lib\javaws.jar

Related

JVM arguments not being passed to java application at run time

I try to give VM parameters (jmx parameters) to run a jar file. For some reason, the VM parameters configured not being passed to the java application at run time (log statement in main method confirms that aswell). Application launches successfully but unable to access jmx service. It all works fine with Intellij though.
JVM_OPTS="-Dcom.sun.management.jmxremote \
-Djava.rmi.server.hostname=localhost \
-Dcom.sun.management.jmxremote.port=8020 \
-Dcom.sun.management.jmxremote.rmi.port=8021 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false"
eval "java $JVM_OPTS -Djava.security.egd=file:/dev/./urandom -jar target/shopfront-0.0.1-SNAPSHOT.jar"
I tried to access jmx via visual vm but I am unsuccessful.
Version: Java 11
I expect to access jmx via visual client
Any help is appreciated!
The above script works fine. It is bash script

JMX and Debugging on Tomcat inside Docker

I am trying to setup IntelliJ to connect to a Tomcat instance running in a Docker container. I would like to be able to use remote debugging and also deploy remotely using JMX.
I can enable remote debugging using the environment variables
JPDA_ADDRESS=8000
JPDA_TRANSPORT=dt_socket
and by starting Tomcat with catalina.sh jpda run, so remote debugging works without a problem.
I can also do this alternatively with
CATALINA_OPTS='-agentlib:jdwp=transport=dt_socket,address=8000,suspend=n,server=y'
and then I don't need to use catalina.sh jpda run
No matter what I do, I cannot get JMX to work. I verified that I have catalina-jmx-remote.jar in /usr/local/tomcat/lib`.
I have tried setting CATALINA_OPTS and JAVA_OPTS to
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.rmi.port=1099
-Djava.rmi.server.hostname=192.168.99.100
-Dcom.sun.management.jmxremote.ssl=false
I have verified that 192.168.99.100 is the IP of my docker machine. I have tried connecting to JMX with VisualJM and IntelliJ, it does not work. I have verified that the port 1099 is open and available from the host.
Tomcat is receiving the JMX args
20-Apr-2016 23:50:14.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.rmi.port=1099 -Djava.rmi.server.hostname=192.168.99.100 -Dcom.sun.management.jmxremote.ssl=false
Why can't I get JMX to work? There is no information available in any logs and this will not work no matter what I try.
Edit: lsof -i :1099 shows nothing running on that port
I am running on Mac OS X. It is a docker-machine but I believe docker uses virualbox on mac because it can't run containers natively.
I have mapped the port. docker ps shows 0.0.0.0:1099->1099/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:8080->8080/tcp. Ports 8080 and 8000 work so 1099 should be mapped correctly too.
I was able to connect when I used 0.0.0.0 for jmxremote.host and server.hostname
HOST=0.0.0.0
java -Xmn100M -XX:+PrintGCDetails -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -Xmx384M $JAVA_OPTS\
-Dcom.sun.management.config.file=/opt/app/management.properties \
-Djava.util.logging.config.file=/opt/app/logging.properties \
-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT \
-Dcom.sun.management.jmxremote.host=$HOST \
-Djava.rmi.server.hostname=$HOST \
-jar /opt/app/app.jar

Undocumented Java command line options?

On a server where I work is a JBoss instance, which has the following command line:
/usr/java/jdk1.6.0_31/bin/java -Dcom.sun.management.jmxremote -Dprogram.name=run.sh -server -Xms464m -Xmx464m -XX:MaxPermSize=128m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.net.inetaddr.ttl=0 -Dcom.sun.management.jmxremote -Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl -Djboss.platform.mbeanserver -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=20071 -Djava.endorsed.dirs=/opt/jboss/lib/endorsed -classpath /opt/jboss/bin/run.jar:/usr/java/jdk1.6.0_31/lib/tools.jar org.jboss.Main -P /opt/jboss/server/default/site-deploy/example.com/boot-1.properties -c default
I have a few questions:
1. I understand that the -D option sets the named property, e.g. -Dsun.rmi.dgc.server.gcInterval=3600000 sets the property sun.rmi.dgc.server.gcInterval to the value 3600000. What about -D options that have no equals sign, like -Dcom.sun.management.jmxremote? What is the value of com.sun.management.jmxremote?
2. I can't find ANY documentation explaining what the -P or -c options do. Neither java -version or man java mentions them. My guess is that -P means "load the properties from the specified file." I have no idea what -c does.
3. The token org.jboss.Main doesn't seem to be part of the preceding -classpath option. Is it the name of the class that Java is telling it to invoke, e.g. how java Foo would invoke a class called Foo?
/usr/java/jdk1.6.0_31/bin/java -Dcom.sun.management.jmxremote -Dprogram.name=run.sh -server -Xms464m -Xmx464m -XX:MaxPermSize=128m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.net.inetaddr.ttl=0 -Dcom.sun.management.jmxremote -Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl -Djboss.platform.mbeanserver -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=20071 -Djava.endorsed.dirs=/opt/jboss/lib/endorsed -classpath /opt/jboss/bin/run.jar:/usr/java/jdk1.6.0_31/lib/tools.jar org.jboss.Main -P /opt/jboss/server/default/site-deploy/example.com/boot-1.properties -c default
1 System property without value means that system property is present, and value is empty string ""
2 those are the command line argument to jboss's Main class
3 that class is coming from one of those jar, open run.jar and validate
The following link documents all of the options to the jboss run.sh script:
Chapter 5. Starting and Stopping JBoss
usage: run.sh [options]
-h, --help Show this help message
-V, --version Show version information
-- Stop processing options
-D<name>[=<value>] Set a system property
-d, --bootdir=<dir> Set the boot patch directory; Must be absolute or url
-p, --patchdir=<dir> Set the patch directory; Must be absolute or url
-n, --netboot=<url> Boot from net with the given url as base
-c, --configuration=<name> Set the server configuration name
-B, --bootlib=<filename> Add an extra library to the front bootclasspath
-L, --library=<filename> Add an extra library to the loaders classpath
-C, --classpath=<url> Add an extra url to the loaders classpath
-P, --properties=<url> Load system properties from the given url
-b, --host=<host or ip> Bind address for all JBoss services
-g, --partition=<name> HA Partition name (default=DefaultDomain)
-u, --udp=<ip> UDP multicast address
-l, --log=<log4j|jdk> Specify the logger plugin type

java running jar via cronjob

I want to setup a Minecraft server, which automatically starts up on system startup.
I use the following script to manually run: /home/mc_ftb/server/start.sh
#! /bin/sh
java -Xms1G -Xmx3G -jar /home/mc_ftb/server/mcpc-plus-1.5.2-R0.2-forge716-B527.jar nogui
The cron to start it on start up looks like that:
mc_ftb Ja ~/server/start.sh
This structure already worked with other mods, like Tekkit, but now with a FTB (NewWorld) mod, I get the error
Exception in thread "main" java.lang.NullPointerException
at cpw.mods.fml.relauncher.FMLRelaunchLog.resetLoggingHandlers(FMLRelaunchLog.java:212)
at cpw.mods.fml.relauncher.FMLRelaunchLog.configureLogging(FMLRelaunchLog.java:191)
at cpw.mods.fml.relauncher.FMLRelaunchLog.log(FMLRelaunchLog.java:242)
at cpw.mods.fml.relauncher.FMLRelaunchLog.info(FMLRelaunchLog.java:274)
at cpw.mods.fml.relauncher.FMLRelauncher.setupHome(FMLRelauncher.java:164)
at cpw.mods.fml.relauncher.FMLRelauncher.relaunchServer(FMLRelauncher.java:147)
at cpw.mods.fml.relauncher.FMLRelauncher.handleServerRelaunch(FMLRelauncher.java:45)
at net.minecraft.server.MinecraftServer.main(MinecraftServer.java:1622)
at org.bukkit.craftbukkit.Main.main(Main.java:21)
Starting the script in a terminal as mc_ftb works fine, but even not with the cronjob, I already tried to start it via exce java ....
The script and the jar file are +x'ed. I'm using the actual stable Debian.
Try adding a 'source /etc/profile' as the first line in your script, this will load the environment variables first.
So replace
#! /bin/sh
java -Xms1G -Xmx3G -jar /home/mc_ftb/server/mcpc-plus-1.5.2-R0.2-forge716-B527.jar
with
#! /bin/sh
source /etc/profile
java -Xms1G -Xmx3G -jar /home/mc_ftb/server/mcpc-plus-1.5.2-R0.2-forge716-B527.jar

foreman can't find java

I'm trying to use foreman to run a java app locally which deploys fine to heroku.
My Procfile looks like this
web: java $JAVA_OPTS -cp target/classes;target/dependency/* Start
but when i do formeman start i get
15:51:21 web.1 | unknown command: java $JAVA_OPTS -cp target/classes;target/dependency/* Start
If I just enter java at the prompt i get java's help text back so its on my path. If I use the full path to the java executable in the Procfile it works, but it'd be cleaner if I didn't need two versions of the Procfile
Is there somethinf funky going on with my path or is foreman not getting the path from my environment?
Could it be the environment variable is the problem?
Windows:
java %JAVA_OPTS% -cp target/classes;target/dependency/* Start
Linux:
java $JAVA_OPTS -cp target/classes:target/dependency/* Start
Looks like the example is a mix of both :-)
Environment variable

Categories

Resources