Current location - Quotes Website - Signature design - Can java be run by double-clicking it after packaging?
Can java be run by double-clicking it after packaging?

Nowadays, windows will be equipped with j2se parser, so this means that if it is packaged into a jar file, it can be opened with this j2se parser and can be double-clicked to run. **********************The following is the packaging method of the jar package************************ ***1. Create MANIFEST.MF (in the root directory of the class file) The following content is the basic content of the file ================== Manifest-Version: 1.0 Main-Class : a (path to the main class) Created-By: Abc Company (name of the creator) ================== 2. Package in the class file directory according to the conditions given by lz Execute jar cvfm classes.jar MANIFEST.MF *.* The above command will package all the files under the class into classes.jar and generate it in the class directory. 3. Double-click to execute under Windows. ----------------------------------This is the solution I recommend because it is simple. ****************************MANIFEST.MF file details********************** *******When opening a Java JAR file, we can often see that the file contains a META-INF directory. There will be some files in this directory, among which there must be a MANIFEST.MF. This file describes the Jar file. A lot of information, the contents of the MANIFEST.MF file will be introduced in detail below. Let’s first look at the contents of the MANIFEST.MF file contained in struts.jar: Manifest-Version: 1.0Created-By: Apache Ant 1.5.1Extension-Name: Struts FrameworkSpecification- Title: Struts FrameworkSpecification-Vendor: Apache Software FoundationSpecification-Version: 1.1Implementation-Title: Struts FrameworkImplementation-Vendor: Apache Software FoundationImplementation-Vendor-Id: org.apacheImplementation-Version: 1.1Class-Path: commons-beanutils.jar commons-collections .jar commons-digester.jar commons-logging.jar commons-validator.jar jakarta-oro.jar struts-legacy.jar If we classify the configuration information in MANIFEST, we can summarize it into the following categories: 1. General Attribute 1. Manifest-Version is used to define the version of the manifest file, for example: Manifest-Version: 1.02. Created-By declares the generator of the file. Generally, this attribute is generated by the jar command line tool, for example: Created-By: Apache Ant 1.5.13. Signature-Version defines the signature version of the jar file 4. Class-Path The application or class loader uses this value to build the internal class search path 2. Application related properties 1. Main-Class defines the jar file The entry class must be an executable class. Once this attribute is defined, the jar file can be run through java -jar x.jar.

3. Applet related attributes 1. Extension-List This attribute specifies the list of extension information required by the applet. Each name in the list corresponds to the following attributes 2. -Extension-Name3. - Specification-Version4. -Implementation-Version5. -Implementation-Vendor-Id5. -Implementation-URL 4. Extension identification attribute 1. Extension-Name This attribute defines the identification of the jar file, such as Extension -Name: Struts Framework 5. Package extension attributes 1. Implementation-Title defines the title of the extension implementation 2. Implementation-Version defines the version of the extension implementation 3. Implementation-Vendor defines the organization of the extension implementation 4. Implementation-Vendor-Id defines the extension Identity of the implementing organization 5. Implementation-URL: Defines the download address (URL) of the extension package 6. Specification-Title Defines the title of the extension specification 7. Specification-Version Defines the version of the extension specification 8. Specification-Vendor declares the maintenance of the extension package Standard organization 9. Sealed defines whether the jar file is sealed, the value can be true or false (I still don’t understand this very well) 6. Signature-related attributes For signature attributes, we can refer to a section in mail.jar provided by JavaMail Name: javax/mail/Address.classDigest-Algorithms: SHA MD5 SHA-Digest: AjR7RqnN//cdYGouxbd06mSVfI4=MD5-Digest: ZnTIQ2aQAtSNIOWXI1pQpw==This content defines the class name of the class signature, the algorithm name for calculating the digest, and the corresponding digest content (Use BASE64 method for encoding) 7. Custom attributes In addition to some of the attributes mentioned above, you can also add your own attributes and response values ????in MANIFEST.MF. For example, the J2ME program jar package may contain the following information MicroEdition-Configuration: CLDC-1.0MIDlet-Name: J2ME_MOBBER Midlet SuiteMIDlet-Info-URL: /MIDlet-Icon: /icon.pngMIDlet-Vendor: Midlet Suite VendorMIDlet-1: mobber,/icon.png,mobberMIDlet-Version: 1.0. 0MicroEdition-Profile: MIDP-1.0MIDlet-Description: Communicator The key is how do we read this information? In fact, it is very simple. JDK provides us with an API for processing this information. For detailed information, please see the java.util.jar package. We can obtain it by passing the path of a jar file to JarFile and then calling the getManifest method of JarFile. Manifest information. ******************************Plan for packaging .exe files****************** ************ For Windows users, it is best to package java applications into .exe. Now I will introduce two methods. 1. Use the professional application packaging tool InstallAnywhere. This software can run on almost all platforms. Of course, you have to download it to the platform you need! And it can also be packaged into installers for various platforms. 2. Use MINI’s free tool javalunch. The download URL of JavaLauncher is: /download/exe4j/files.php4. Step a) Use Eclipse to make the required main class into a jar package that can run independently. Pay attention to adding the manifest attribute and MainClass.

b) Create a new exe4j project c) Select "JAR in exe" mode d) Configuration in Configure application: i. Short name: Write whatever you want. ii. Ourput Directory: Select the output path. e) Configuration in Configure Executable: i. Executable type: There are three options, graphics, console. or service. Let’s start simple. Here we choose console ii. Executable name: Fill in the name of the destination output source. Such as test.exe iii. Icon file: exe icon file, but it must be an .ico file f) Configuration in Configure Java invocation: i. Classpath: Select the jar package we generated and the class library required to run the jar file ii. Main-Class: Select the main class we need to run. iii.Arguments (optional): input parameters. We don't need it here yet. g) Configuration in Configure JRE: i. Minimum Version: Write the minimum JVM version required to run the program, such as 1.4 h) Keep next, and default the options for the steps encountered until finish: OK. After the compilation is successful, there will be a brand new exe program in your output directory. Just enjoy it. 3 Summary and Comparison There are many tools for generating exe from Java. The above two are the two that I personally find more convenient to use. The principles of the two are basically the same, but the specific use is still a little different: 1. Similarities a) The biggest similarity is of course that their principles are interoperable. All are done by packaging executable java programs into executable jar packages. Convert again. b) The generated exe executable program needs to be run in a JVM environment with a higher version than the minimum version. 2. Differences a) When generating an exe, if you want the exe to run, you only need a pure JVM environment (no third-party class library is required). In JSmooth, you need to compress all the third-party libraries used into a jar package (because it has an embedded jar option), which is more troublesome, because when more than one jar is needed, these jar packages need to be First use jar –xvf to decompress, then use jar –cvf to create a new jar file, and then put it in the embedded jar option; exe4J will also compile the jar package used in the classppath into the exe. b) JSmooth is free; exe4J is a free software and requires registration, otherwise a very annoying prompt box will pop up when executing the exe. c) Selection of ico files: exe4J requires strict ico files, while JSmooth is compatible with jpg and other types of pictures.

The above is a transfer