Replace ClassName with the classname (no file extension) that contains your main() method. To execute your code, run the following command: To run your code, you need to know which class has the main() method. Double-check that your classpath is setup correctly. In this case, javac cannot figure out where the third-party libraries like junit are located. Those are the files necessary to execute your Java code.Ī common error if you do not have your classpath setup properly will be similar to: error: package org.junit does not exist Now, when you ls your directory, you should notice you also have *.class files. You first need to compile these files using Java.
#Compiling java in terminal with third party libraries code#
Remember, Java source code is always stored a *.java file. Make sure you are currently in the directory with your source code files. (It is okay if there are extra directories in the output.) Compile You should see all of the directories you specified in your $CLASSPATH variable above. If it is setup correctly, you will see something similar to the following: If that looks correct, run the following command as well: You should see somewhere in the output the following lines (there may be other lines as well): To test that everything is setup, try the following command: You can also add that directory (or any other) to your $CLASSPATH variable by adding the additional line:Įxport CLASSPATH="$CLASSPATH:/home/public/cs212/libraries/*" For example, the CS 212 course places third-party libraries at /home/public/cs212/libraries/ on the lab computers. Some classes also provide some third-party libraries for you on the lab computers. If it does not exist yet, go ahead and create it. See the Using Linux via Command Line guide if you are unfamiliar using a text editor via the command line prior to completing this guide.Ĭhange to your home directory (run cd ~ at the prompt) and open the. To do this, you will need to edit a configuration file in your home account.
This becomes especially important when you start using third-party libraries and must include multiple jar files. You need to set your $CLASSPATH variable on the lab computers, or you will be stuck specifying long classpath parameters every time you run java.