Commonly used examples:-
1. How to compile a java file?
2. How to run a class file?
3. How to debug a java file?
4. How to set classpath?
5. How to view current classpath?
6. How to set destination of the class file?
7. How to run a compiled class file?
8. How to check version of java running on your system?
9. How to set classpath when class files are in .jar file?
Showing posts with label Classpath. Show all posts
Showing posts with label Classpath. Show all posts
How to set classpath when class files are in .jar file?
Following example shows how to set class path when classes are stored in a .jar or .zip file.
c:> java -classpath C:\java\myclasses.jar utility.testapp.main
Result
The above code sample will produce the following result.
Class path set.
c:> java -classpath C:\java\myclasses.jar utility.testapp.main
Result
The above code sample will produce the following result.
Class path set.
How to view current classpath?
Following example shows how to view current classpath using echo command.
C:> echo %CLASSPATH%
Result
The above code sample will produce the following result.
.;C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip
C:> echo %CLASSPATH%
Result
The above code sample will produce the following result.
.;C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip
How to set classpath?
Following example shows how to set classpath.
C:> java -classpath C:\java\DemoClasses utility.demoapp.main
Result
The above code sample will produce the following result.
Class path set.
C:> java -classpath C:\java\DemoClasses utility.demoapp.main
Result
The above code sample will produce the following result.
Class path set.
How to set multiple classpath in Java?
Following example shows how to set multiple classpath. Multiple class paths are separated by a semicolon.
c:> java -classpath C:\java\MyClasse1;C:\java\MyClass2
utility.testapp.main
Result
The above code sample will produce the following result.
Class path set.
c:> java -classpath C:\java\MyClasse1;C:\java\MyClass2
utility.testapp.main
Result
The above code sample will produce the following result.
Class path set.
Subscribe to:
Posts (Atom)