java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Spring Shell打Jar包

Spring Shell打Jar包时常用小技巧

作者:贾树丙

这篇文章主要介绍了Spring Shell打Jar包时常用小技巧,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1、Main-Class

  spring-shell项目打Jar包的一个必要条件就是,指定Main-Class为org.springframework.shell.Bootstrap

  一般情况下,如果想在IDE中直接运行项目,显示在控制台中,也会调用org.springframework.shell.Bootstrap中的Main方法。如下:

import org.springframework.shell.Bootstrap;
import java.io.IOException;

public class HelloApplication {
  public static void main(String[] args) throws IOException {
    Bootstrap.main(args);
  }
}

2、配置读取新xml文件

  spring-shell项目,要求在resource/META-INF/spring目录下,必须有一个spring-shell-plugin.xml文件,打Jar包的时候必须要包括这个文件。

  在IDEA中,Maven项目是会默认扫描resource目录的,但是打成Jar包的时候, 是不会扫描的。我也不知道为什么,只是只是此时最好在pom.xml中配置一下,让它读取这个xml文件:

<resources>
  <resource>
   <directory>src/main/resources</directory>
   <includes>
     <include>**/*.xml</include>
   </includes>
  </resource>
  <resource>
   <directory>src/main/java</directory>
   <includes>
     <include>**/*.xml</include>
   </includes>
  </resource>
</resources>

  PS:src/main/java目录下的xml文件也得读。如果把上面这两个<resource>合并到一起,写成<directory>src/main</directory>,反而是不对的。太奇怪了。

3、打包多个Jar包

  如果项目打Jar包时,需要依赖于另外一个spring-shell的Jar包,可以直接在pom.xml中添加依赖,这样就会把所有的新增的命令合并到一起

<dependencies>
  <dependency>
   <groupId>cn.com.bignzi</groupId>
   <artifactId>dcore</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  </dependency>
  <dependency>
   <groupId>cn.com.bignzi</groupId>
   <artifactId>plugin.data</artifactId>
   <version>0.0.1-SNAPSHOT</version>
</dependencies>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文