(1).创建pom.xml
<?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>com.x2_sap_collect</groupId> <artifactId>x2_sap_collect_shell</artifactId> <version>1.0-SNAPSHOT</version> <!--项目属性--> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <!--启动类--> <start-class>com.x2_sap_collect.ShellApplication</start-class> <!--跳过测试类--> <skipTests>true</skipTests> </properties> <!--项目依赖--> <dependencies> <!--一定要依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.7.14</version> </dependency> <!--一定要依赖--> <dependency> <groupId>org.springframework.shell</groupId> <artifactId>spring-shell-starter</artifactId> <version>2.1.11</version> </dependency> </dependencies> <!--编译设置--> <build> <plugins> <!--配置spring boot的打包依赖,方便把整个项目打包为Jar文件--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.5.4</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build></project>
(2).创建一个启动类,文件路径为.\src\main\java\com\项目名\ShellApplication.java
package com.x2_sap_collect;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class ShellApplication { public static void main(String[] args) { SpringApplication app = new SpringApplication(ShellApplication.class); app.run(args); }}
(3).创建一个命令行程序类,文件路径为.\src\main\java\com\项目名\task\V1.java
package com.x2_sap_collect.task;import org.springframework.shell.standard.ShellComponent;import org.springframework.shell.standard.ShellMethod;@ShellComponentpublic class V1 { @ShellMethod("Add two integers together.") public int add(int a, int b) { return a + b; }}
(4).启动程序进行测试
java -jar .\x2_sap_collect_shell-1.0-SNAPSHOT.jarshell:>add --a 1 --b 23
测试1+2等于3
(5).学习中我遇到的错误
提示./xx.jar中没有主清单属性,需要您在pom中设置启动类start-class,同时通过编译设置依赖spring-boot-maven-plugin来进行编译,spring-boot-maven-plugin方便把整个项目打包为Jar文件
java一个类可以有多个构造方法,根据传参类型和个数来匹配执行哪个构造方法。public class Member { public Member(){  ...
java限制1个方法同一时间只能被一个线程访问public synchronized void setOrderPay(){ }加上synchronized 修饰符即可...
java判断字符是否是一个字母System.out.println(Character.isLetter('a'));java判断字符是否是一个数字System.out.println(Character.isDigit('0'));java判断字符是否是一个空白Sy...
在java中字符串属于对象,刚开始我就疑惑为什么int char等类型都是小写,结果String是大写,java太反人类,后来才知道String是对象。(1).java创建字符串String text = "net"; String tex...
java stringBuffer(1).stringBuffer和stringBuilder区别stringBuffer是线程安全的,stringBuilder速度更快(2).简单的stringBuffer例子StringBuffer sBuffer = new&nb...
System.out.println("当前时间戳(秒): " + System.currentTimeMillis()/1000); System.out.println("当前时间戳(毫秒): " +&nb...