how to get running jvms in current machine - jvm

Imagine that: Two java projects are work on JDK1.5 and JDK1.6
Two are work on JDK 1.7.
How to get the running jvm names, pids and projects name works on it.
the result should LOOKS LIKE:
pid 1234, projec_tname prj1, java_version JDK1.6
pid 4354, projec_tname prj2, java_version JDK1.5
pid 6234, projec_tname prj3, java_version JDK1.7
pid 9034, projec_tname prj4, java_version JDK1.7
Solution in Is there a Java library that searches for JVMs on the current machine? is find JDKs in current machine which not running. It is not helped for my question. Any ideas?

You are looking for this API: http://docs.oracle.com/javase/7/docs/jdk/api/attach/spec/
You have to add the tools.jar to your classpath.
This is the method to start with: VirtualMachine.list()
The id()s are provider specific but it’s usually a process id.

Related

jackrabbit - There is an error in invoking javac. A full JDK (not just JRE) is required

I'm learning Jackrabbit and following the documentation to run a standalone server. When I run the command java -jar jackrabbit-standalone-2.16.2.jar and access localhost:8080 on my browser, I get a 500 error saying:
org.apache.jasper.JasperException: PWC6345: There is an error in invoking javac. A full JDK (not just JRE) is required
What am I doing wrong?
Note: I have set my jdk/bin path in my environment variables.Also, my javac command is working properly. I've jdk version 1.8.0_74 and Jackrabbit version 2.16.2
Edit: According to this answer, I tried setting my jdk to my installed jres in eclipse but that didn't solve my problem.
Running the latest jackarabit standalone jar(2.17.3) in my machine(windows 10 and java home pointing in java8 jdk) produced the same errors.
I then executed the rar with java -Djava.home="%JAVA_HOME%" -jar jackrabbit-standalone-2.17.3.jar. Although I got the same error in browser I was able to see errors in the console where I invoked the running command.
One of these error was
can't open C:\Progra~1\Java\jdk1.8.0_144\lib\tzmappings.
Searching my java installation I found that the missing files, are located under jre's installation folder.
So I eventually made the standalone jar to work with:
java -Djava.home="%JAVA_HOME%\jre" -jar jackrabbit-standalone-2.17.3.jar
The initial error is a bit misleading as it refers to javac and not to the missing files.
The whole thing seems to be a bug for me. Please give a try to my workaround and if it works for you consider filing a bug in Jackrabbit's issue tracker platform.
jackrabbit-standalone uses JSP. JSP needs compilation. Compilation needs JDK.
Before running java -jar jackrabbit-standalone-2.16.2.jar do you check your JAVA_HOME, and make sure it refers to a fully-fledged JDK? In short, the bin directory should have javac.
I found that there was another variable in the Path environment System variable preceding my %JAVA_HOME%\bin variable.
You don't have to delete the other variable, but move it down (or move %JAVA_HOME\bin up) to correct the load order.

AttachNotSupportedException when trying to start a JFR recording

I'm receiving AttachNotSupportedException when trying to start a JFR recording.
It was working normally, until now.
jcmd 3658 JFR.start maxsize=100M filename=jfr_1.jfr dumponexit=true settings=profile
Output:
3658:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
What might be happening?
SO: Oracle Linux Server release 6.7
$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
One of the probable reasons is that /tmp/.java_pid1234 file has been deleted (where 1234 is PID of a Java process).
Tools that depend on Dynamic Attach Mechanism (jstack, jmap, jcmd, jinfo) communicate to JVM through a UNIX domain socket created at /tmp.
This socket is created by JVM lazily on the first attach attempt or eagerly at JVM initialization if -XX:+StartAttachListener flag is specified.
Once the file corresponding to the socket is deleted, tools cannot connect to the target process, and unfortunately there is no way to re-create communication socket without restarting JVM.
For the description of Dynamic Attach Mechanism see this answer.
With personal experience... This problem also occurs in scenarios where the development environment is divided into partitions, and the partition where the operating system is located is different from the operating system partition. Example, operating system partition is EXT4 and the development environment partition is NTFS (where the JVM is). Problem occurs because you can not create a file "/tmp/.java_pid6024" (where 6024 is the PID of the java process).
To troubleshoot add -XX: + StartAttachListener at the start of the JVM, or application server.
Another possibility: your app is running under systemd with 'PrivateTmp=yes'. This prevents the /tmp/.java_pid1234 file from being found.

