How the Java package updates the class in the package, or repackage

Source: Internet
Author: User

Here we mainly introduce the method of executing in the form of the basic command:

The main use is only, Javac, Jar, Java (*.exe) command,

A. Javac[java source file compiled into class]

1. Common directives: JAVAC-CP Specify multiple Classpath

Javac-classpath can specify a classpath to compile Java files

Such as:
Javac-classpath **\servlet-api.jar **.java To compile a Java file

Need to specify multiple paths? is with a semicolon; separated
Such as:
JAVAC-CP classes; C:\Tomcat\lib\servlet-api.jar -encoding UTF-8 Beerselect.java

(Directly inside the cmd) This is compiled with the classes class file and the Servlet-api.jar.

Beerselect.java

PS: Here to remember the focus, when running the main program is possible to use. The jar packages need to be classpath specified,

Internal compilation reference will not error, if the project is small, the package is not many, not too much emphasis on the compilation of aging, you can suggest the project

The package is placed in a class library file. The jar Baoqian under this folder is also compiled into the package.

Another,-encoding UTF-8 is if the file to be compiled is not all English, that is, "there are Chinese characters, you can set the code, save the

Compile an error.

2. Other instructions or parameters can be entered in cmd "Javac" (plus enter key) or "javac-help"

(plus enter key) See comments:

Usage: Javac < options > < source files >

Among them, possible options include: -g                          generate all debug information  -g:none                     does not generate any debug information  -g:{lines, vars,source}     only generates certain debug information  -nowarn                     do not generate any warnings  -verbose                    output messages about the actions that the compiler is performing  -deprecation               output using obsolete API Source Locations  -classpath < paths >            Specifies where to find user class files  -CP < paths >                    specifies where to find user class files  -sourcepath < paths >           Specifies the location of the lookup input source file  -bootclasspath < path >        Overwrite the location of the boot class file  -extdirs < catalog >              location of the extended directory where the installation is covered  - Endorseddirs < directory >         location of standard paths for overwriting signatures  -D < directories >                     Specifies the location of the generated class file  -encoding < encoding >             Specify the character encoding used by the source file  -source < version >                provide source compatibility with the specified version  -target < version >                generate class files for a specific VM version  -version                    Version Information  -help         Summary of the               output standard options  -x                           output non-standard options for feeds  -j< flags >                      directly pass < flag > to the runtime

two. Jar[*.jar the operation of the package referenced in Java]

1. Common directives: Jar CF updates the specified file or repack in the specified package

e.g.:%java_home%\bin\jar CF Lib\a.jar Sample\b.class (this format is mostly written in *.bat etc.

Batch file to execute, same as below)

While using the jar command to directly modify the files in the package (usually the class file), it is important to understand the structure of the original package and then hands-on.

And remember a principle, the relationship between the reference and the actual structure of the package is "." = = "\" (The actual folder will be found after decompression)

2. Other instructions or parameters can enter "Jar" (plus enter key) or "jar-help"(plus enter key) in cmd

See comments:

Usage: jar {ctxu}[vfm0mi] [jar-file] [manifest-file] [-C directory] File name ...

Options:

-C Create a new archive

-t lists the list of archived content

-X expands the named (or all) file in the archive

-U updates an existing archive

-V generates verbose output on standard output

-f Specifies the archive file name

-M contains marked information from the indicated file

-0 storage mode; Zip compression format not used

-M does not produce a list of all items (manifest) file

-I generates index information for the specified jar file

-C changes to the specified directory and contains the following files:

If a file name is a directory, it will be processed recursively.

The manifest (both the Manifest) file name and the archive file name need to be specified, in the same order specified by the ' m ' and ' F ' flags.

First write a manifest file in the current directory of the resource file EXAMPLE.MF

A simple example can be see: http://blog.csdn.net/studyvcmfc/article/details/7745500

Three. java[class file actual operation]

This should be more familiar, is to execute the Java class file (the last step) '

Such as

JAVA-CP.; C:\dir1\lib.jar Test
-CP, like-classpath, are paths that specify other classes on which classes run, typically class libraries, jar packages, and so on, that require

Full path to jar package, window on semicolon ";"

> e.g: @ "%java_home%\bin\java"-CP Lib\a.jar; ... sample. B "%~1"

In the same vein, Java or java-help can be used to view:

Options command line option (the Internet did not find the Chinese, I now use is not Chinese, do make a first look at it, with the Chinese system, their own to lay the test, very simple) Usage: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 "Server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is the 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 verbose output
-version Print product version and exit
-version:<value>
Require the specified 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>...|:<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 full pathname
-javaagent:<jarpath>[=<options>]
Load Java programming language agent, see Java.lang.instrument

In short, step order (the first step) do not make a mistake, you can forget the parameters to go to the degree of Niang check.

Example ' (Code in BAT)

Bat1.bat Source

----------------------------------------------------------

REM @echo off

RemRecompile the B.java intoB.class
%JAVA_HOME%\BIN\JAVAC-CP Lib\a.jar,-encoding UTF-8 Sample\b.java

RemUpdateIn S.jarB.class
%java_home%\bin\jar CF Lib\s.jar Sample\b.class

REM Set internal environment variables (This step depends on source condition, some do not need)
Set Func_lang=zh
Set INNER_home=...
path=%INNER_home %\bin;%path%

REM actually tune the additional. bat file to run the. java file
BAT2. bat Samplefile\test.tif>c:\test\result.txt

Bat2.bat Source

----------------------------------------------------------

@ "%java_home%\bin\java"-cp lib\a.jar, ...-dxx=%ss% Sample. B "%~1"

S.jar (.. lib\s.jar), update

S.jar Tree:

S.jar
|_____sample
| |______b.class
|_____meta-inf

|______manifest. Mf

So still that sentence, to change the package, in advance must be familiar with the structure of this package, backup one, and then change.

※: Finally, a key point that can easily be ignored, in the 1th step of compilation, the entity source is stored, if

Do not want to change a lot of source, compile at a time, and in the 2nd step directly update the corresponding package corresponding to the relationship directory

Class words. Your own rewrite of the. java file save location, be sure to create a and will change the package relative

The same path as the location relationship, otherwise an error occurs. Here: If you rewrite the B.java file, you will need to

source directory, create a sample folder and rewrite your b.java file to put it in.

This generally can also be Span style= "color: #000000;" >B.java The first line of the package sample;  in this code.

How the Java package updates the class in the package, or repack

Related Article

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.