[Reserved] will. Class files generated executable jar

2010-10-18  来源:本站原创  分类:Java  人气:313 

Operator into the dos window

cd into the package to be labeled jar class file directories all folders

jar cvf [generated jar name. jar] [List class file] / / If there are multiple, separated by space separated

Such as:

One. Operate a single or a few scattered class file

jar cvf ibstool.jar com / cn / ibs / TurnD.class com / cn / ibs / TurnB.class

II. To a folder all of the following class files into jar package

Enter jar cvf ibstool.jar *

Generate executable jar package:

Compiled class file must have main entrance of a class can only produce an executable jar package, such as:

public static void main (String [] args)

Generated method steps:

Method One:

1. Class with the above method to the structure of the directory with the corresponding labeled jar package

2. Unzip the package into the current directory jar

3. Edit META-INF/MANIFEST.MF, the entrance to the jar package main function of the specified program, says:

Manifest-Version: 1.0
Created-By: 1.5.0_06 (Sun Microsystems Inc.)
Main-Class: MutiThread (carriage return)

(Note that carriage return and spaces, and the contents of the file layout must be standard)

4. These files are then compressed into winzip to jar format package, or pressed into a zip package, then change the suffix can also be called the jar.

Method II (recommended):
2. Labeled executable jar package
cmd file class action form, enter the root directory of the root reason why is because of the following can also have a lot of the following package (folder);
In this directory ready for a manifest.mf file, which reads:
Manifest-Version: 1.0
Created-By: 1.5.0_06 (Sun Microsystems Inc.)
Main-Class: MainEntry

main-class of all classes for the specified class name where the main method.
Finally, the command: jar cvfm jarname.jar manifest.mf *

3. Test executable jar package.
With the command: java-jar jarname.jar

4. To make bat file executable jar package.
For example:
@ Echo off
rem
rem Set BQ_IBS_HOME before running this script.
rem

if not "% BQ_IBS_HOME%" == "" goto CONT0
set BQ_IBS_HOME = c: \ ibs
: CONT0

@ Echo on
java-DBQ_IBS_HOME =% BQ_IBS_HOME%-jar jarname.jar

: END

Web reference:

java jar command such as the storage path of your class package for the d: \ com \ demo (demo is a directory, the following class that contains subfolders and files)

To do the following:

1, open dos window into the demo directory

cd d: \ com \ demo

2, the implementation jar cvf demo.jar * Enter

3, in the demo directory you will find demo.jar

See below for explanation of specific parameters:

Usage: jar {ctxu} [vfm0Mi] [jar-file] [manifest-file] [-C directory] filename ...

Options:

-C create new archive

-T List archive contents list

