How does a Java program generate a Jar execution file (2), javajar
I. UseEclipseProductionJarFile
Note: This method can be used to package a project containing a third-party jar package.
1. Right-click your Java project, select Export, and select Runnable JAR file in the Java folder, as shown in:
2. After you select Runnable JAR file, the following dialog box is displayed. After you select the export path, Finish by default. However, note the following two points:
- The JVM parameter you set in the run configuration does not take effect after it is packaged. You need to specify it in the command line when executing the jar (see figure 4 );
- There are three processing methods for third-party packages. No matter which one does not affect your use, I use the first one by default, he will decompress the third-party jar package and put it in src.
3. after the jar package is generated, the executable jar package is generated. If your project contains a configuration file, such as conf/xx. properties, create the conf directory in the directory at the same layer as the jar package, and put xx in the conf directory. properties, as shown in:
4. Finally, run the packaged jar file. Execute the start java command in the command line and specify the JVM parameters. For example, set the initial memory allocation to 128 MB, and the maximum value is 256 MB:
Start java-Xmx256m-Xms128m-jar spider. jar
In, we can see that there is a run. bat file, which actually contains only one line of command: start java-Xmx256m-Xms128m-jar spider. jar, and then double-click it to execute the jar. When you need to change the startup parameters, you only need to edit run. bat.