具有服务器端依赖性的GWT maven项目

时间:2012-07-06 09:33:29

标签: gwt maven jasper-reports conflict

我在eclipse下有一个maven GWT项目,因为我添加了一些服务器端依赖项,maven插件不再编译了。以下是有关上下文的更多信息:

如果我不添加除GWT之外的依赖项,目标gwt:GWT maven插件的编译成功完成:

<dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-servlet</artifactId>
    <version>${gwt.version}</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-user</artifactId>
    <version>${gwt.version}</version>
    <scope>provided</scope>
</dependency>

当我添加任何其他依赖项时,目标gwt:compile失败:

[INFO] establishing classpath list (scope = compile)
[ERROR] Exception in thread "main" java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.Compiler.<init>(Lorg/eclipse/jdt/internal/compiler/env/INameEnvironment;Lorg/eclipse/jdt/internal/compiler/IErrorHandlingPolicy;Lorg/eclipse/jdt/internal/compiler/impl/CompilerOptions;Lorg/eclipse/jdt/internal/compiler/ICompilerRequestor;Lorg/eclipse/jdt/internal/compiler/IProblemFactory;)V
[ERROR]     at com.google.gwt.dev.javac.JdtCompiler$CompilerImpl.<init>(JdtCompiler.java:93)
[ERROR]     at com.google.gwt.dev.javac.JdtCompiler.<init>(JdtCompiler.java:231)
[ERROR]     at com.google.gwt.dev.javac.JdtCompiler.compile(JdtCompiler.java:193)
[ERROR]     at com.google.gwt.dev.javac.CompilationState.compile(CompilationState.java:115)
[ERROR]     at com.google.gwt.dev.GWTCompiler.distill(GWTCompiler.java:327)
[ERROR]     at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:564)
[ERROR]     at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:554)
[ERROR]     at com.google.gwt.dev.GWTCompiler.main(GWTCompiler.java:214)

我确实在gwt:compile(http://mojo.codehaus.org/gwt-maven-plugin-1.2/compile-mojo.html)中搜索了关于类路径/依赖关系的配置参数但没有成功。

我想将服务器端依赖与GWT一起使用,告诉GWT插件不考虑非GWT依赖。


工作pom(gwt:编译成功完成):

<?xml version="1.0" encoding="UTF-8"?>
<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>mygroupid</groupId>
    <artifactId>projectname</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>project name</name>

    <organization>
        <name>My company</name>
        <url>my company url</url>
    </organization>

    <properties>
        <gwt.version>1.5.3</gwt.version>
    </properties>

    <build>
        <finalName>final name</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
                <version>2.5.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <ajdtVersion>none</ajdtVersion>
                </configuration>
                <version>2.9</version>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <runTarget>org.mycompany.myproject.Main/welcomeGWT.html</runTarget>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <warSourceDirectory>war</warSourceDirectory>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- GWT -->
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-servlet</artifactId>
            <version>${gwt.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>${gwt.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

不工作pom(gwt:compile抛出异常):

 <?xml version="1.0" encoding="UTF-8"?>
 <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>mygroupid</groupId>
    <artifactId>projectname</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>project name</name>

    <organization>
        <name>My company</name>
        <url>my company url</url>
    </organization>

    <properties>
        <gwt.version>1.5.3</gwt.version>
    </properties>

    <build>
        <finalName>final name</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
                <version>2.5.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <ajdtVersion>none</ajdtVersion>
                </configuration>
                <version>2.9</version>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <runTarget>org.mycompany.myproject.Main/welcomeGWT.html</runTarget>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <warSourceDirectory>war</warSourceDirectory>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.ibatis</groupId>
            <artifactId>ibatis-sqlmap</artifactId>
            <version>2.3.4.726</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>3.6.0</version>
        </dependency>



        <!-- GWT -->
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-servlet</artifactId>
            <version>${gwt.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>${gwt.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
 </project>

2 个答案:

答案 0 :(得分:1)

您在我们的项目中使用JasperReport吗?我记得使用JasperReport和GWT时遇到了问题。 JasperReport包含了与GWT预期不同的org.eclipse.jdt.internal.compiler.Compiler版本。

我认为你可以通过简单地改变类路径的顺序来解决这个问题(已在评论中提出)。如果这没有帮助,请尝试更新您的GWT版本。或者尝试找到一个JasperReport版本,其中包含一个与GWT一起使用的org.eclipse.jdt.internal.compiler.Compile类版本。

答案 1 :(得分:0)

在我们的Web应用程序部署过程中,我在QA Linux 环境中遇到了类似的错误,我们设法解决了这个问题。当我部署到我的本地 Windows 10 Linux Ubuntu 虚拟机时,问题就不存在了。我的环境配置如下

  1. Ubuntu 16.04 LTS
  2. Apache Maven 3.3.3
  3. Apache Tomcat / 8.0.32(Ubuntu)
  4. JVM 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14
  5. 问题是因为在两个不同的jar文件中发现了两个eclipse编译器类,这会在tomcat部署期间在类路径中产生冲突。罪魁祸首是文件ecj.jar和jdtcore.jar

    我原来的pom.xml snipet如下

        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
            <version>6.3.0.Final</version>
        </dependency>       
        <dependency>
            <groupId>net.sourceforge.dynamicreports</groupId>
            <artifactId>dynamicreports-core</artifactId>
            <version>3.1.3</version>
        </dependency>
    
    1. drools-compiler的 Maven 依赖关系树引入了ecj.jar文件。
    2. 具有jasperreports.jar的dynamicreports-core.jar文件的 Maven 依赖项,后者又引入了jdtcore.jar文件。
    3. <强>解决方案:

      我们升级了引入jasperreports.jar文件的dynamicreports-core版本。

      注意: 阅读http://www.cnblogs.com/xiaoMzjm/p/4566672.html后,我能够解决这个问题。这个博主的信用。

          <dependency>
              <groupId>net.sourceforge.dynamicreports</groupId>
              <artifactId>dynamicreports-core</artifactId>
              <version>4.1.0</version>
          </dependency>