âšī¸ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | FAIL | download_stamp > now() - 6 MONTH | 7.9 months ago |
| History drop | FAIL | isNull(history_drop_reason) | tooold |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | http://tutoringcenter.cs.usfca.edu/resources/using-java-via-command-line.html |
| Last Crawled | 2025-08-30 13:54:50 (7 months ago) |
| First Indexed | 2013-08-10 11:44:16 (12 years ago) |
| HTTP Status Code | 200 |
| Content | |
| Meta Title | CS Tutoring Center |
| Meta Description | null |
| Meta Canonical | null |
| Boilerpipe Text | Lab Setup 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 . This becomes especially important when you start using third-party libraries and must include multiple jar files. To do this, you will need to edit a configuration file in your home account. 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. Change to your home directory (run cd ~ at the prompt) and open the .bash_profile file. If it does not exist yet, go ahead and create it. Add the following line to the file: export CLASSPATH=".:.*"
Some classes also provide some third-party libraries for you on the lab computers. For example, the CS 212 course places third-party libraries at /home/public/cs212/libraries/ on the lab computers. You can also add that directory (or any other) to your $CLASSPATH variable by adding the additional line: export CLASSPATH="$CLASSPATH:/home/public/cs212/libraries/*"
Save the file and exit. Then, run the following command: . .bash_profile
Make sure you include the . dot followed by a space before the .bash_profile above. To test that everything is setup, try the following command: cat ~/.bash_profile
You should see somewhere in the output the following lines (there may be other lines as well): export CLASSPATH=".:./*"
export CLASSPATH="$CLASSPATH:/home/public/cs212/libraries/*"
If that looks correct, run the following command as well: echo $CLASSPATH
If it is setup correctly, you will see something similar to the following: .:./*:/home/public/cs212/libraries/*
You should see all of the directories you specified in your $CLASSPATH variable above. (It is okay if there are extra directories in the output.) Compile Make sure you are currently in the directory with your source code files. Remember, Java source code is always stored a *.java file. You first need to compile these files using Java. To do this, run the following command: javac *.java
Now, when you ls your directory, you should notice you also have *.class files. Those are the files necessary to execute your Java code. A common error if you do not have your classpath setup properly will be similar to: error: package org.junit does not exist In this case, javac cannot figure out where the third-party libraries like junit are located. Double-check that your classpath is setup correctly. Execute To run your code, you need to know which class has the main() method. To execute your code, run the following command: java ClassName
Replace ClassName with the classname (no file extension) that contains your main() method. If you have not setup your classpath yet, you need to also provide a -cp "." parameter to tell the java tool to look for your *.class files in the current directory. A common error if you do not have your classpath setup properly will be similar to: Exception in thread "main" java.lang.NoClassDefFoundError:
In this case, javac cannot figure out where the class files are located. Double-check that your classpath is setup correctly and that your code is properly compiled. Arguments If you want to provide command-line arguments to your program, just include those arguments after the class name: java ClassName arg1 arg2 arg3 ...
Replace arg1 arg2 arg3 ... with your command-line arguments (separated by spaces). For example, suppose the class Driver takes a filename as an argument. To execute your code with the argument, run the following command: java Driver hello.txt
If you must specify a file name with a space inside it, use quotes around the filename: java Driver "Hello World.txt"
Jar Files If you have already packaged your *.class files in a *.jar file, you can skip compiling your code with javac . To execute your code, run the following command: java -cp filename.jar ClassName arguments
Replace filename.jar with the name of your jar file (assuming it is in the current directory). For this to work, your *.jar file must contain ALL of the necessary classes for your program to run. JUnit Tests You can run JUnit tests via the command-line on the lab computers. You need to make sure your classpath is setup (see above) first. To run your tests, you can use the following command: java org.junit.runner.JUnitCore ClassName
Replace ClassName with the name of the class with the JUnit tests. For example, suppose the JUnit tests are located in a file named Tester.java . After you have compiled the source code, you can use the following command to run those tests: java org.junit.runner.JUnitCore Tester
You will get some basic text output telling you how many tests you passed or failed. |
| Markdown | null |
| Readable Markdown | null |
| ML Classification | |
| ML Categories | null |
| ML Page Types | null |
| ML Intent Types | null |
| Content Metadata | |
| Language | en |
| Author | null |
| Publish Time | not set |
| Original Publish Time | 2013-08-10 11:44:16 (12 years ago) |
| Republished | No |
| Word Count (Total) | 850 |
| Word Count (Content) | 763 |
| Links | |
| External Links | 7 |
| Internal Links | 13 |
| Technical SEO | |
| Meta Nofollow | No |
| Meta Noarchive | No |
| JS Rendered | No |
| Redirect Target | null |
| Performance | |
| Download Time (ms) | 42 |
| TTFB (ms) | 42 |
| Download Size (bytes) | 3,131 |
| Shard | 144 (laksa) |
| Root Hash | 10754122321078002144 |
| Unparsed URL | edu,usfca!cs,tutoringcenter,/resources/using-java-via-command-line.html h80 |