创建 Maven 项目时出错

Error Creating a Maven Project

我正在尝试按照本教程创建一个 Maven 项目 https://docs.mulesoft.com/mule-user-guide/v/3.7/building-a-mule-application-with-maven-in-studio 那次当 Studio 自动构建 Maven 项目时,我收到此错误:updating maven project has encountered a problem There was an error running the studio:studio goal on project test 并且在控制台中:

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.mycompany:test:1.0.0-SNAPSHOT (C:\Users\Rajeun\AnypointStudio\workspace\test\pom.xml) has 2 errors
[ERROR]     Unresolveable build extension: Plugin org.mule.tools.maven:mule-app-maven-plugin:1.1 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:1.5.0 at specified path C:\Program Files (x86)\Java\jre1.8.0_40/../lib/tools.jar -> [Help 2]
[ERROR]     Unknown packaging: mule @ line 8, column 16
[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/PluginManagerException

检查您的 MuleStudio.ini 是否包含您 JDK:

的正确路径的配置
-vm
C:\Path\To\Your\JDK\bin\javaw

我认为这是您的 mule studio Java 设置的问题。 Mule studio 默认点 JRE 而不是 JDK。 tools.jar 在 JDK 文件夹下可用。请参阅下面的 link,它告诉您如何将 JDK 添加到工作室,然后使用它来构建

http://www.gamefromscratch.com/post/2011/11/15/Telling-Eclipse-to-use-the-JDK-instead-of-JRE.aspx

在您的 Anypoint 工作室中,转到 windows >> 首选项 >> 左侧菜单 select java >> 安装的 jre将其更改为 jdk 路径

我解决了这个问题,我不知道究竟是什么起作用了,但我更改了 java 版本,并且对于每个项目,我都执行以下命令:

mvn clean install
mvn eclipse:eclipse

然后我刷新我的项目 这可以帮助:http://www.avajava.com/tutorials/lessons/how-do-i-update-my-maven-project-to-work-in-eclipse.html

您需要为插件添加 Maven 依赖

第 1 步:编辑 settings.xml 添加具有以下存储库和 pluginRepositories 的新配置文件。 (settings.xml 文件可能存在两个位置:$M2_HOME/conf/settings.xml 或 ${user.home}/.m2/settings.xml )

<profiles>
     ...
     <profile>
        <id>mule-extra-repos</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>mule-public</id>
                <url> https://repository.mulesoft.org/nexus/content/repositories/public </url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>mule-public</id>
                <url> https://repository.mulesoft.org/nexus/content/repositories/public </url>
            </pluginRepository>
        </pluginRepositories>
     </profile>
     ...
 </profiles>

第二步:添加一个新的pluginGroup,如下图。

<pluginGroups>
    ...
    <pluginGroup>org.mule.tools</pluginGroup>
    ...
 </pluginGroups>

更多详情,您可以访问此页面https://docs.mulesoft.com/mule-user-guide/v/3.7/maven-tools-for-mule-esb

我注意到,如果您的流程涉及 API Kit 和 Dataweave,则需要添加额外的依赖项。

        <plugin>
            <executions>
                <execution>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>src/main/api/</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-apikit</artifactId>
        <version>${mule.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.mulesoft.weave</groupId>
        <artifactId>mule-plugin-weave_2.11</artifactId>
        <version>${mule.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-http</artifactId>
        <version>${mule.version}</version>
        <scope>provided</scope>
    </dependency>

我遇到了同样的错误,我通过在已安装的 JRE 中添加 JDK 并将 JAVASE-1.8 的执行环境设置为 jdk1.8 来解决它并且它起作用了。 enter image description here

我遇到了同样的问题,通过在首选项中将 JRE 更改为 JDK 并重新启动任意点工作室来解决。 这解决了我的问题。

如果您在使用 Maven 构建项目时遇到来自 Anypoint studio 的以下错误。

[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unresolveable build extension: Plugin org.mule.tools.maven:mule-app-maven-plugin:1.2 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:1.5.0 at specified path C:\Program Files\Java\jre1.8.0_162/../lib/tools.jar @ 
[ERROR] Unknown packaging: mule @ line 9, column 16
[WARNING] 'dependencies.dependency.systemPath' for com.sun:tools:jar refers to a non-existing file C:\Program Files\Java\jre1.8.0_162C:\Program Files\Java\jdk1.8.0_162\lib\tools.jar @ line 75, column 21
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.mycompany:maven-test1:1.0.0-SNAPSHOT (C:\Users\Venkata Phanindra\AnypointStudio\workspace\maven-test1\pom.xml) has 2 errors
[ERROR]     Unresolveable build extension: Plugin org.mule.tools.maven:mule-app-maven-plugin:1.2 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:1.5.0 at specified path C:\Program Files\Java\jre1.8.0_162/../lib/tools.jar -> [Help 2]
[ERROR]     Unknown packaging: mule @ line 9, column 16
[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/PluginManagerException

请按照以下步骤解决问题

  1. 从 Anypoint studio 转到 Windows -> 首选项 -> 安装的 JRE。
  2. 这里把JRE (C:\Program Files\Java\jre1.8.0_162)改成你的JDK (C:\Program Files\Java\jdk1.8.0_162) 和 select JDK 复选框并单击完成 -> 确定 -> 确定。

现在尝试通过右键单击 pom.xml 文件 Mule -> 更新项目依赖项来更新 pom.xml 文件。

如果问题仍然存在,请按照以下步骤进行操作:

  1. 转到 Windows -> 首选项 -> 安装的 JRE -> 执行环境 这里selectJavaSE-1.8和右边window点击jdk1.8.0_162[绝配] 现在尝试更新项目依赖项。

这将解决问题。