idea建立、執行、打包控制檯程式

bcbobo21cn發表於2020-11-27

新建maven專案;選擇已安裝的jdk;

新建專案;

完成如下;

輸入一段程式碼;

import java.io.*;
public class MyClass
{
    private int val1,val2;

    public void myFun(int x,int y)
    {
        val1=x;
        val2=y;
        System.out.println("the sum is "+(val1+val2));
    }

    //主函式
    public static void main(String arg[])
    {
        MyClass MyObj=new MyClass();
        MyObj.myFun(3,4);
    }
}

執行一下;沒問題;

設定選單;

選擇如下;

在pom檔案加入內容;之後會出來target資料夾;

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>console1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!-- maven外掛 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <plugin>
                <!--打包跳過測試-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>MyClass</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

構建專案;沒有看到jar檔案打包出來;這操作還不熟悉; 

再進行如下操作;

 

1

構建專案,然後看到jar檔案出來了;

但是不能開啟此jar檔案;

也許radiobutton該選擇第二項;下回再整;

 

相關文章