CFEngine. I want to distribute a set of files which are different for different versions of ubuntu for eg 13.04 and 14.04.

I googled it up and read through but did'nt find any answer. I am using cfengine-community 3.5 version on ubuntu.
You can create different subdirectory trees for each of the versions of Ubuntu that you're dealing with; i.e.:
/data/cfengine3/data/ubuntu-13.04
/data/cfengine3/data/ubuntu-14.04
...
Then define one class per version of Ubuntu (ubuntu_13_04, ubuntu_14_04...) and execute the copying of files of one subdirectory or the other, depending on the class that is defined.
We do it like this, because we still have a small set of servers with CentOS 5.

How to get the path/name to java binary running my application?

That is the question: my Java application is running, so how to get the path/name to the java binary that is running it? For example, 'C:\Program Files\Java\jre6\bin\java.exe' in Windows or '/usr/bin/java' in Linux. I need a platform independent solution, preferably relying only on the JDK.
The context for the question is the following. I'm developing two Java applications, let's say FirstApplication and SecondApplication. The FirstApplication will start the SecondApplication using the ProcessBuilder API. The problem is that I need to tell the path to the Java binary to start the SecondApplication. For example,
String cmd = "C:\Program Files\Java\jre6\bin\java.exe -cp <second application classpath> com.secondapplication.MainClass";
Process p = new ProcessBuilder(cmd).start();
Possible alternative solutions to this could be assume that there is a java binary available through the PATH system variable, or assume that the JAVA_HOME system variable is set. But this may not be always the case. Also, the final user of the application (targeting to other Java developers, as well as final users) may have more than one JVM installed on his system, and may execute the FirstApplication expliciting what JVM he wants. Ideally, the SecondAplication should run using the exact same Java binary as the FirstApplication, without relying on such system variables.
Thank you

Jdeveloper - Unrecognized option: -jrockit

Every time I try to run a weblogic webcenter application on Jdev I get the following error and I cant find any reference on how to fix this anywhere on the web.
starting weblogic with Java version: Could not create the Java virtual
machine. Unrecognized option: -jrockit
Try modifying the startWebLogic.cmd file (WIN7)
c:\users\{user}\AppData\Roaming\JDeveloper\system{version}\DefaultDomain\bin\startWebLogic.cmd
to contain
set JAVA_VM=-server
set MEM_ARGS=-Xms512m -Xmx1024m -XX:MaxPermSize=512m
Jdeveloper 11g do not support jdk 1.7
https://forums.oracle.com/thread/2482850
I fixed it by add to top of c:\users{user}\AppData\Roaming\JDeveloper\system{version}\DefaultDomain\bin\setDomainEnv.cmd:
set SUN_JAVA_HOME=E:\Oracle\Java\jdk1.6.0_37
set JAVA_VENDOR=Sun
In OSX, look for the this folder /Users/{USERNAME}/.jdeveloper/system{VERSION}/DefaultDomain/bin
Edit the file setDomainEnv.sh and look for SUN_JAVA_HOME and make sure the value is the same value as your JAVA_HOME, i.e. /Library/Java/JavaVirtualMachines/jdk${JDK_VERSION}.jdk/Contents/Home, by default it seems it is set to an empty string "".
Edit the file startWebLogic.sh and add the following before setDomainEnv.sh is called.
JAVA_VENDOR=Sun
You can test it out by running sh ./startWebLogic.sh, if it runs with -jrockit error, then all is good :)
I've also tested with Java JDK 1.7 and it seems to work.
The reason is, that older Weblogic Versions use the Java VM "JRockit"
http://www.oracle.com/technetwork/middleware/jrockit/overview/index.html
The JRockit VM is no longer supported in Java 7 or higher.
All of the other solutions here seem to be hacks and none of them helped me.
I had the same Problem with a Weblogic 10.3.5 and I found out, the installation was incorrect.
The Problem is, that there is no java version check in the installer, so if you don't know that you can't use Java 7 or higher you are screwed.
These steps fixed it for me:
You need to make sure you have Java 6 or lower installed.
Reinstall the Weblogic and make sure to specify the correct JDK