Thursday, February 26, 2009

How To Get A Homemade Trailer Title In Il



Well, as we begin to program in Java, there is always question: What is the Classpath? Well, it's very simple, as the name implies is the classpath that will be used to compile and / or run a program. And his role is to access classes outside the project, how some external library, there are two main ways to configure a Classpath, the 1st is to set an environment variable named CLASSPATH system, and there you go placing each of the folders or files *. jar we have. The 2nd is writing directly to the Classpath Compiling as a parameter to the compiler in this way:

 
javac-cp "PATH"
HolaMundo.java

Well now, to find a use, imagine that we have a standard library of classes the folder C: / lib, and there is the class "Libreria"

 
public class Bookstore {public static


void print (String message) {
System.out.println (message);
}}




Now imagine you want to use it in another program:
 

public class HelloWorld {public static void main
( String [] args) {

Library l = new Library ();
l.imprimir ("Hello World");
}}




order to compile this, we must tell the compiler the CLASSPATH, which will be used to compile the classes and for that we do this:

 
javac-cp "C: \\ lib"
HolaMundo.java

And also to run the program requires specifying the classpath in the same manner as otherwise get NoClassDefFoundError, because you will not find all the necessary classes. So what we do is very similar, except that this time we must also specify the path where we are and this is done with a "point":

 
java-cp "C: \\ lib;." HelloWorld


And with that we can run our class.


Greetings!

0 comments:

Post a Comment