Use eclipse to export the program as a jar file

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.

tool

  • Computer (already configured java installation environment)
  • eclipsetools

method/step

  1. 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);    }}

    How to export the program as a jar file in eclipse





  2. 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"

    How to export the program as a jar file in eclipse





  3. Select the export storage path location . Can be stored in a disk or Chinese directory. Select the export directory location

    How to export the program as a jar file in eclipse





  4. 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

    How to export the program as a jar file in eclipse





  5. 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.

    How to export the program as a jar file in eclipse







  6. 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

    How to export the program as a jar file in eclipse





  7. 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.

  8. How to export the program as a jar file in eclipse
    END






Precautions

  • In the process of using java, it is best not to have Chinese names or directories.
  • If the java environment variables are not configured, you can search for: Baidu experience "How to install java and how to configure java environment variables" to configure

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324694051&siteId=291194637