The Java project is packaged into a Jar,main method that can be run with parameters

Source: Internet
Author: User

I. Overview

Java project has two kinds of architectures, one is b/s architecture, and the other is C/s architecture.
For b/s architecture, our common Java EE is the B/s architecture, usually developers will develop locally, then package the project into a war file and upload it to the server for invocation.
For b/s architecture, usually there is a main method, which is the Java project/program that we often write. Typically, after development, the project is packaged into a jar package, which is then uploaded to the server for invocation.
In this paper, the latter is introduced.

Ii. Description of requirements

A Java project that contains multiple Java files, a Java file, and a third-party library (a jar package imported from the outside). where the main function (project portal) is within a package of the project, the main function must have four parameters.

Third, export jar package Step 3.1 to ensure that the project is finished correctly

This is a step that will not be eliminated.

3.2 Select items, right-click

Mouse click on project name, select U, right-click, pop-up menu list

3.3 Select Export

In the list that pops up, select "Export ..." and the export window pops up.

3.4 Select Export runnable jar file

In the Export window that pops up, click Open Java and select the runable JAR file option.

    • Jar file, simply package the project into a jar package, typically used for the export of Java Lib, for other people to rely on development use
    • runable jar file, as the name implies, can run a jar package that can be run (because a project entry is subsequently specified)

Select the Runable JAR file option and click Next to eject the runable jar file Export window

3.4 Configuring the JAR Package

In the pop-up runable JAR file Export window,

    • Modify the Launch configuration, select the entry for your project, which is the class with the Main method
    • Export destination, select the directory you want to import
    • Library handling, a few options as the name implies, do not repeat
    • Click Next
3.5 Complete

The export process may take a while, and there is a green progress bar on the ground to alert the progress. Wait a moment to complete the process.

If the project is dependent on a third-party package, you may be prompted with the following alert box, click OK.

Because there may be some non-canonical in the project, after you complete this step, a warning box may pop up. Click Details to view more information and click OK to enter the export process.

You can see the exported jar package in the target directory that you selected in step 3.4.

Four, can run the jar file structure resolution 4.1 Unzip the above steps to get the jar package

File directory structure See:

    • The Meta-inf folder holds the configuration information for the project:
      • Maven dependencies (if any, the Maven folder is included in the Meta-inf)
      • MANIFEST Information for the project (stored in meta-inf/manifest. MF) manifest-version, Class-path, Main-class, notice that there is a space between the content behind them and the colon, this space is necessary
    • Other folders contain. class files, which are structured like bin directories in Exlipse projects, and third-party packages are also available if third-party dependencies are available. class files

Iv. running on the server

The steps to upload the file to the server are not described in this article. Here is a brief explanation of the running process.
Go to the Runnable Jar package directory, open the command line here, type the command java -jar JSTUNServer.jar 5000 192.168.2.1 5001 192.168.2.3 ( java -jar [jar包] [参数1 参数2 参数3...] ), and hit Enter to run.

Since the instance code I chose requires a special environment, the error reported here is irrelevant to the content discussed in this article. The correctness of the above procedure is demonstrated here.

The Java project is packaged into a Jar,main method that can be run with parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.