欢迎访问我的个人网站==》 jiashubing.cn

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>

 

posted @ 2017-04-12 10:41  贾树丙  阅读(646)  评论(0编辑  收藏  举报