- Command-line compilation of Java classes with packages
Compiling this piece at the command line is basically about getting started, and then going straight to the IDE. This is true, afraid of those ... Then today in the video to see this method, think it may be used, so it is recorded, for self-examination.
The steps are as follows:
Create a new Java file in X disk and write a piece of code with the package in it, as shown in the following example:
Package Com.hsp;public class exercise{public static void Main (string[] args) {System.out.println ("Hello world! "); }}
I am here D-disk, file for Exercise.java, and then save (because the EditPlus tool is used, so there will be a backup file):
When compiling the file on the command line, you need to add-D after javac to compile, as an example:
As you can see from the example, the compilation was successful without an error. If you follow the steps to compile a sample error stating that there is an error in the Java environment configuration, please check.
Then look at the X-disk (I'm here for the D-drive) related files and you can see that the compilation generated the COM folder
Click to go to see the HSP folder, and then open to see the Exercise.class file.
Then run Java com.hsp.Exercise, note that not Java Exercise, you can see the following, indicating that the operation was successful. If you follow the steps to run the sample failure, there may be an error in the Java environment configuration, please check.
Hanshunping the servlet video series Unexpected Harvest Command-line compilation Java class solution with package