Java Compile Package command

Source: Internet
Author: User

    • Background
    • Compile
    • Packaged
    • Extract
    • Run
    • Reference
Background

Sometimes we have to compile our own projects into class files and package them into jars, although there are various tools to help us, but after all, it is more flexible to use Java's original commands to do this.

Compile

For example, I want to compile the package named Com.demo, all called the Com.demo.Main class, while the resulting file is specified in the current directory under the Bin folder, then do it?

Main.java content:

1  Package Com.demo; 2  Public class main{34publicstaticvoid  Main (string[] Argvs) {  5 System.out.println ("-------****hello world!***-------"); 6 }78 }

Since the compiled class has a package name, you must create the folder under the working directory for the package name, place the source in the corresponding folder, and if you do not, you will not find this class, then execute the javac command

1 mkdir bin #创建输出目录 2
Packaged

Package all resources under the Bin folder to the jar package

1 Touch bin/2 jar-cvfm main.jar mymanifest-c bin. #这里 mymanifest corresponds to M option, merging Mymanifset into jar In the meta-inf/manifest. MF, that is, with the new inventory configuration file,-C later specify the directory to be packaged (compile time is not so convenient) note after the directory. Represents all Files 3 #最终会在当前工作目录下生成一个 Main.jar package file, including bin All files under the

Update jar Package Contents

1 mkdir Res 2 Touch res/map.property3 jar-uvf main.jar res/map.property #此时如果解压 jar package, you will find the Res directory generated, At the same time the directory has map.property file, of course, before the stock has so this file will be updated 4 #jar-UVFM Main.jar manifest If you want to follow the new manifest file with the M option
Extract
JAR-XVF Main.jar #会在当前目录下解压 Main.jar Package, note that the decompression path cannot be specified
Run
1 java-jar main.jar #java-2-------****hello world!***-------

Reference
1 Javac2 3Usage: Javac <options> <source files>4 among the possible options are:5-g generate all debug information6-G:none does not generate any debug information7-G:{lines,vars,source} only generates some debugging information8-NoWarn does not generate any warnings9-verbose output messages about the actions that the compiler is performingTen-deprecation output using outdated API source location One-classpath < paths >specify where to find user class files and comment handlers A-CP< paths >specify where to find user class files and comment handlers --sourcepath < paths >specify where to find the input source files --bootclasspath < paths >overwrite the location of the boot class file the-extdirs < catalogue >overwrite the location of the installed extension --endorseddirs < catalogue >the location of the standard path that overrides the signature --proc:{none,only} Controls whether annotation processing is performed and/or compiled.  --processor <class1>[,<class2>,<class3>...] The name of the comment handler to run; Bypassing the default search process +-processorpath < paths >specifies where to find the comment handler --parameters generating metadata for reflection of method parameters +-D < directories >specify where to place the generated class file A-S < catalogue >specify where to place the generated source files at-H < catalogue >specify where to place the generated native header file --Implicit:{none,class} Specifies whether to generate a class file for an implicit reference file --encoding < coding >Specify the character encoding used by the source file --source < release >provides source compatibility with a specified release version --target < release >to generate a class file for a specific VM version --profile < configuration files >Make sure that the API you use is available in the specified configuration file in-Version Information --Summary of the Help output standard options to-a keyword [=value] The option to pass to the comment handler +-Summary of X-output non-standard options --j< tags > Direct < tags >passing to the runtime system the-werror terminating compilation When a warning occurs *@< file name > read from File option and file name
Javac
1 Jar2 3Usage: jar {CTXUI}[VFMN0PME] [jar-file] [manifest-file] [Entry-point] [-Cdir] Files ...4 Options:5-C Create a new profile6-t lists the archive directory7-x Extract the specified (or all) files from the file8-u Update existing archive9-v generate verbose output in standard outputTen-f Specify file file name One-m contains inventory information from the specified manifest file A-N Perform Pack200 normalization after creating a new file --E is a standalone application bundled into an executable jar file - Specify the application entry point the-0store only; do not use any ZIP compression --P retains leading in file name'/'(absolute path) and".."(parent directory) component --M do not create a manifest file for the entry --I generate index information for the specified jar file +-C change to the specified directory and include the following files - If any file is a directory, it is recursively processed.  + manifest file name, file file name, and entry point name in the specified order AAnd'm','F'And'e'tags are specified in the same order.  at  -Example1: Archive Two class files to a file named Classes.jar: - jar CVF Classes.jar foo.class bar.class -Example2: Using an existing manifest file'mymanifest'and -Archive all files in the foo/directory to'Classes.jar'Medium: -Jar CVFM Classes.jar mymanifest-c foo/.
Jar
1 Java2 3Usage: Java [-options] class [args ...]4 (Execution Class)5or Java [-options]-jar Jarfile [args ...]6 (execute jar file)7 among the options are:8-D32 use +bit data Model (if available)9-d64 use -bit data Model (if available)Ten-server selection"Server"VMS One The default VM is server, A because you are running on a server class computer.  -  -  the-CP< catalogue andZipClass search path for/jar files > --classpath < catalogue andZipClass search path for/jar files > - by: Delimited directory, JAR file - and a list of ZIP archives to search for class files.  +-d< name >=< value > - Setting System Properties +-verbose:[class|gc|JNI] A Enable verbose output at-Version output product versions and exit --version:< value > - Warning: This feature is obsolete and will be - removed in future releases.  - The specified version is required to run --showversion Output product version and Continue in-jre-restrict-search | -no-jre-restrict-Search - Warning: This feature is obsolete and will be to removed in future releases.  +Include in version search/exclude user-specific JRE --? -Help output this helper message the-Help for X-output non-standard options *-ea[:<packagename>...|:<classname>] $-enableassertions[:<packagename>...|:<classname>]Panax Notoginseng enable assertion at the specified granularity --da[:<packagename>...|:<classname>] the-disableassertions[:<packagename>...|:<classname>] + disables assertions with the specified granularity A-esa | -enablesystemassertions the Enable System Assertion +-DSA | -disablesystemassertions - Disabling system assertions $-agentlib:<libname>[=< Options >] $Load native Agent library <libname>, for example-agentlib:hprof -See also-agentlib:jdwp=help and-agentlib:hprof= Help --agentpath:<pathname>[=< Options >] the load the native agent library by full path name --javaagent:<jarpath>[=< Options >]Wuyi load the Java programming language proxy, see Java.lang.instrument the-splash:<imagepath> - Displays the splash screen using the specified image WuFor more information, see http://www.oracle.com/technetwork/java/javase/documentation/index.html. 
Java

Java Compile Package command

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.