-X expand the archive named (or all files〕

-U update existing archive

-V generate verbose output to standard output

-F specify archive file name

-M mark files containing information from the marked

-0 Store only way; not use the zip compression format

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

-I for the specified jar file index information generated

-C change to the specified directory, and include the following documents:

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

List (manifest〕 file name and archive file name needs to be specified, according to 'm' and 'f' flag is specified in the same order.

Example 1: to archive two class files into a file called 'classes.jar' archive file:

jar cvf classes.jar Foo.class Bar.class

Example 2: Use an existing list (manifest) file 'mymanifest' the foo / directory of all files to an archive called 'classes.jar' archive file:

jar cvfm classes.jar mymanifest-C foo /.

To try a small example:

We have only one HelloWorld, as follows:

public class HelloWorld {
public static void main (String [] args) {
System.out.println ("Hi, Hello World!");
}
}

Java file will be saved to the C drive with the directory, ok, then,

In a previous open command prompt (the prompt to jump to C drive), we enter javac HelloWorld.java, then continue: jar cvf hello.jar HelloWorld.class, enter your C drive after going to see, What is more, yes hello.jar.

The basic steps we all know now, you can go try it with the jar behind the different parameters, the results of any changes.
Then we look at how to run our jar package.

Before entering the topic, you must first open the jar package we just look good, what more, META-INF directory? And then see what it is, there is a MANIFEST.MF file is not it? With a text editor (I am here UltraEdit) to open it to see:

Manifest-Version: 1.0
Created-By: 1.4.2 (Sun Microsystems Inc.)

Is the case. Here we modify it, add one: Main-Class: HelloWorld (in the third line). This is what we wrote before the class, which is our entry point class. That is,

Manifest-Version: 1.0
Created-By: 1.4.2 (Sun Microsystems Inc.)
Main-Class: HelloWorld

Next, we perform at the command prompt, where:

jar umf MANIFEST.MF app.jar (it should be hello.jar)

So we use our own default MANIFEST.MF file of the original has been updated. You may wish to can then see if it is added into the Main-Class: HelloWorld this sentence. (Yeah, how I did not try out, tips java.io.FileNotFoundException: MANIFEST.MF (system can not find the file specified) how is it?)

Ok, this last step, and to verify everything we do at the command prompt, type:

java-jar hello.jar (execution)

What is happening, Hi, Hello World!

Let us look to publish jar files in tomcat, Note: We can no longer tomcat jar in this format, and change the format war, which is dedicated to web applications, in fact, down the whole process is basically similar jar of:

We first prepared the resource pack.

Tomcat's webapps directory to find storage, into one, create a new folder, here named hello, then go in the new WEB-INF folder, and then the new classes into the folder, this time we will our only servlet, HelloWorld. java into here, the same level with the classes directory under the establishment of a file web.xml. Ok, now we have initially created a simple web application.

Written on the MANIFEST.MF.

For example, we packaged the jar for the Test.jar

Manifest-Version: 1.0

Main-Class: windows.VideoWindow

Class-Path: lib \ org.eclipse.swt_3.3.0.v3346.jar lib \ org.eclipse.swt.win32.win32.x86_3.3.0.v3346.jar

The above is packaged as a jar file in the package. The following error has occurred.

could not find main class. Program will exit

The error is in fact not found no main class. But the jar can not execute if an error occurs the error. Package is complete, first run cmd -> java-jar your.jar sure there is no problem to execute the jar. Use -jar argument, the system's Classpath variables no longer work. virtual machine to the MANIFEST.MF Class-Path in the next to find the relevant package.

Before you can successfully from: windows.VideoWindow the main method of access. Or is not connected package will be prompted to find main class. May also be confused and we can not find the North. Obviously you have main class.

If the writing is wrong. Then would have been an error.

See the above Class-Path: behind the wording. Separated by a space. Definitely can not have a semicolon. Remember.

Finally, there must be a new line. This is to be noted. Otherwise, tips are still not mainclass.

Do not let the small things the delay. Which lib / indicates that the jar must be a directory packed Test.jar lib subdirectory.

Need to run the jar command: java-jar Test.jar

Double-click you can, use javaw open.

About java-classpath a.jar; b.jar; class test.Test execution. A.jar; b.jar; behind must have a semicolon. Or error. Do not expect the system classpath do not write your own. This is not the eclipse there. must be written on the class you want to use. Otherwise always prompt you to compile error.

Can be used on are:

1. Main-Class specified in the entry process, which can directly use the java-jar xxx.jar to run the program.

2. Class-Path dependency package specified jar, class loader will be based on the path to search for class.

Generally speaking, I usually use the mf files are to be directly run the jar for this purpose. Although the purpose of that simple, but each time it is easy to package a variety of problems arise headache. mf is not always applied, or wrong.

Firstly a simple and standard example:

Manifest-Version: 1.0
Main-Class: ui.JFrameMain
Class-Path: jtds-1.2.jar c3p0-0.9.1.2.jar
esri_mo20.jar esri_mo20res.jar jsde83_sdk.jar

Explain:

Manifest-Version mf file version number, this line of copy

Main-Class contains the main function of the class, the program's entry

Class-Path to use some of the packages

Analyze points:

Point 1: Every line ":" (colon) is used to separate the key pair. Must be used with a space behind the colon! ! !

That must be written as:

  1. Main-Class space) YouClassName
  2. Class-Path spaces) Class1.Jar

Copy the code will be reported <br /> or JBuilder ("Manifest.mf": Error reading manifest: java.io.IOException: invalid header field
) So wrong. Do not help JAR IDE will find not play its due role MF. By the way, before I saw another report JBuilder is a mistake about what line breaks right, as if the problem is caused because of this. Always thought that the original windows inside the carriage is carriage returns, line 2 characters constitute caused. Now it seems like not so, because the less the space behind the colon.

Point 2: Class-Path content inside separated by spaces, not commas or semicolons. (Well... I always subconsciously with a semicolon)

That is sure to be written:

  1. Class-Path spaces) Class1.jar (space) Class2.jar (space) Class3.Jar

Copy the code points <br /> 3: Some article said MF files can not exceed seventy per line of characters, my experience is that if the MF than JBuilder to edit it anyway, usually I try to finish line. Trouble also continues the very beginning of what a space. I often open the jar directly winRar inside mf then directly edit the file, which is a good way, very straightforward, the disadvantage is that if the error does not change the bad, only some part of the failure of the MF, it seems to run when would say, "wrong file version of MF."

Introduce a few tips:

Tip 1: Use winRar open jar, double-click the MF file, you can edit, and edit the finished Ctrl + S Save. Especially convenient. Can also be written on the outside of a Manifest.mf, and then drag directly overwrite the previous.

Tip 2: Write a run.bat to run your jar. run.bat roughly as follows:

java-jar yours.jar

pause

Back to add a pause to allow you to see what went wrong specifically, in general, if the problem lies in the MF, then what is often the package, which class was not found in the NoClassDef this exception.

