首先随便准备一个Java文件(含有main方法)
使用IDEA的方式打jar包
步骤:
选择main class
选择meta-info路径
选择输出位置
点击OK就可以
然后点击它就可以了
然后选择build,即可
maven项目
指定入口类
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.lt.QuickStartServer</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
spring boot插件
最好继承 spring-boot-starter 父项目
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0.RELEASE</version>
<configuration>
<!--使用-Dloader.path需要在打包的时候增加<layout>ZIP</layout>,不指定的话-Dloader.path不生效-->
<layout>ZIP</layout>
<!-- 指定该jar包启动时的主类[建议] -->
<mainClass>com.lt.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
java -jar xx.jar 参数 参数……
这种是怎么实现的呢。
原理很简单 就是用args数组赋值就可以了。代码如下:
public static void main(String[] args) {
String x =args[0];
String y =args[1];
System.out.println(x);
System.out.println(y);
}