我对 Maven 和 Spring MVC 完全陌生。我想做的是使用 Maven 设置一个新的 Spring MVC 项目(希望这句话有意义),并使用 Eclipse 在 Tomcat 上运行我的 Web 应用程序。
我正在按照此链接上的教程进行操作,但遇到了问题pom.xml
file:
- Maven 和 Spring 入门 http://spring.io/blog/2011/01/17/green-beans-getting-started-with-maven-and-spring/
本教程要求创建文件夹结构,并创建 pom.xml 文件。对于初学者,他们要求将此行放入 pom.xml 中:
xml 4.0.0org.springsource.greenbeans.mavenexample11.0-SNAPSHOTOur Simple Project
但是当我这样做时,我的 Eclipse 会抛出一个错误:
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project (D:\projectName\pom.xml) has 1 error
[ERROR] Non-parseable POM D:\projectName\pom.xml: only whitespace content allowed before start tag and not ` (position: START_DOCUMENT seen `... @1:1) @ line 1, column 1 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException
您知道正确的最小 pom.xml 可能是什么吗?我尝试了很多东西,但它对我不起作用......
您不需要自己创建文件夹结构。 Maven archtype 'maven-archetype-webapp' 会为你做到这一点。这是一个很好的教程,可指导您在 eclipse 中基本设置 MVC 项目(以及正确的方法):
-
使用Maven创建Spring MVC动态Web项目并使其支持Eclipse IDE http://www.beingjavaguys.com/2013/08/spring-maven-web-application-in-eclipse.html
<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.beingjavaguys.sample</groupId>
<artifactId>SampleSpringMaven</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SampleSpringMaven Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<jdk.version>1.6</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>SampleSpringMaven</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>my-tomcat</server>
<path>/SampleSpringMaven</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)