Okay I need both java and C compilers to work on my pc.
So I have set the path variable of C and now I need to set java's path, so for that can I set the path variable of java in the same PATH (where I set path for C) or do I need to create a separate PATH for setting it up? Some one please help.
If I set both in a same path, then will anything go wrong? Sorry I am new to this, please bear with me. Thanks
It would matter if there were any name collisions. To my knowledge there's no such, but since there are many C compilers and much more stuff for them, and the most important java stuff starts with 'java', just add the Java path AFTER the gcc/mingw path
SET PATH=%PATH%;%MINGW_PATH%\bin;%JAVA_PATH%\bin
I am introducing you to what is PATH variable ?
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.
On POSIX and Unix-like operating systems, the $PATH variable is specified as a list of one or more directory names separated by colon (:) characters
On DOS, OS/2, and Windows operating systems, the %PATH% variable is specified as a list of one or more directory names separated by semicolon (;) characters.[3]
Note : The above is an excerpt from WIKI
For Windows, you can set the path
SET PATH=%PATH%;%MINGW_HOME%\bin;%JAVA_HOME%\bin
For Unix-like operating systems, you can do
SET PATH=%PATH%;\home\%MINGW_HOME%\bin;\home\%JAVA_HOME%\bin
Related
Does anyone have an idea on how to call something from JDK_INSTALL_FIR/bin using:
Runtime.getRuntime().exec(cmd)
Without having to care about OS terminal specifics like escaping or quoting spaces in paths on Windows or concatenating .exe at the end of the command.
In other words I want to make this work on Windows:
Runtime.getRuntime().exec("C:\Program Files (x86)\Java\jdk1.7.0_45\bin\java -version")
I'm open to any solutions like bundling my own JDK, or generally anything that will save me from checking what OS I'm currently running on.
Thanks.
Java path is saved in system variables (mostly)
try something like:
System.out.println(System.getenv("JAVA_HOME"));
Which should return path to java (not sure about "JAVA-HOME" )
It is from:
How can I get System variable value in Java?
Generally I advice using:
System.getenv(String);
method:
getenv documentation
i am relatively new to java. when i installed jdk and jre on my laptop it asked me to set a system variable with the name path and a value of its home directory. next i installed tomcat server and that too asked me to set CATALINA_HOME,JAVA_HOME and path as its home directory.now after mysql installation it also said a variable of path with its home directory value.will it not effect the old s/w if i change path variable to new software variable address?? or should i create new paths for each software??
CATALINA_HOME and JAVA_HOME are separate variables and should be set separately.
As for the PATH, this is one variable and should contain all necessary values separated by the ; character.
Just curious as to when System.getProperty("java.io.tmpdir") returns "c:\temp". According to the java.io.File Java Docs-
The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\temp". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the the temporary directory used by this method.
But in my case-
System.out.println(System.getProperty("java.io.tmpdir"));
Always returns-
C:\Users\admin\AppData\Local\Temp\ i.e. %TEMP%
In what conditions will it return "c:\temp"?
EDITED: If I change %TEMP% to C:\Temp then I will get C:\Temp, right? But the documentation shows c:\Temp instead of C:\Temp.
In MS Windows the temporary directory is set by the environment variable TEMP. In XP, the temporary directory was set per-user as Local Settings\Temp.
If you change your TEMP environment variable to C:\temp, then you get the same when you run :
System.out.println(System.getProperty("java.io.tmpdir"));
If you set
-Djava.io.tmpdir=C:\temp
On the one hand, when you call System.getProperty("java.io.tmpdir") instruction, Java calls the Win32 API's function GetTempPath.
According to the MSDN :
The GetTempPath function checks for the existence of environment
variables in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
On the other hand, please check the historical reasons on why TMP and TEMP coexist. It's really worth reading.
Value of %TEMP% environment variable is often user-specific and Windows sets it up with regard to currently logged in user account. Some user accounts may have no user profile, for example when your process runs as a service on SYSTEM, LOCALSYSTEM or other built-in account, or is invoked by IIS application with AppPool identity with Create user profile option disabled. So even when you do not overwrite %TEMP% variable explicitly, Windows may use c:\temp or even c:\windows\temp folders for, lets say, non-usual user accounts. And what's more important, process might have no access rights to this directory!
Using Java,
How can I add environment variable permanently to the existing env variables.
so that when I do a restart operation for windows or Linux, this environment variable is still there.
You might want to take a look at this.
In Windows you can set a Path Variable from command line so it should do the trick.
I realize this is only applicable to Windows.
Not in any cross platform sort of way. In Linux, these are typically controlled via shell init scripts. You would have to edit one of those (which one depends on the user, system, and shell type). In Windows, this is controlled via system configuration (i'd imagine there are some windows specific APIs to modify those).
coppy the path of jdk upto C:\Program Files\Java\jdk1.6.0\bin from program and past in user variables and put ;.; at the end and give name .
and in system variables click on new and enter the name and past the path....and save ...
go to command prompt
..
to check current paths >echo %path%
to set path >set path="C:\Program Files\Java\jdk1.6.0\bin" enter ok now check and run java program
Environment variables are platform specific. Windows stores them in Registry.
*In the registry the User environment variables are stored at
HKEY_CURRENT_USER\Environment
and the System environment variables are stored at
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
(from http://demins.blogspot.co.il/2007/10/where-does-windows-xp-store-evrironment.html)*
There are a lot of ways to access windows registry from java. You can for example execute command line using utility named reg that has a reach command line. You can also use one of interoparability APIs like JaWin, Jinterop, Jintegra. You can also refer to my solution explained here.
On linux you can use command line like export MYVAR=myvalue. I mean execute this command line from java using Runtime.exec() or ProcessBuilder. The problem is that this variable will not become really persistent. It will be visiable for all users until the computers is restarted. To make it really persistent you have to modify user login script (e.g. bashrc file for most linux systems if users's default shell is bash).
I'm looking at http://akuma.kohsuke.org/, but it's only for POSIX systems. I don't need daemonization, just an orderly way to launch more jvms from a java program. Yes, ProcessBuilder, but how do I find the right java.exe?
System property java.home contains path to current java home. For example on my computer it is C:\Program Files\Java\jdk1.6.0_21\jre.
So, the following statement System.getProperty("java.home") + "/bin/java" should give you the fully qualified path to your current JVM.
If you want to be even more cross platform use File.separator instead of slash.