相关文章
  • [Reserved] will. Class files generated executable jar 2010-10-18

    Operator into the dos window cd into the package to be labeled jar class file directories all folders jar cvf [generated jar name. jar] [List class file] / / If there are multiple, separated by space separated Such as: One. Operate a single or a few

  • Derived from the Eclipse executable jar package, and finally to generate an executable file exe 2009-05-22

    1. Fat Jar plug-in download 2. After the installation, right-choice item, there will be Build Fat Jar, select this method, one can then step by step in accordance with the Export Wizard executable jar file. If there is outside the jar package, for ex

  • The first attempt to Ant executable jar packaging 2010-06-15

    Today tried to use Ant to package executable jar, request: not to rely on the jar in the other package to the target class in the jar. (Beginners, as learning notes record) Environment: Eclipse3.5.1 (comes with Ant) + Java1.5 1. META-INF/MANIFEST.MF

  • Create an executable JAR 2010-09-02

    Create an executable JAR 1. Package jar cvf manifest ExecutableJar.jar . 2. Modify the MANIFEST.MF file Main-Class: com.mycompany.myapp.Sample Class-Path: . Extension1.jar Extension2.jar Main-Class entry specifies the application class Class-Path cla

  • JSP page, Servlet Java class files generated during the coding problem involved 2010-10-07

    When requesting a JSP page, the general need through the following stages: 1, the application server based on JSP page to generate a Java file 2, the application server will call java.exe Java file is compiled into a Servlet class file corresponding

  • IBM AIX Core files generated methods (transfer) 2010-11-08

    IBM AIX Core files generated in the method environment: (product, platform, model, software version, etc.) Platform: RS Software Version: AIX4.3 or later description of the problem: If you need an application process to produce a complete core file f

  • JAR packaged, fatjar package, fatjar packaged third-party jar to jar, the 3rd party, executable jar 2011-05-11

    Fatjar installed right after the project -> Export ..-> select other, all the way to the default This lay the jar package, can be used as a control on other projects referenced, use, is the executable jar Fatjar installed right after the project -&g

  • JAR package, fatjar package, fatjar packaged third-party jar to jar, the third party, executable jar 2011-05-11

    Fatjar installed right after the project -> Export ..-> choose other, all the way to the default This lay the jar package, can be used as a control on other projects referenced, use the executable jar Fatjar installed right after the project -> E

  • Eclipse executable JAR package to fight 2011-01-11

    Download RUL: http://fjep.sourceforge.net/ Download fatJar plug-in, unzip a ... / plugins / (net. ..) the following plugins (net..) Files copied to the eclipse's plugins folder, restart Eclipse3.1, Windows => prefernce = > fat jar preference to see

  • Hibernate Mapping files generated by myeclipse No entries available when a solution 2011-04-29

    Original link: http://gundumw100.iteye.com/blog/436692 In hibernate, each corresponding data table is an entity class, each class has a corresponding entity profile and you hbm.xml match, myeclipse There is a MyEclipse Database Explorer view, it prov

  • When running an executable Jar, Classpath settings invalidity, java the-cp and-jar argument can not be 2010-07-12

    The situation is: in the cmd, run java-jar *. jar, there classnotfound exception, jar jar contains the following class lib can not find the following, and later added in the MANIFEST.MF Class-Path configuration, but still not work? One of the compone

  • Trace files generated word list, position the cursor to mark where the page 2010-10-18

    The company had to develop several projects, all related to the document on-line editing, a good implementation of this feature is currently found on the Internet can be a lot of online editorial office and middleware controls the files, regardless o

  • Using Task Scheduler comes with windows automatic backup function of the files generated by the project 2010-11-29

    First, write yourself a batch command, which is a bat file which will be generated by the project's files to a folder. Step one: first create a new txt file, and then write to the txt file the following content. @echo off xcopy h:\txt\* h:\backup\tem

  • Double-click the executable jar file package 2011-06-01

    jar is a file format that is common in Java archive command. jar file for distribution and use of libraries, applications and extensions as building blocks, as a component, applet or plug-in unit of deployment, packaging and components for auxiliary

  • Html static files generated using the FreeMarker 2010-03-29

    import java.io.*; import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import freemarker.template.*; /* * Created on 2005-4-7 * */ /** * Test FreeMarker. * * @author scud

  • tomcat log files generated 2010-08-30

    By copying the following log4j.properties in the content, you can generate log files to the specified directory: # Define DEBUG priority, R for the purpose of the log output # Log4j.rootLogger = debug, P # Set the log output type, for the file type #

  • With FatJar the SWT / JFace works package labeled Executable Jar 2010-12-21

    Swt wrote with a small project, and finally labeled jar package, with the eclipse export jar package function, derived after the report "could not find the main class!" Error. Spent an evening, a lot of information in the online search or not ev

  • perform background tasks ajax download csv files generated 2011-04-13

    Click of a button, generate a csv file, the generation process is very time-consuming csvs to put the background, generated after the expiry, but also to send the file to the client, this time using ajax request, to determine whether the file success

  • Words under a single fat32 and ntfs folder can limit the number of files generated 2011-03-11

    Yesterday, a problem encountered in the project, which is when a static site problem, the system reported a File not found, the upper error Is , file or directory can't not create , I wonder, has been repeatedly tested twice and the problem is not su

  • php cache files generated 2010-04-22

    Code: <?php /* Instance : include("cache.php"); $cache = new cache(30); $cache->cacheCheck(); echo date("Y-m-d H:i:s"); $cache->caching(); */ class cache { // The cache directory var $cacheRoot = "./cache/"; // Cache