Create maven project in eclipse, export jar package, run on windows server

1. Create a maven project in eclipse

1>In the menu bar of eclipse: file -> new -> project -> maven project -> next ->next -> select maven-archetype-quickstart ->next -> Group id: enter com.zhaifx; enter Artifact id zhaifx ->finish

2>Create App.java class under com.zhaifx and create main method.

public class App{
    
    

    public static void main( String[] args ){
        System.out.println( "成功!" );
    }
}

3>Open the pom.xml file, add the following code in the tag, and define the main entry.

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.zhaifx.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

2. Export the jar package

1>Right click on the project -> run as -> run configurations...

2>Click Browse Workspace... button to select the project -> ok

3>Enter package in goals for packaging (you can also enter clean package)

Write picture description here

4> Click run.

Write picture description here

5>Find zhaifx-0.0.1-SNAPSHOT.jar in the target file of the project, which is the exported jar package


3. Run on windows server

1>Start cmd

2>Find the path of the jar package

3>Enter java -jar zhaifx-0.0.1-SNAPSHOT.jar and press Enter to see the result (input the first letter and press tab to quickly enter)

Write picture description here


【note】

We find the packaged jar package, open it as a compressed package, and find the MANIFEST.MF file under the META-INF file.

Write picture description here

Write picture description here

Then we open the file with an editor.

Write picture description here

The Main-Class is the mainClass that we configured in pom.xml.

Guess you like

Origin blog.csdn.net/u010318957/article/details/56011627