the Java class file is born into an executable Java Application. There are three Java applications: a jar that executes entirely natively (such as a native GUI executable), is executed remotely on the server (for example, a browser), and in a combination of the two (for example, the client interacts locally with the remote Server)
to generate a jar from a class file
Specify the storage directory for the Compile-time class filehitting the jar (javaarchivefile) package requires only the compiled class class file and does not require the source Code. Java Files. You can specify the class directory for the output of the compilation result via-dfor Example: Java-d. /classes Myapp.javacan also be compiled by *.java matching all Java files
to create an executable jarthe jar package does not need to be extracted from the file to be used, and the program can be saved in the jar for Execution. The main jar file needs to contain a mainfest file with the jar information, and the file needs to specify which class and the main () method. The jar file does not contain source code, It is a class file 1. All class files need to be placed in the same directory and create the Mainfest.txt file in this directory2.manifest.txt needs to specify the class that contains main () in the following line:Main-class:myappMyApp is the class that contains main (), do not write the Following. class (the line will need to be wrapped after the Content)3. Execute the JAR tool to create a jar file with all classes and MainifestEnter the directory where class is locatedJAR-CVMF manifest.txt Outputname.jar *.class or JAR-CVMF manifest.txt outputname.jar myapp.classmanifest.txt Specify main () entryOutputname.jar Specifies the name of the generated jar*.class specifying the class file to be packaged
Execute Jarfirst make sure that the jar file is under classpath, otherwise the Java Virtual Machine cannot find the jar. execution mode: Java-jar Xxx.jar
Manage class files with packages and generate jarsthe package can prevent class name collisions, the name of the class in the complete package is "package Name. class name", in the class, the. Java file is compiled into a class file, and the jar executes with the full name of the package name
1. Put the class into the packagethe name of the package is generally used to reverse the domain name, and then add other names, such as Com.wuba.zhuanzhuan.xxxxPackage The following class, the first line needs to be added to the package directive "packages com.wuba.zhuanzhuan.xxx;"the class needs to be placed under the directory structure corresponding to the package name, each of which is represented by the first level directory, the above package name example, the class file needs to be placed in the Com->wuba->zhuanzhuan>xxx folder
2. Compiling the packageby using-d to compile, a compiled directory is created according to the directory of the package files, and the compiled class file is placed in the corresponding level directoryfor Example:the directory where the CD package is located (note that the directory where The. Java files are located)Javac-d. /classes Com/wuba/zuanzhuan/xxx/*.java(if the path to the class compilation output is not yet created,-d will create the directory based on the source Code's Directory)
3. Execute the packagethe full name of the package must be specified for execution, and the Java Virtual machine can find the class file under the packageJava com.wuba.zhuanzhuan.xxx.MyApp
4. Creating an executable jar in a packagepackage packages into jars, package directories must be in jars, first-level directories of packages must be first-level directories of Jars4.1 First need to make sure that all the class files are in the correct package directory4.2 Create Mainfest.txt describes which class with main (), be sure to use the full class name that contains the registrationMain-class:com.wuba.zhuanzhuan.xxx.myappthen put the manifest.txt in the directory where the package is located (classes)4.3 execute jar tool to create jar containing directory structure and MainfestJAR-CVMF manifest.txt myapp.jar comas long as you specify the top-level directory of the package, the remaining
operation of the Jar
Generate JarEnter the file of class, if it is a package, you need to go to the directory where the packageCreate a Manifest.txt file to specify the main function entry JAR-CVMF manifest.txt Outputname.jar *.class
Execute Jarfirst make sure that the jar file is under classpath, otherwise the Java Virtual Machine cannot find the jar. execution mode: Java-jar Xxx.jar
the composition of the jar fileView jar file contents "JAR-TF xxx.jar" (tf is table File)the class file directory is the same as the directory at the time of packaging, and there is a meta-inf->manifest in the root directory. MF File. This file is generated automatically by the jar tool, and the jar does not hold the Manifest.txt file of the main entry, but instead puts its contents in the MANIFEST.MF file
Unpack the jar packageUnzip the jar package "JAR-XF xxx.jar" (xf is extract File)
Java Web StartJava Web Start (JWS) deployment allows users to download applications from the browser, launch locally, and detect updates
how Java Web start Works the first step: the user clicks on the browser's. jnlp file download link Step two: The Web server sends The. JNLP file to the client browser Step three: The client browser launches the Java Web Start,jws Helper app to read The. JNLP file and then requests the jar from the WEB server through the contents of The. JNLP fourth step: The Web server sends A. JAR file Fifth step: JWs gets the. jar file and invokes the specified main () to start the applicationthe user can then launch the application via JWS offline
steps to create and deploy a Java Web startfirst step: make the application executable jarrefer to the previous content Step two: Write the. jnlp fileThis file specifies the version of the current jar, The. jar, and the main () entry of the jar.format:<?xml version= "1.0" encoding= "UTF-8"?><jnlp spec= "1.0+" codebase= " Specify the relevant file start directory " href= " relative codebase path " ><information><title>dynamic Tree demo</title>
<vendor>dynamic team</vendor>
<icon href= "sometree-icon.jpg"/>
<offline-allowed/>
</information>
<resources><!--application Resources --<j2se version= "1.3+" ><jar href= " executable jar name (xx.jar)" main= "true"/></resources><application-desc main-class= " and mintiest, specify which class has main ()"/></jnlp> JNLP is an XML file,<information> information is used by the helper app to display information about Java applicationsJ2SE version Specifies the minimum edition required for java, and automatically installs Java if not installed the detailed JNLP file format can refer to the following links:HTTP://DOCS.ORACLE.COM/JAVASE/TUTORIAL/DEPLOYMENT/DEPLOYMENTINDEPTH/JNLPFILESYNTAX.HTML#JNLP Step three: Place The. JNLP and jar files on the Web server Fourth Step: set a new MIME type for the Web serverApplication/x-java-jnlp-file Fifth step: set the page link to the. jnlp fileThis step is for downloading The. jnlp file from the Browser.
Java Foundation ten [package, jar archive file and deployment] (read head first Java record)