Javac compile single file, multi-file Introduction jar package,-CP solve the problem of unable to load main class

Source: Internet
Author: User

Introduction : Many people with IDE integrated development environment with more, the DOS command to compile multiple Java files or introduce jar package has become unfamiliar, Java is different from other interpretation languages, such as Ruby, PHP have require, directly introduced to run code, But Java needs to be compiled into bytecode, so you need to add some parameters to cmd when you run it.

1. Introduction of external jar package compilation run

Test the directory structure

Test

    • --Src/a.java
    • --Lib/pinyin4j-2.5.0.jar

The A.java code is as follows:

1 ImportNet.sourceforge.pinyin4j.PinyinHelper;2 ImportNet.sourceforge.pinyin4j.format.HanyuPinyinCaseType;3 ImportNet.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;4 ImportNet.sourceforge.pinyin4j.format.HanyuPinyinToneType;5 ImportNet.sourceforge.pinyin4j.format.HanyuPinyinVCharType;6 Importnet.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;7 8  Public classA {9 Ten      Public Static voidMain (string[] args)throwsException { One         /** A * The Tohanyupinyinstringarray method receives a character type char, which returns an array of strings string[] -          */ -          for(inti=0; I<args[0].length (); i++) { the  -string[] Pinyinarray = Pinyinhelper.tohanyupinyinstringarray (args[0].charat (i)); -  -              for(intj=0; j<pinyinarray.length; J + +) { +  - System.out.println (Pinyinarray[j]); +             } at         } -     } -}

Start compiling

Run successfully

    1. JAVAC-CP indicates the location of the import class in the. java file.
    2. JAVA-CP indicates the package path of all classes required to execute the class file-the path of the system ClassLoader (involving the class loading mechanism)

Note: Paths are used in Linux: separate from windows, and for. class files, you only need to specify the path to the package, but for a jar file, you must format the full path, path + file name, and you cannot specify only one path

pinyin4j-2.5.0 Download

Https://files.cnblogs.com/files/bc8web/pinyin4j-2.5.0%E8%A7%A3%E5%8E%8B%E4%BD%BF%E7%94%A8.rar

2. Compiling multiple Files

Compile all. java files at once

    • Compile all. java files at once

    • Compiling the specified number of Java files

Attached JAVAC usage

Usage: Javac < options > < source files >

among the possible options are:
- g generates all debug information
-g:none does not generate any debug information
-g:{lines,vars,source} only generates some debugging information
-nowarn does not generate any warnings
-verbose output messages about the actions that the compiler is performing
-deprecation output using outdated API source location
-classpath < paths > specifying where to find user class files
-CP < paths > specifying where to find user class files
-sourcepath < paths > Specify where to find the input source files
-bootclasspath < path > Overwrite the location of the boot class file
-extdirs < directory > location of the extended directory to overwrite installation
-endorseddirs < directory > location of standard paths for overwriting signatures
-D < directory > Specify the location where the generated class files are stored
-encoding < encoding > specifying the character encoding used by the source file
-source < version > provides source compatibility with the specified version
-target < version > Generate a class file for a specific VM version
-version Version Information
Summary of-HELP output standard options
-X output a feed of non-standard options
-j< flag > Direct < flag > pass to runtime system

Javac compile single file, multi-file Introduction jar package,-CP solve the problem of unable to load main class

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.