将maven依赖项添加到GWT项目

时间:2011-11-13 22:20:59

标签: gwt maven

我开始我的GWT项目,然后有人告诉我使用maven很好,所以我决定尝试将我的maven依赖项添加到我的项目中 它生成了非常简单的pom文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven 4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>demo5</groupId>
  <artifactId>demo5</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
</project>

我试图运行目标gwt:compile gwt:run,当我第一次运行它时下载了很多罐子并且卡住了,当我第二次运行它时它会给我这个:

[INFO] --- gwt-maven-plugin:2.4.0:compile (default-cli) @ demo5 ---
[WARNING] The POM for com.google.gwt:gwt-servlet:jar:2.4.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
Downloading: http://repo1.maven.org/maven2/com/google/gwt/gwt-dev/2.4.0/gwt-dev-2.4.0.jar
Downloaded: http://repo1.maven.org/maven2/com/google/gwt/gwt-dev/2.4.0/gwt-dev-2.4.0.jar (27647 KB at 61.4 KB/sec)
[WARNING] GWT plugin is configured to detect modules, but none were found.
[INFO] 
[INFO] >>> gwt-maven-plugin:2.4.0:run (default-cli) @ demo5 >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ demo5 ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\workspace\springsource\demo5\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ demo5 ---
455388 [main] ERROR org.sonatype.guice.bean.reflect.LoadedClass - Error injecting: org.apache.maven.plugin.CompilerMojo
java.lang.NoClassDefFoundError: org/codehaus/plexus/compiler/CompilerException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getDeclaredConstructors(Class.java:1836)
    at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:243)
    at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:96)
    at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:609)
    at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:816)
    at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:750)
    at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:235)
    at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:185)
    at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:824)
    at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:938)
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:971)
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:932)
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:984)
    at org.sonatype.guice.bean.reflect.AbstractDeferredClass.get(AbstractDeferredClass.java:48)
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
    at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:949)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:995)
    at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:945)
    at com.google.inject.Scopes$1$1.get(Scopes.java:59)
    at org.sonatype.guice.bean.locators.LazyQualifiedBean.getValue(LazyQualifiedBean.java:66)
    at org.sonatype.guice.plexus.locators.LazyPlexusBean.getValue(LazyPlexusBean.java:54)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:247)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:239)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:451)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:98)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:365)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:199)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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)
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.compiler.CompilerException
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    ... 51 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7:36.976s
[INFO] Finished at: Sun Nov 13 22:03:36 GMT 2011
[INFO] Final Memory: 7M/16M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project demo5: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile failed: Unable to load the mojo 'compile' in the plugin 'org.apache.maven.plugins:maven-compiler-plugin:2.3.2'. A required class is missing: org/codehaus/plexus/compiler/CompilerException
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-compiler-plugin:2.3.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/c:/users/mad%20troll/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.jar
[ERROR] urls[1] = file:/c:/users/mad%20troll/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.5/plexus-utils-2.0.5.jar
[ERROR] urls[2] = file:/c:/users/mad%20troll/.m2/repository/org/codehaus/plexus/plexus-compiler-api/1.8.1/plexus-compiler-api-1.8.1.jar
[ERROR] urls[3] = file:/c:/users/mad%20troll/.m2/repository/org/codehaus/plexus/plexus-compiler-manager/1.8.1/plexus-compiler-manager-1.8.1.jar
[ERROR] urls[4] = file:/c:/users/mad%20troll/.m2/repository/org/codehaus/plexus/plexus-compiler-javac/1.8.1/plexus-compiler-javac-1.8.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------: org.codehaus.plexus.compiler.CompilerException
[ERROR] -> [Help 1]
[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/PluginContainerException

如果这会有所帮助,我会在eclipse下工作 任何人都可以告诉我我做错了什么以及我如何解决这个问题? 提前谢谢。

2 个答案:

答案 0 :(得分:0)

创建项目并添加一些依赖项是不够的。首先,您需要添加正确的依赖项,codehaus插件以及正确的配置,当然还有正确的项目结构和web.xml以及gwt描述符模块。

使用maven启动gwt的最简单方法是从原型生成一个完整的项目。请看http://mojo.codehaus.org/gwt-maven-plugin/user-guide/archetype.html

要生成GWT项目,只需在控制台中输入:

mvn archetype:generate \
   -DarchetypeRepository=repo1.maven.org \
   -DarchetypeGroupId=demo5 \
   -DarchetypeArtifactId=demo5 \
   -DarchetypeVersion=2.4.0

接下来,您必须将生成的项目导入IDE,我建议您在使用以下命令启动托管模式之前对其进行编译:

mvn gwt:run

答案 1 :(得分:0)

您可以将-maven标记与GWT SDK附带的webAppCreator实用程序一起使用,如下所示:

webAppCreator -maven -out MyGwtProject com.mycompany.myproject.MyGwtProject