eclipse 打包maven项目的坑

一、问题:

  公司开发了一个项目,需要作为后台服务运行,整个项目的构成是:【maven + spring + eclipse】

  在使用打包的时候遇到许多问题:

  (1)eclipse中maven工具的集成【配置仓库

  (2) 打包的jre环境必须是jdk本身自带的,须在【performence--java】配置好java的运行环境【会报出多个环境异常】

  (3)maven项目打包的命令可以使用【install/maven build】install会把安装包打到仓库里,build 会把安装包达到【target】

  (4)【spring-ApplicationContext】如果是使用spring的手动加载,在读取配置文件的时候会报出【offending resource】

  (5)如果maven的依赖除仓库本身外还依赖本地其它的jar包,需要西安【install】本地jar包到本地仓库再打包才能打入

 

二、解决:

  (1)手动加载spring容器获取不到配置文件的情况,【classpath + *】

    public static void init() {
        if (ac == null) {
            //ac = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");//修改为添加*号即可
            ac = new ClassPathXmlApplicationContext("classpath*:applicationContext-dao.xml");
            resource = new ClassPathResource("/properties/file.properties");
        }
    }

  

三、总结:

  (1)为什么加【 * 】号可以识别到类路径的问题,网上的资料说加星号后可以识别其它jar包项目的配置文件,没有深入了解,大家有知道的麻烦评论下

classpath 和 classpaht*的区别 , classpath* 会查找根目录下所有的文件,至到找到匹配文件即可。儿classpath只会在/WEB-INF/classes中查找。

  (2)在服务调试的时候,想到一个问题,在【cmd】启动一个jar包后,控制台当时可以看到程序的调试输出,再次打开控制台怎么查看这个程序的输出?

      试过linux的jobs命令,但是,当时运行的控制台关闭,job也就关闭了,无法重新输出到本控制台

  (3)还有一种spring容器加载配置文件错误的解决办法就是:

<plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-shade-plugin</artifactId>  
                <executions>  
                    <execution>  
                        <phase>package</phase>  
                        <goals>  
                            <goal>shade</goal>  
                        </goals>  
                        <configuration>  
                            <finalName>dwbi-excel</finalName>  
                            <shadedArtifactAttached>true</shadedArtifactAttached>  
                            <shadedClassifierName>jar-with-dependencies</shadedClassifierName>  
                <!-- 以下就是解决配置文件无法加载的另一种解决办法,我没有试验,是同事试验的 --> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>${mainClass}</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.tooling</resource> </transformer> </transformers> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin>

 

      

转载于:https://www.cnblogs.com/hackxiyu/p/8985188.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值