How to distinguish same jars started from different directories? - java

I started several (eight) jar files with the same name from different directories and different config files.
Now I have to kill a specific one. But neither jps and ps gives enough information to distinguish them. How could I find out which java process was started from which directory?
Platform : linux (ubuntu server)

from the man page it says: use option e to show the environment variables after the command.
so try using the 'e' option:
ps e
you can then look for PWD variable. I hope this will help.

Related

java : how to know from where the libraries are loaded at runtime

I have a issue where a jar file runs on one machine , but not on another machine -
asked on stackoverflow.
It seems some dependencies are not found on the second computer. My question is, is there a way to know from where the libraries are loaded (as in - to simply System.out.println("from which directory the dependent jar is linked")) ?
This will output a lot of information, but it includes the location of all jar files:
You can start Java with the -verbose:class option to debug classloader issues.
You maybe could use jcmd (part of the JDK) and query the JVM which class path it was using at its startup.
jcmd ${pid_of_the_JVM} VM.system_properties | grep path
in the output have a look for the properties
java.class.path
sun.boot.class.path

System Startup Folders/Methods on UNIX Platforms?

I have a Java application that needs to implement installation features of making a JAR launch on startup.
I can do this on Window by entering a REG file into the registry, but how can I do this on UNIX platforms? Linux and Mac if the methods are different.
Do Linux and Mac have system startup folders?
Remember that I need to do this programmatically not through system preferences or anything like that.
On Linux, the classic way would be through adding a script in the appropriate /etc/rcN.d/ directory (where N is a number 0-6 representing the 'run level'). I'm not sure whether that's still the recommended way, but it usually is still supported. This would also work with minor variations for other mainstream Unix variants (Solaris, HP-UX, AIX).
On Mac, you have to work harder. The files /etc/rc.common, /etc/rc.imaging and /etc/rc.netboot are related, but there are no /etc/rcN.d directories. There's also a script rc and another rc.local. Typing man rc reveals:
DESCRIPTION
rc.local is now unsupported and has been replaced with launchd(8), which bootstraps itself via the launchctl(1) bootstrap subcommand to read in launchd(8) jobs from the standard locations.
SEE ALSO
launchd(8), launchctl(1)
So, you should investigate launchctl and launchd, particularly launchctl.
This is how I would do it on ubuntu.
First create a bash script to run the java app, similar to.
#!/bin/bash
java -jar "helloworld.jar"
and save it, in this case called 'HELLOWORLD' in /etc/init.d.
Need to make the script executable so need to run
chmod +x HELLOWORLD
Finally to make it run on start up
update-rc.d HELLOWORLD defaults
On Macs I think its launchd, and on linux its init.d. They are config files.

Check if a program is installed on a linux machine from a java applet

Hi I need to be able to check if a certain software is installed on the clients computer and where, in order to launch it. I found the following three posts as to how to do so on Windows and Mac but I can't seem to figure it out for Linux as there is no registry. Does any one know how this can be done on Linux?
Similar posts for Windows and Mac:
Can a Java applet open a "select directory" and write to a filesystem via JavaScript interaction?
read/write to Windows Registry using Java
How can I see the software installed in a Mac OS using a java application?
any help would be greatly appreciated :)
Assuming your security context allows it, you could call out to which.
$ which java
/usr/bin/java
which will output nothing if the program is not found.
Use the
which file
command to find out if the software is installed in the path. If that comes up with nothing then you could do a
find ./ -name "file"
Also check their local bin or .bin if its not included in the path.
Well, basically every binary installed on Linux is in the PATH (environment variable), so if you can find it there, it's there.
There may also be software that installs into other paths, but in this case the user would need to point them out. It is a very uncommon case to have an application in a seperate path and not adding that one to PATH.

Jboss server error : why it cause

why the error occurs when i am starting the jboss server 6.0 ?
'findstr' is not recognized as an internal or external command,
operable program or batch file.
It looks like your PATH environment variable hasn't been set up correctly. Does this link help?
http://community.jboss.org/wiki/FindstrCommandNotFound
EDIT: are you sure that the JBoss startup batch script (usually in %JBOSS_HOME%\bin\run.bat) is picking up the PATH correctly? It might be running as a different user with a different PATH. Edit this script and add the line echo %PATH% before the first line that contains findstr. What output does this give you?
The only other place findstr is used (in jboss-6.0.0.20100721-M4 anyway) is in the service.bat script in the same folder as run.bat . Again, you could try putting echo %PATH% before the line in this script that uses findstr if the previous step didn't help you.
EDIT 2: according to your comments, the echo %PATH% line I asked you to add gave the following output:
E:\jdk1.6\bin;E:\apache-ant-1.7.0\bin;E:\jboss-6.0\bin\run.bat
Clearly this doesn't contain C:\WINDOWS\system32, so JBoss definitely won't be able to find findstr. But I don't understand why the PATH is ending up like this. How are you starting JBoss - as a service or by running run.bat? Is JBoss being run under some user account which has been set up with a very restricted PATH? Do you have some other script which is manipulating the PATH before JBoss starts? Also, which version of Windows are you using?
Also, it's not immediately clear to me from your three comments
I'm already checked that the findstr application is already in that path C:\WINDOWS\system32\
E:\jboss-6.0\bin\run.bat
Am also set that in the system variables in Environmental Variables
whether C:\WINDOWS\system32 is in the PATH in Control Panel > System > Environment Variables. Is C:\WINDOWS\system32 in the PATH in the System Variables section within the Environment Variables dialog?
This doesn't seem to be an issue with JBoss. This seems to be more of an issue with the environment within which you are running it. I can quite imagine a lot of other programs would be unhappy with being run in a similar environment.

How to get the list of java processes along with their PID(process id) that are running on UAT server under a specfic account?

Problem:
A jar file was failed to deploy on a UAT server.
Reason:
Because when we are trying to rename it,it is showing
"cannot rename the file it is been used by another user".
step choosen in order to solve the problem
log on UAT server(xxx).
we need the list of java processes along with the PID on our UAT server
which is running under the account XXXAPPFUNC.
Please tell me how can I do this?
Thanks in Advance.
Did you try the jps tool?
DESCRIPTION
The jps tool lists the instrumented
HotSpot Java Virtual Machines (JVMs)
on the target system. The tool is
limited to reporting information on
JVMs for which it has the access
permissions.
...
The list of JVMs produced by the jps
command may be limited by the
permissions granted to the principal
running the command. The command will
only list the JVMs for which the
principle has access rights as
determined by operating system
specific access control mechanisms.
...
OUTPUT FORMAT
The output of the jps command follows the following pattern:
lvmid [ [ classname | JARfilename | "Unknown"] [ arg* ] [jvmarg* ] ]
For example, to list the instrumented JVMs on the local host:
$ jps
18027 Java2Demo.JAR
18032 jps
18005 jstat
Run it under the desired account.
Have you tried Process Explorer
"Ever wondered which program has a particular file or directory open? Now you can find out. Process Explorer shows you information about which handles and DLLs processes have opened or loaded."
Doesn't just work for java processes.

Categories