Using eclipse software development, it is often necessary to type the code into a jar package for the finished product, and then copy the jar package to the server for running. The process of packaging with eclipse is also relatively simple, but there are also many pits, and you will fall into the pits if you are not careful. This experience introduces how to package the project java code (individual java code can also) into a jar package in eclipse.
method/step
-
Right-click --export on the prepared java package (separate).
The following is a simple java applet that can be used for testing
public class Main { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JTextArea textArea = new JTextArea(); panel.setLayout(new GridLayout()); textArea.setText(" Hello world...\n Today is "+ new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date())); panel.add(new JScrollPane(textArea)); frame.add(panel); frame.setSize(500, 500); frame.setVisible(true); }}
-
Select the type to export. In the Export dialog box, select the JAR File to export , or use the fuzzy query to enter the keyword "jar"
-
Select the export storage path location . Can be stored in a disk or Chinese directory. Select the export directory location
-
The exported data type is jar, that is, the suffix of the exported file is .jar. Note that the exported suffix is a file in .jar format
-
Select the entry of the program, that is, the class where the main method is located. Then click Finish. After completion, the corresponding jar file will be found in the exported directory.
-
To test whether the exported jar is normal, use the java -jar command to test.
First enter the directory where the jar is located, and then execute: java -jar XXX.jar command
Test to see if it works. If you use the code of the above steps, a windows box will pop up, indicating that the export is normal.
-
END