LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I get platform specific info in Java (https://www.linuxquestions.org/questions/programming-9/how-do-i-get-platform-specific-info-in-java-591437/)

devn 10-13-2007 12:18 AM

How do I get platform specific info in Java
 
Hi,
I am coding in Java the skeletal structure of a program that uses the p2p system. A centralized server communicates with the clients and when clients want to transfer some file or sth, the server initializes the p2p between the clients.

The communication protocol I am working on is pretty simple for start. The main concern for me is to start the server and the clients on boot. I can achieve this using init scripts at rc* in *IX. But about windows, I am going to use the "reg" system command to add my program at the registry. But looks like its hell of a registry job to do and am not so good at win32 registry hack.

My query, "Is there a generic way I can make my application start at boot time using any java classes?" :scratch:
And I want to know detail about the platform my application is currently running on. How do I fetch that?:rolleyes:

Any suggestion is welcome.

:)

Alien_Hominid 10-13-2007 03:24 AM

Java was created to hide platform specific details from developers. If you need hardware access, use JNI (java native interface) to call OS specific libraries. However, this way your program will need to determine it's working environment and make calls accordingly. Btw, check Java API Runtime class.

How to start a program at boot time is not a java api problem. It should be users prerogative, so each user should modify their environment accordingly.

devn 10-13-2007 11:15 AM

Quote:

However, this way your program will need to determine it's working environment and make calls accordingly. Btw, check Java API Runtime class.
Thanks for the quick reply. Anyway, my main query is actually how to get OS properties, such as the hostname, current user name, platform type (output of uname -a for *IX). Since the problem is platform (only OS, not hardware), I want to get what OS the user is running.

I know System.getProperty is one of the methods, but its doesn't have a rich set of parameters to get system info. Is there any other way?

Plz help...

Alien_Hominid 10-14-2007 07:10 AM

Code:

Key                                  Description of Associated Value

java.version                        Java Runtime Environment version
java.vendor                        Java Runtime Environment vendor
java.vendor.url                Java vendor URL
java.home                        Java installation directory
java.vm.specification.version        Java Virtual Machine specification version
java.vm.specification.vendor        Java Virtual Machine specification vendor
java.vm.specification.name        Java Virtual Machine specification name
java.vm.version                Java Virtual Machine implementation version
java.vm.vendor                        Java Virtual Machine implementation vendor
java.vm.name                        Java Virtual Machine implementation name
java.specification.version        Java Runtime Environment specification version
java.specification.vendor        Java Runtime Environment specification vendor
java.specification.name        Java Runtime Environment specification name
java.class.version                Java class format version number
java.class.path                Java class path
java.library.path                List of paths to search when loading libraries
java.io.tmpdir                        Default temp file path
java.compiler                        Name of JIT compiler to use
java.ext.dirs                        Path of extension directory or directories
os.name                        Operating system name
os.arch                        Operating system architecture
os.version                        Operating system version

file.separator                        File separator ("/" on UNIX)
path.separator                        Path separator (":" on UNIX)
line.separator                        Line separator ("\n" on UNIX)
user.name                        User's account name
user.home                        User's home directory
user.dir                        User's current working directory

What are you missing?

devn 10-15-2007 12:44 AM

Dear Alien_Hominid,
Thanks for the keys. I find it very useful. Thats all I needed.
:D
Actually I will be using win32 registry (by using a system call to reg once I know its win32) to add my application to the Windows startup. For UNIX (actually on Solaris mainly), I will be able to put it up as service in the SMF. I will now be able to do all that in no time.:)
Thanks again.
devN
:jawa:

Alien_Hominid 10-15-2007 12:51 AM

np. I just pasted from manual.


All times are GMT -5. The time now is 06:13 PM.