Maven package打包webapp项目遇到的问题
2017-02-10 16:37
465 查看
环境
Java: JDK_1.7.0_79
Eclipse: Mars(4.5.0)
Maven: 3.3.3
最近公司同事重构某Java web项目,完成之后发现部署启动总是不成功
项目原结构为
test-parent
|-test-common
|-test-dao
|-test-po
|-test-vo
|-test-service
|-test-api
其中test-po包含了Hibernate的数据库映射文件
项目采用SpringMVC+Hibernate
spring: 3.2.14.RELEASE
hibernate: 3.0
applicationContext.xml中的hibernate配置如下:
使用mvn clean package -Denv=qa打包,一直没有问题,经过重构之后项目结构为
test-api, 即所有类及文件包含在一个项目内,无论使用package或者install打包war后,生成的文件都报上文的错误。经同事定位,是由于生成的war的lib目录下包含了一个jar文件(打包当前webapp项目的.class和resources文件),删掉此文件即不会报错,于是最后修改了maven-war-plugin的配置archiveClasses为false解决问题
引申:
maven package打包webapp项目时
a)若没有pom的<name>test-api</name>属性时,必须设置maven-war-plugin
b)若含有pom的<name>test-api</name>属性时,可以不设置maven-war-plugin,但会提示web.xml已存在
c)maven-war-plugin的archiveClasses属性若设置为true,webapp模块会生成jar并存在lib目录,反之不会
Java: JDK_1.7.0_79
Eclipse: Mars(4.5.0)
Maven: 3.3.3
最近公司同事重构某Java web项目,完成之后发现部署启动总是不成功
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.test.test.po.Test at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:3179) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:178) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:4006) ... 42 more
项目原结构为
test-parent
|-test-common
|-test-dao
|-test-po
|-test-vo
|-test-service
|-test-api
其中test-po包含了Hibernate的数据库映射文件
项目采用SpringMVC+Hibernate
spring: 3.2.14.RELEASE
hibernate: 3.0
applicationContext.xml中的hibernate配置如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.hbm2ddl.auto">validate</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.query.substitutions">Y</prop> </props> </property> <property name="mappingLocations"> <list> <value>classpath*:com/test/test/test/po/**/*.xml</value> </list> </property> </bean>
使用mvn clean package -Denv=qa打包,一直没有问题,经过重构之后项目结构为
test-api, 即所有类及文件包含在一个项目内,无论使用package或者install打包war后,生成的文件都报上文的错误。经同事定位,是由于生成的war的lib目录下包含了一个jar文件(打包当前webapp项目的.class和resources文件),删掉此文件即不会报错,于是最后修改了maven-war-plugin的配置archiveClasses为false解决问题
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>artifact-package</id> <phase>package</phase> <goals> <goal>war</goal> </goals> <configuration> <archiveClasses>false</archiveClasses> <warSourceExcludes>WEB-INF/lib/servlet-*</warSourceExcludes> <webResources> <resource> <directory>src/main/webapp/WEB-INF</directory> <filtering>true</filtering> <targetPath>WEB-INF</targetPath> <includes> <include>**/web.xml</include> </includes> </resource> </webResources> </configuration> </execution> </executions> </plugin>
引申:
maven package打包webapp项目时
a)若没有pom的<name>test-api</name>属性时,必须设置maven-war-plugin
b)若含有pom的<name>test-api</name>属性时,可以不设置maven-war-plugin,但会提示web.xml已存在
[INFO] WEB-INF/web.xml already added, skipping
c)maven-war-plugin的archiveClasses属性若设置为true,webapp模块会生成jar并存在lib目录,反之不会
相关文章推荐
- Eclipse通过Maven插件创建webapp项目中遇到的问题
- Maven项目打包遇到的两个问题
- 一个笨鸟在使用Eclipse导入Maven项目遇到的问题及解决方案
- reindex-maven 私服(nexus)架设以及项目管理中遇到的问题及解决方案(updating)
- Intellij Idea导入非maven Web项目时遇到lib目录冲突的问题
- idea 中部署maven项目是遇到的问题
- ant打包所遇到问题(外导library项目包)
- maven构建项目自动部署到tomcat中遇到的各种sb问题总结
- maven构建项目自动部署到tomcat中遇到的各种sb问题总结
- 遇到的问题----新建maven项目ArtifactTransferException 和Execution default-testResources of goal
- 遇到问题-----maven项目右键运行或者run as运行main方法找不到类
- java web 项目 转 maven java web 项目(旧项目 转maven)遇到的问题
- maven创建webapp项目碰到的问题
- 遇到问题-----maven项目右键运行或者run as运行main方法找不到类
- maven整合到eclipse中的android项目遇到的几个问题及解决方法
- maven构建项目自动部署到tomcat中遇到的各种sb问题总结
- 使用ant对项目进行多渠道打包时遇到问题记录
- Maven_Python打包遇到的问题总结
- Maven 项目不打包 *.xml 映射文件 的问题解决