java - Maven+Eclipse编译失败,终端上的Maven编译正常

标签 java eclipse maven

我在尝试从 Eclipse Mars (4.5.1) 内部编译 Maven 项目时遇到问题。

规范:

  • Win 7 SP1 x64
  • JDK x64 1.8.0_72
  • eclipse x64 4.5.1
  • maven 3.3.9

我认为这是一个 Eclipse-Maven 插件交互问题,因为我能够从终端执行目标,例如:

mvn clean compile

mvn generate-sources

mvn install

在 Eclipse 中,当我右键单击项目名称并选择 Maven install 作为执行目标时,出现以下错误:

Scanning for projects

...

Building project-name-1.0-SNAPSHOT ...

[WARNING] The POM for com.sun.xml.ws:jaxws-rt:jar:2.2.10 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

[INFO] --- jaxws-maven-plugin:2.3:wsimport (default) @ project-name

[WARNING] The POM for com.sun.xml.ws:jaxws-tools:jar:2.2.10 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

[INFO] Processing: file:/C:/project-name/src/main/resources/file.wsdl [INFO] jaxws:wsimport args: [-keep, -s, C:\project-name\target\generated-sources\wsimport, -d, C:\project-name\target\classes, -encoding, UTF-8, -Xnocompile, "file:/C:/project-name/src/main/resources/file.wsdl"]

[WARNING] Failed to build parent project for com.sun.xml.ws:bundles:pom:2.2.10

[WARNING] Failed to build parent project for com.sun.xml.ws:jaxws-tools:pom:2.2.10

[WARNING] Invalid POM for com.sun.xml.ws:jaxws-tools:jar:2.2.10, transitive dependencies (if any) will not be available, enable debug logging for more details

[INFO] BUILD FAILURE

...

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport (default) on project project-name: Execution default of goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport failed: String index out of range: -1 -> [Help 1]

[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/PluginExecutionException

但是,如果我从终端执行 mvn install,目标就成功了! 我想我在 Eclipse 中安装了所有必要的 Maven 插件并且 pom.xml 文件是正确的,因为通过终端一切似乎都有效。 希望有人能够提示这个问题。

编辑:虽然 mvn install 在 Eclipse 中失败,但如果我在 Eclipse 中创建目标为 mvn install -e 的 Maven Build 配置,则不会发生问题。传递这个标志以某种方式解决了这个问题。

编辑:我粘贴了在 Eclipse 中触发问题的特定 pom.xml 部分(粗体文本是 Eclipse 中红色下划线的内容):

<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>
    <!-- http://maven.apache.org/pom.html#Quick_Overview -->

    <groupId>group.name</groupId>
    <artifactId>project-name</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>${project.artifactId}</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>

        <wsdl.directory>${basedir}/../project-dep/src/main/resources</wsdl.directory>
        <wsdl.filename>file.wsdl</wsdl.filename>

        <mainclass>group.name.subname.TestApplication</mainclass>

        <ws.url>http://localhost:8081/sample-ws/endpoint</ws.url>

        <ws.name>Sample</ws.name>
        <uddi.url>http://localhost:9090</uddi.url>
    </properties>

    <dependencies>
        <!-- JAX-WS -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.2.10</version>
        </dependency>
        <!-- UDDI -->
        <dependency>
            <groupId>group.name.uddi</groupId>
            <artifactId>uddi-naming</artifactId>
            <version>1.0</version>
        </dependency>
        <!-- SOAP Handlers -->
        <dependency>
            <groupId>group.name.soap</groupId>
            <artifactId>ws-handlers</artifactId>
            <version>1.0</version>
        </dependency>
        <!-- JMockit - must appear before JUnit -->
        <dependency>
            <groupId>org.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <version>1.21</version>
            <scope>test</scope>
        </dependency>
        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- https://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html -->
                    <wsdlDirectory>${wsdl.directory}</wsdlDirectory>
                    <wsdlFiles>
                        <wsdlFile>${wsdl.filename}</wsdlFile>
                    </wsdlFiles>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.sun.xml.ws</groupId>
                        <artifactId>jaxws-tools</artifactId>
                        <version>2.2.10</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- to prevent deprecation warning: -->
                    <killAfter>-1</killAfter>
                    <mainClass>${mainclass}</mainClass>
                    <arguments>
                        <argument>${ws.url}</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>1.10</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <programs>
                        <program>
                            <mainClass>${mainclass}</mainClass>
                            <id>${project.artifactId}</id>
                        </program>
                    </programs>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

这是我在 Eclipse 中安装的 Maven:

enter image description here

最佳答案

首先,如果它在控制台中运行良好,那么您就有了一个可以在每个支持 Maven 项目的 IDE 中导入的项目。这是个好消息。

其次,检查所选的 ma​​ven 配置文件(存储库配置,...)在控制台和 Eclipse 中是否相同。

然后您可以在settings.xml(在您的.m2 目录中)检查您的配置

也许之前的回答也有帮助: Maven ignores execution configuration

关于java - Maven+Eclipse编译失败,终端上的Maven编译正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35901501/

相关文章:

java - Jackson2 在服务器上运行时创建错误的日期格式

java - 调用 getClass().getSimpleName() 时在必要的地方留一个空格

java - 如何从数组列表中获取某些信息并分组到Java中的其他列表中

java - 使用 m2eclipse 选择原型(prototype)

java - 在 Eclipse 中保存时生成 javadoc

java - 无法从自定义 Maven Nexus 存储库下载的 jar 导入类

java - 从 itext5 升级到 itext5.2 的问题

Java Jigsaw JUnit 测试 - JUnit 不在模块中

java - 将现有项目导入heroku

java - 如何将 logging.properties 添加到 Eclipse 项目的类路径?