My Java Development learning journey------> compiling and running Java internal classes in a DOS environment

Source: Internet
Author: User

Used to write code on the IDE tools, even the most basic javac commands and Java commands are almost forgotten, today, a Java internal class compiled and run, it is embarrassing. The IDE is a double-edged sword, it can do anything to help you, you just hit a few lines of code, a few mouse clicks, the program ran up, it is quite convenient to use. You don't have to worry about what's behind it, what commands are executed, and what the principles are based. However, this excessive reliance often loses the most basic skills, and when it comes to a place where there is no IDE, you don't know what to do, and you don't have a code to run.

  


First I wrote a Innerclasstest.java code on the C drive, the code reads:

Package Com.csdn.oyp.inner;public class Innerclasstest {static class One{private static class Two{public static void Main ( String[] ("args") {System.out.println ("")}}}}

Then I compile with the command in the DOS window

C:\USERS\ADMINISTRATOR>CD C:c:\>javac Innerclasstest.javac:\>java innerclasstest$one$twoexception in Thread "main" java.lang.noclassdeffounderror:innerclasstest$one$two (wrong name:com/csdn/oyp/inner/innerclasstest$ One$two) at Java.lang.ClassLoader.defineClass1 (Native Method) at Java.lang.ClassLoader.defineClass (classload er.java:621) at Java.security.SecureClassLoader.defineClass (secureclassloader.java:124) at Java.net.URLClass  Loader.defineclass (urlclassloader.java:260) at java.net.urlclassloader.access$000 (URLClassLoader.java:56) at Java.net.urlclassloader$1.run (urlclassloader.java:195) at java.security.AccessController.doPrivileged (Native Meth OD) at Java.net.URLClassLoader.findClass (urlclassloader.java:188) at Java.lang.ClassLoader.loadClass (Classlo ader.java:307) at Sun.misc.launcher$appclassloader.loadclass (launcher.java:301) at Java.lang.ClassLoader.loa DClass (classloader.java:252) at Java. lang.  Classloader.loadclassinternal (classloader.java:320) Could not find the main class:innerclasstest$one$two. Program would exit.


After running the Javac Innerclasstest.java command, the following three class files are generated on the C drive, respectively:Innerclasstest$one$two.class

Innerclasstest$one.class

Innerclasstest.class


However, when running the Java innerclasstest$one$two command, an exception was reported: Exception in thread "main" java.lang.noclassdeffounderror:innerclasstest$ One$two (wrong Name:com/csdn/oyp/inner/innerclasstest$one$two).

it turned out to be my There are package statements in Innerclasstest.java: Package Com.csdn.oyp.inner; so when compiling the Javac command to add the-D option.

Change the Javac command to c:\>javac-d. Innerclasstest.java (note ".") No.


javac-d destdir srcfile Command explanation

Where: 1,-D destdir is used to specify the path to the. class file where the compilation was generated. (If this option is omitted, the. class file is generated by default in the current directory, and no package folder is generated; The current directory can be used "." To express, namely: javac-d. Srcfile)

Note: To add the-D option, in addition to specifying the path to the. class file that is compiled, the biggest difference is that you can generate a folder under the current path for the package name under the Packages keyword on the first line of the source file.


Then generate a C:\com\csdn\oyp\inner directory under the current directory (C-drive) to hold the compiled class file. As shown in the following:


Then use the Java command to run the main method.

Java com.csdn.oyp.inner.innerclasstest$one$two

The result of the operation is: output.


Of course, if the package statement in the Innerclasstest.java is deleted, it is not packaged.

public class Innerclasstest {static class One{private static class Two{public static void Main (string[] args) {System.out. println ("both");}}}
Compile and run the code as:

C:\>javac Innerclasstest.javac:\>java Innerclasstest$one$twotwo
As shown in the following:


=================================================================

C:\>javac-help usage: Javac < options > < source files > Where possible options include:-G generates all debug information-g:none Does not generate any debug information-g:{lines,vars,source} only generates some debug information-nowarn does not generate any warning-verbose output about compiling The-deprecation output uses the outdated API's source location-classpath < path > specifies where to find user class files and comment handlers-cp < road        Path > specifies where to find user class files and comment handlers-sourcepath < paths > Specify where to find input source files-bootclasspath < paths > Overwrite the location of the boot class file-extdirs < directory > Overwrite the location of the installed extension directory-endorseddirs < directory > Overwrite the location of the signed standard path-proc:{none,o  NLY} controls whether annotation processing and/or compilation is performed. -processor <class1>[,<class2>,<class3&gt ...] The name of the comment handler to run, bypassing the default search process-processorpath < path > specifying where to find the comment handler-d < directory > Specify the location where the generated class file is stored-             S < directory > specifies the location of the generated source files-implicit:{none,class} Specifies whether to generate class files for implicit reference files-encoding < encoding > Specifies the character encoding used by the source file-source < version > provided with the referenceFixed version of source Compatibility-target < version > generate class file for a specific VM version-version version information-help output label The feed of the quasi-option-akey[=value] The option to pass to the comment handler-X output non-standard options for the Feed-j< flag > Straight Connect < flag > pass to the runtime system


C:\>java-helpusage:java [-options] class [args ...]           (to execute a class) or Java [-options]-jar jarfile [args ...] (To execute a JAR file) where options include:-client to select the ' client ' vm-server to select the ' s    Erver "Vm-hotspot are a synonym for the" client "VMS [deprecated] The default VM is client. -CP <class Search Path of directories and Zip/jar files>-classpath <class Search Path of directories and zip/ Jar Files> A;    Separated list of directories, JAR archives, and ZIP archives to search for class files. -d<name>=<value> set a system Property-verbose[:class|gc|jni] enable Ver Bose output-version Print product version and exit-version:<value> require the Specifi Ed version to run-showversion print product version and Continue-jre-restrict-search | -jre-no-reStrict-search include/exclude User Private JREs in the version search-? -help Print this Help message-x print help on non-standard options-ea[:<packagename>...|:&lt Classname>]-enableassertions[:<packagename>...|:<classname>] Enable Assertions-da                  [: <packagename>...|:<classname>]-disableassertions[:<packagename>...|:<classname>] Disable Assertions-esa | -enablesystemassertions Enable System ASSERTIONS-DSA |                  -disablesystemassertions disable system assertions-agentlib:<libname>[=<options>]  Load native Agent library <libname>, e.g.-agentlib:hprof See also,-agentlib:jdwp=help And-agentlib:hprof=help-agentpath:<pathname>[=<options>] Load native Agent library by F    Ull Pathname-javaagent:<jarpath>[=<options>]              Load Java programming language agent, see java.lang.instrument-splash:<imagepath> Show splash screen with specified image


You can refer to the following links:

Http://www.cnblogs.com/xiazdong/p/3216220.html?utm_source=tuicool

==================================================================================================

Ouyangpeng welcome reprint, sharing with people is the source of progress!

Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng

==================================================================================================



My Java Development learning journey------> compiling and running Java internal classes in a DOS environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.