Spring项目上的Maven构建错误
Posted
技术标签:
【中文标题】Spring项目上的Maven构建错误【英文标题】:Maven Build Error on a Spring Project 【发布时间】:2015-11-28 06:40:39 【问题描述】:我正在尝试使用 Maven 构建 Spring MVC 项目,但是当我运行 maven compile 时出现错误(如下)。
这是我的pom.xml
文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zodiac.qtp</groupId>
<artifactId>QTPGenerator</artifactId>
<packaging>war</packaging>
<version>0.1.0.BUILD-SNAPSHOT</version>
<name>QTPGenerator</name>
<properties>
<aspectj.version>1.7.4</aspectj.version>
<java.version>7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.7.5</slf4j.version>
<spring.version>3.2.6.RELEASE</spring.version>
<spring-security.version>3.1.0.RELEASE</spring-security.version>
</properties>
<repositories>
<repository>
<id>spring-maven-release</id>
<name>Spring Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
<repository>
<id>spring-maven-milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>codehaus</id>
<url>http://repository.codehaus.org/org/codehaus</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-maven-release</id>
<name>Spring Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</pluginRepository>
<pluginRepository>
<id>spring-maven-milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<!-- EHcache dependencie -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.7.Final</version>
</dependency>
<!-- General dependencies for standard applications -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>ibm.lotus</groupId>
<artifactId>domingo</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>com.zodiac.lotus</groupId>
<artifactId>notes</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>$slf4j.version</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>$slf4j.version</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>$slf4j.version</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>$aspectj.version</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>$aspectj.version</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sf.flexjson</groupId>
<artifactId>flexjson</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>$spring.version</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>$spring.version</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.7.Final</version>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>$spring.version</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.webflow</groupId> -->
<!-- <artifactId>spring-js-resources</artifactId> -->
<!-- <version>2.2.1.RELEASE</version> -->
<!-- </dependency> -->
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>$spring-security.version</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>$spring-security.version</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>$spring-security.version</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>$spring-security.version</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-ImportXhtml</artifactId>
<version>3.0.0</version>
</dependency>
<!-- Hibernate Search Dependencies -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>4.5.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-analyzers</artifactId>
<version>4.5.1.Final</version>
</dependency>
<!-- APACHE POI Dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
<!-- Selenium Tests -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<!-- necessary only if you are using WebDriver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.42.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<!-- End Selenium Tests -->
<!-- APAche POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<!-- END APAche POI -->
<!-- PDF SEARCH -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.1.0</version>
</dependency>
<!-- end PDF SEARCH -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<!-- <configuration> <webXml>target/web.xml</webXml> </configuration> -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>$java.version</source>
<target>$java.version</target>
<encoding>$project.build.sourceEncoding</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<!-- NB: You must use Maven 2.0.9 or above or these are ignored (see
MNG-2972) -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>$aspectj.version</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>$aspectj.version</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>$java.version</source>
<target>$java.version</target>
<!-- Aspects in src/main/java and src/main/aspects are added as default
in the compile goal. Aspects in src/test/java and src/test/aspects are added
as default in the test-compile goal. Aspects in src/main/java are added in
the test-compile goal if weaveWithAspectsInMainSourceFolder is set to true -->
<weaveWithAspectsInMainSourceFolder>false</weaveWithAspectsInMainSourceFolder>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>$project.build.sourceEncoding</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<printSummary>false</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*_Roo_*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<!-- IDE -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.7</version>
<!-- Note 2.8 does not work with AspectJ aspect path -->
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<additionalBuildcommands>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
<aspectPath>org.springframework.aspects</aspectPath>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
</buildCommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
<projectnature>com.springsource.sts.roo.core.nature</projectnature>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-idea-plugin</artifactId>
<version>2.2</version>
<configuration>
<downloadSources>true</downloadSources>
<dependenciesAsLibraries>true</dependenciesAsLibraries>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.4.v20120524</version>
<configuration>
<webAppConfig>
<contextPath>/$project.name</contextPath>
</webAppConfig>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<configuration>
<browser>*firefox</browser>
<suite>src/main/webapp/selenium/test-suite.xhtml</suite>
<results>$project.build.directory/selenium.html</results>
<startURL>http://localhost:4444/</startURL>
</configuration>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.25.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
这是 Maven 命令输出
[错误] 无法在项目 QTPGenerator 上执行目标:无法解析项目 com.zodiac.qtp:QTPGenerator:war:0.1.0.BUILD-SNAPSHOT 的依赖项:无法收集 [org.hibernate:hibernate- ehcache:jar:4.3.7.Final (编译), commons-io:commons-io:jar:1.4 (编译), mysql:mysql-connector-java:jar:5.1.6 (编译), junit:junit:jar :4.11 (测试), com.sun.mail:javax.mail:jar:1.5.2 (编译), ibm.lotus:domingo:jar:1.5.1 (编译), com.zodiac.lotus:notes:jar: 1.0.0(编译)、log4j:log4j:jar:1.2.17(编译)、org.slf4j:slf4j-api:jar:1.7.5(编译)、org.slf4j:jcl-over-slf4j:jar:1.7 .5 (编译), org.slf4j:slf4j-log4j12:jar:1.7.5 (编译), org.aspectj:aspectjrt:jar:1.7.4 (编译), org.aspectj:aspectjweaver:jar:1.7.4 ( compile), javax.servlet:servlet-api:jar:2.5 (提供), net.sf.flexjson:flexjson:jar:2.1 (compile), org.apache.commons:commons-lang3:jar:3.1 (compile), org.springframework:spring-core:jar:3.2.6.RELEASE (编译), org.springframework:spring-test:jar:3.2.6.RE LEASE (测试), org.springframework:spring-context:jar:3.2.6.RELEASE (编译), org.springframework:spring-aop:jar:3.2.6.RELEASE (编译), org.springframework:spring-aspects :jar:3.2.6.RELEASE (编译), org.hsqldb:hsqldb:jar:2.2.9 (编译), org.hibernate:hibernate-core:jar:4.3.7.Final (编译), org.hibernate: hibernate-entitymanager:jar:4.3.7.Final (编译), org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final (编译), commons-collections:commons-collections: jar:3.2.1 (编译), org.hibernate:hibernate-validator:jar:4.3.1.Final (编译), javax.validation:validation-api:jar:1.0.0.GA (编译), javax.transaction :jta:jar:1.1 (编译), org.springframework:spring-jdbc:jar:3.2.6.RELEASE (编译), org.springframework:spring-orm:jar:3.2.6.RELEASE (编译), commons- pool:commons-pool:jar:1.5.6 (编译), commons-dbcp:commons-dbcp:jar:1.4 (编译), org.springframework.data:spring-data-jpa:jar:1.4.3.RELEASE (编译), org.springframework:spring-webmvc:jar:3.2.6.RELEASE (co mpile), commons-digester:commons-digester:jar:2.1 (编译), commons-fileupload:commons-fileupload:jar:1.2.2 (编译), javax.servlet.jsp.jstl:jstl-api:jar:1.2 (编译), org.glassfish.web:jstl-impl:jar:1.2 (编译), javax.el:el-api:jar:2.2 (提供), joda-time:joda-time:jar:1.6 (编译) , javax.servlet.jsp:jsp-api:jar:2.1 (提供), commons-codec:commons-codec:jar:1.5 (编译), org.springframework.security:spring-security-core:jar:3.1.0 .RELEASE (编译), org.springframework.security:spring-security-config:jar:3.1.0.RELEASE (编译), org.springframework.security:spring-security-web:jar:3.1.0.RELEASE (编译), org.springframework.security:spring-security-taglibs:jar:3.1.0.RELEASE (编译), org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13 (编译), javax.mail: javax.mail-api:jar:1.5.1 (编译), javax.mail:mail:jar:1.4 (编译), org.json:json:jar:20140107 (编译), org.docx4j:docx4j-ImportXHTML:jar :3.0.0 (编译), org.hibernate:hibernate-search-orm:jar:4.5.1.Final (编译), org.hibernate:hibernate-search-analyzers:jar:4.5.1.Final (编译), org.apache.poi:poi:jar:3.10-FINAL (编译), org.apache.poi:poi-ooxml:jar: 3.10-FINAL(编译)、org.seleniumhq.selenium:selenium-java:jar:2.44.0(编译)、org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.42.2(测试)、com.google .code.gson:gson:jar:2.3.1 (编译), org.apache.poi:ooxml-schemas:jar:1.1 (编译), org.apache.pdfbox:pdfbox:jar:1.1.0 (编译)] :无法读取 ibm.lotus:domingo:jar:1.5.1 的工件描述符:无法将工件 ibm.lotus:domingo:pom:1.5.1 从/到 codehaus (http://repository.codehaus.org/org/codehaus) 传输:repository.codehaus.org:名称或服务未知:未知主机 repository.codehaus.org:名称或服务未知 -> [帮助 1] [错误]
【问题讨论】:
我认为它可能与***.com/questions/32248317/…重复 【参考方案1】:您必须在存储库块中删除 repository.codehaus.org。
所有 Codehaus 服务将逐步终止,直至 5 月 17 日 2015
如果您被引导到这里,那么您正在访问的服务可能 已经被禁用,或者我们正试图通过以下方式引起您的注意 尽早中断服务。
现在 Codehaus 工件位于 Maven Central 存储库中
【讨论】:
【参考方案2】:转到.m2 repo 并找出repository 下的目录结构。并删除相同。 清理 Java 项目。它将自动加载所需的 jar。不需要做任何其他事情。
【讨论】:
以上是关于Spring项目上的Maven构建错误的主要内容,如果未能解决你的问题,请参考以下文章
使用http://start.spring.io/构建maven微服务项目的几个坑及eclipse构建spring boot微服务项目
Gradle 学习总结—— 如何将 Spring Boot 构建工具从 Maven 迁移到 Gradle
Gradle 学习总结—— 如何将 Spring Boot 构建工具从 Maven 迁移到 Gradle