How To Set Classpath in Java

0
208
Spread the love
  • 28
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    137
    Shares

Set Classpath in Java
Set Classpath in Java

What is Class path in Java?

Once you install java this settings are not immediate required.It is only required when you try to run java programs from other than bin folder. Without the class path settings one can run Java programs from bin folder. But after number of coding code , the bin folder looks very unorganized. Even if you have created and archived the source and .class files to another folder. To run them you need to bring them into bin folder.

It would have been great if we could create our own folder structure place required source code and .class files into them and could run.

How to set classpath in java?

Yes!! if you are thinking this then this post is for you. To solve this problem we need to set classpath for java.
Lets see how:

Step 1: First install java software,say in E drive or in C drive inside folder j2sdk1.4.2_01 or java

How to Set Classpath in Java?
How to Set Classpath in Java?


Step 2: Now,set the class path.
Step 3: Go to ‘My Computer’.
Step 4: Right click on mouse and go to ‘Properties’.

Classpath in Java
Classpath in Java


Step 5: Go to ‘Advanced’ on the ‘System Properties’. then click on ‘Environment Variables’

Class path settings in Java
Class path settings in Java


Step 6: In User Variables click ‘New’.

Class path settings in Java
Class path settings in Java
 
Class path settings in Java
Class path settings in Java
 


Step 7: Write ‘JAVA_HOME’ in Variable name and the path where the software is installed in Variable value.And then click ‘OK’.
Step 8: In System variables, click new and give the values as in figure.And then click ‘OK’.
Step 9: In System variables, there will be a variable named ‘Path’. Double click there. A new window will come. In ‘Variable value’ give a semi-colon after whatever is written. After that write ‘%Path%;C:j2sdk1.4.2_01lib;.;’  (if the software is installed in j2sdk1.4.2_01 folder of C drive.for this device it is in E:javalib And click ‘OK’ wherever required.

Class path settings in Java
Class path settings in Java


Hope you enjoyed this post. Please consider sharing this article .Also let me know if you face any issue regarding the same.

ClassPath tester

This below write-up is about a tiny basic selection of batch information which can be utilized to examination the actions of the javac compiler and java class launcher for various classpath eventualities. The method is called ClasspathTester.

When you are in the center of striving to debug a java develop it is a terrible time to attempt to boil everything down to a straightforward take a look at scenario, so generally the intent of my take a look at collection is to do this for you ahead of time. If you can’t locate the precise check you require, it is simple to modify the present exams or make a new exam to match your requires.

How ClasspathTester Is effective?

As previously mentioned, I did almost everything with batch files, for the reason that I required the tests to be as uncomplicated, portable (inside the Home windows surroundings), and very simple as possible. There are a couple of helper batch files to do issues like make formatted output and make a directory construction, but or else virtually all of the get the job done is accomplished in the RunAllTests.bat file.

What RunAllTests.bat is made up of is tests and sub-tests. If you haven’t downloaded it nonetheless, I suggest you download it and get a glance. Just about every examination is composed of some kind of a set up. Set up generally involves the pursuing:

1. Exam surroundings is cleaned up of outdated directories, files, and classpath.

2. New listing structure is created, new data files are made and placed in right directories, and the classpath is established if vital.

Just after set up, the assessments are run. This is composed of functioning possibly the javac.exe compiler, the java.exe launcher, or equally. Which is all there is to it.

A Simple Case in point

To fully grasp what ClasspathTester, does, open the RunAllTests.bat file in your text editor and search at Test1. Each check is a assortment of sub-tests which are loosely grouped about some kind of a central screening theme, and Examination1 is a single of the most straightforward.

So what transpires in Test1? Initial it phone calls banner.bat to insert a header to the success file. Then it results in the Good day.java and MyLibClass.java files, by copying them from their corresponding avaj information (the rationale for utilizing avaj documents is discussed later on in this short article). Now every little thing is set up to run some subtests.

Exam1A is very simple. In accordance to its description, ” The Hello.java file is located in the current listing, and the Hi there.class file will be prepared to the existing directory and operate from the latest directory”. As you can imagine, Exam1A operates flawlessly.

Check1B and Take a look at1C are made to demonstrate unique means that making use of java.exe to start the Hi.class file can are unsuccessful. In Exam1B the classpath is been set to an vacant directory. In Take a look at1C the file Hello.class is erased. Curiously, these two exams fall short in specifically the similar way.

Be aware that all assessments effects are stored in the benefits.log file.

How the Tests are Kept Safe and sound?

By “harmless” I mean secure to your personal computer, harmless to your other facts. Because the checks entail batch data files that are building and destroying files and directories, treatment have to be taken to stay away from accidentally destroying or creating more than other unrelated data files. This is attained in the cleanup.bat file by keeping away from the use of statements like “erase /S *.*” or “rmdir /S *”. In its place, all erasures are kept rather certain.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 28
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    137
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here