Full Stack Web Development Internship Program
- 3k Enrolled Learners
- Live Class
In this article, we will cover how to set Java classpath, and take a look at how to set JAVA_HOME as an environment variable in Windows 10 operating system. Following pointers will be covered in this article,
Many programs which are developed in Java require JAVA_HOME to set in an environment variable to execute error-free one example of such program is Tomcat. When we set up environment variables programs search for executable paths like in this case javac will be located. JAVA_HOME should be pointing to JDK but not JRE.
JAVA_HOME is the path to the installation directory of JDK which is not same as JRE installation home the installation path is ‘C:Program FilesJavajdk1.8.0_191’. In JRE_HOME we store the java runtime environment path which is in my case ‘C:Program FilesJavajre1.8.0_191’
Whenever a Java application executes it checks for Java classes in CLASSPATH in order to execute without any error. It commonly contains paths to Jar files with OS path separator in windows it is ‘;’.
If you want to specify classpath while running any program using command line you can use Java -cp “some.jar;someOther.jar” com.edureka.HelloWorld . Here these two jars will be available to the program currently executed. If these jars are set in CLASSPATH environment variable it will be available to all the programs. Also, there is a wildcard * to include all the jar files inside one folder.
If we want to execute java command in command prompt we need to set PATH whose value is always JAVA_HOMEbin. If it is not set but JAVA_HOME is set then you can execute it in the following way C:%JAVA_HOME%/bin/java -version, after this is done you simply have to execute java command.
In windows 10 we need to press Windows Key + Pause Key, which will open the System settings window. Head ahead to Change settings and select Advanced tab.
Press ⊞ Windows Key and click on the search box ‘Type here to search’ .
1. Search advanced system settingsIn the box, which is shown in the screenshot below.
2. Click on the option which says View advanced system settings .
Once you click on System Settings below box will appear head to Advanced tab, click on ‘Environment Variables’.
Click the “New” button Under “System variables” and enter JAVA_HOME as “Variable name” and the path to your Java JDK directory under “Variable value”
In ‘System Variables’ click on the ‘New’ Button and type JAVA_HOME in field ‘Variable name:’ and type in the path of JDK in ‘Variable value:’.
We should add the path as System Variable.
1. In the Environment Variables window under System variables click on the path.
2. Click Edit.
3. In the Edit environment variable window click New.
4. Then type in the following%JAVA_HOME%bin .
Click on OK.
Run Command Prompt
1. Type in the following echo %JAVA_HOME%
This will echo the directory path of JAVA_HOME or it will echo nothing if Variable is not set.
To check version type java -version:
1. Type following in command line tool
This will print out the version of Java as in my case:
java version “1.8.0_191”
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191, mixed mode)
1. In vi editor open /etc/profile # vi /etc/profile .
2. Add export JAVA_HOME=/usr/jdk1.8.0.
3. Add export CLASSPATH=$CLASSPATH:/home/LOG4J_HOME/log4j-2.2.16.jar:..
4. Add export PATH=$PATH:/usr/jdk1.8.0/bin.
5. Run # . /etc/profile to activate these settings.
6. Execute # java -version to verify whether the settings are correct or not.
Now you would have understood “How to Set Classpath in Java”. Thus we have come to an end of this article. If you wish to learn more, check out the Java Online Course by Edureka, a trusted online learning company. Edureka’s Java J2EE and SOA training and certification course is designed to train you for both core and advanced Java concepts along with various Java frameworks like Hibernate & Spring.
Got a question for us? Please mention it in the comments section of this blog and we will get back to you as soon as possible.
|Java Certification Training Course|
Class Starts on 29th October,2022
29th OctoberSAT&SUN (Weekend Batch)
|Java Certification Training Course|
Class Starts on 26th November,2022
26th NovemberSAT&SUN (Weekend Batch)