我已经从这篇博文下载了示例的源代码,我想将它导出到 Tomcat。我已经“几乎”成功地将项目导入 Eclipse,几乎是因为 Eclipse 没有将该项目视为 Web 项目。
好的,我仍然可以从控制台编译 WAR,而不是从 IDE 导出。
相反,我从控制台尝试过mvn package
,但出现错误:
djechelon@RAYNOR:~/workspace/rest-sample> mvn package
28/gen/2013 12:54:47 com.google.inject.internal.MessageProcessor visit
INFO: An exception was caught and reported. Message: java.util.NoSuchElementException
java.util.NoSuchElementException
at java.util.AbstractList$2.next(libgcj.so.13)
at com.google.inject.spi.InjectionPoint.forMember(InjectionPoint.java:116)
at com.google.inject.spi.InjectionPoint.<init>(InjectionPoint.java:73)
at com.google.inject.spi.InjectionPoint$InjectableMethod.toInjectionPoint(InjectionPoint.java:459)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:725)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:358)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:377)
at com.google.inject.internal.BindingBuilder.toInstance(BindingBuilder.java:84)
at org.codehaus.plexus.DefaultPlexusContainer$ContainerModule.configure(DefaultPlexusContainer.java:803)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.spi.Elements.getElements(Elements.java:80)
at org.sonatype.guice.bean.binders.MergedModule.configure(MergedModule.java:54)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:94)
at com.google.inject.Guice.createInjector(Guice.java:71)
at com.google.inject.Guice.createInjector(Guice.java:61)
at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
at org.apache.maven.cli.MavenCli.container(MavenCli.java:375)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:191)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at java.lang.reflect.Method.invoke(libgcj.so.13)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
28/gen/2013 12:54:47 com.google.inject.internal.MessageProcessor visit
INFO: An exception was caught and reported. Message: java.util.NoSuchElementException
java.util.NoSuchElementException
at java.util.AbstractList$2.next(libgcj.so.13)
at com.google.inject.spi.InjectionPoint.forMember(InjectionPoint.java:116)
at com.google.inject.spi.InjectionPoint.<init>(InjectionPoint.java:73)
at com.google.inject.spi.InjectionPoint$InjectableMethod.toInjectionPoint(InjectionPoint.java:459)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:725)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:358)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:377)
at com.google.inject.internal.BindingBuilder.toInstance(BindingBuilder.java:84)
at org.codehaus.plexus.DefaultPlexusContainer$DefaultsModule.configure(DefaultPlexusContainer.java:836)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.spi.Elements.getElements(Elements.java:80)
at org.sonatype.guice.bean.binders.MergedModule.configure(MergedModule.java:54)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:94)
at com.google.inject.Guice.createInjector(Guice.java:71)
at com.google.inject.Guice.createInjector(Guice.java:61)
at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
at org.apache.maven.cli.MavenCli.container(MavenCli.java:375)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:191)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at java.lang.reflect.Method.invoke(libgcj.so.13)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
[ERROR] Error executing Maven.
[ERROR] null
上述错误适用于任何 Maven 项目。我首先尝试从不稳定的包安装 Maven 3 ,然后卸载它,从 Apache 下载官方 Maven 3,然后在主目录中使用新包重试(所以我没有运行mvn
但是/home/djechelon/apache-mvn------/bin/mvn
):同样的错误。
但是,如果我从 Eclipse STS ( Spring Tools
-> Update Maven dependencies
) 运行 Maven,我不会收到任何错误,它会更新 Eclipse 的所有依赖项(但不会使项目成为 Web 项目)。
如何解决问题并将 WAR 部署到 Tomcat?
[添加] pom.xml 的内容
<?xml version="1.0"?>
<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">
<artifactId>rest-sample</artifactId>
<modelVersion>4.0.0</modelVersion>
<inceptionYear>2011</inceptionYear>
<packaging>war</packaging>
<groupId>com.blog.rest</groupId>
<version>1.0</version>
<properties>
<releaseCandidate>1</releaseCandidate>
<spring.version>3.1.1.RELEASE</spring.version>
<java.version>1.5</java.version>
<jackson.mapper.version>1.5.6</jackson.mapper.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.javadoc.reporting.version>2.7</maven.javadoc.reporting.version>
<commons.logging.version>1.1.1</commons.logging.version>
<log4j.version>1.2.16</log4j.version>
<context.path>rest-sample</context.path>
<jackson.mapper.version>1.5.6</jackson.mapper.version>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>${context.path}</warName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</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.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</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>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.mapper.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>
[编辑] Java 版本
djechelon@RAYNOR:~/workspace/rest-sample> java -version
java version "1.7.0_09"
OpenJDK Runtime Environment (IcedTea7 2.3.4) (suse-3.20.1-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)