(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文件
字节(Byte)是计量单位,表示数据量多少,是计算机信息技术用于计量存储容量的一种计量单位,通常情况下一字节等于八位。字符(Character)计算机中使用的字母、数字、字和符号,比如'A'、'B'、'$'、'&'等。一般在英文...
public class test { public static void main(String[] args) { &...
(1).final 修饰符通常和 static 修饰符一起使用来创建类常量。(2).父类中的 final 方法可以被子类继承,但是不能被子类重写,声明 final 方法的主要目的是防止该方法的内容被修改。public class Member {  ...
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...