Maven 为 Munits 构建 - Mule

Posted

技术标签:

【中文标题】Maven 为 Munits 构建 - Mule【英文标题】:Maven build for Munits - Mule 【发布时间】:2017-03-25 07:25:06 【问题描述】:

我正在为构建包含 munit 的 mule 应用程序准备 maven。当我“mvn package”应用程序时出现以下错误。

警告 2016-11-11 09:35:32,415 [主要] org.springframework.beans.factory.xml.XmlBeanDefinitionReader:忽略 XML 验证警告 org.xml.sax.SAXParseException: schema_reference.4:无法读取架构文档 'http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd',因为 1) 找不到文件; 2) 文件无法读取; 3) 文档的根元素不是。在 org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(未知 来源)~[xercesImpl-2.8.0.jar:?] at org.apache.xerces.util.ErrorHandlerWrapper.warning(未知来源) ~[xercesImpl-2.8.0.jar:?]

[ERROR] 未能执行目标 com.mulesoft.munit.tools:munit-maven-plugin:1.2.1:test (test) on project api-system-plm-material:目标的执行测试 com.mulesoft.munit.tools:munit-maven-plugin:1.2.1:test failed: org.mule.api.config.ConfigurationException:XML 文档中的第 19 行 来自网址 [file:/D:/Mule-Workspace-28thOct/myapplication/target/test-classes/myapplication_flow1.xml] 是无效的;嵌套异常是 org.xml.sax.SAXParseException; 行号:19;列号:105; cvc-complex-type.2.4.a:无效 发现以元素“ws:consumer-config”开头的内容。之一 '"http://www.mulesoft.org/schema/mule/core":注解, “http://www.mulesoft.org/schema/mule/core”:描述, “http://www.springframework.org/schema/beans”:豆子, “http://www.springframework.org/schema/beans”:豆, “http://www.springframework.org/schema/context”:属性占位符, "http://www.springframework.org/schema/beans":ref, "http://www.mulesoft.org/schema/mule/core":global-property, “http://www.mulesoft.org/schema/mule/core”:配置, “http://www.mulesoft.org/schema/mule/core”:通知, “http://www.mulesoft.org/schema/mule/core”:抽象扩展, "http://www.mulesoft.org/schema/mule/core":abstract-shared-extension, “http://www.mulesoft.org/schema/mule/core”:抽象混合内容扩展, “http://www.mulesoft.org/schema/mule/core”:抽象代理, "http://www.mulesoft.org/schema/mule/core":abstract-security-manager, "http://www.mulesoft.org/schema/mule/core":abstract-transaction-manager, "http://www.mulesoft.org/schema/mule/core":abstract-shared-transaction-manager, “http://www.mulesoft.org/schema/mule/core”:抽象连接器, “http://www.mulesoft.org/schema/mule/core”:抽象共享连接器, "http://www.mulesoft.org/schema/mule/core":abstract-global-endpoint, “http://www.mulesoft.org/schema/mule/core”:抽象异常策略, “http://www.mulesoft.org/schema/mule/core”:抽象流构造, “http://www.mulesoft.org/schema/mule/core”:流, "http://www.mulesoft.org/schema/mule/core":子流, “http://www.mulesoft.org/schema/mule/core”:抽象模型, “http://www.mulesoft.org/schema/mule/core”:抽象拦截器堆栈, “http://www.mulesoft.org/schema/mule/core”:抽象过滤器, “http://www.mulesoft.org/schema/mule/core”:抽象变压器, “http://www.mulesoft.org/schema/mule/core”:处理器链, “http://www.mulesoft.org/schema/mule/core”:定制处理器, “http://www.mulesoft.org/schema/mule/core”:抽象空处理器, “http://www.mulesoft.org/schema/mule/core”:调用, "http://www.mulesoft.org/schema/mule/core":set-payload, "http://www.mulesoft.org/schema/mule/core":abstract-global-intercepting-message-processor, "http://www.mulesoft.org/schema/mule/core":custom-queue-store, "http://www.mulesoft.org/schema/mule/core":abstract-processing-strategy' 是期待。 (org.mule.api.lifecycle.InitialisationException) -> [帮助 1] org.apache.maven.lifecycle.LifecycleExecutionException: 失败 执行目标 com.mulesoft.munit.tools:munit-maven-plugin:1.2.1:test (test) on project api-system-plm-material:目标的执行测试 com.mulesoft.munit.tools:munit-maven-plugin:1.2.1:test failed: org.mule.api.config.ConfigurationException:XML 文档中的第 19 行 来自网址 [file:/D:/Mule-Workspace-28thOct/myapplication/target/test-classes/myapplication_flow1.xml] 是无效的;嵌套异常是 org.xml.sax.SAXParseException; 行号:19;列号:105; cvc-complex-type.2.4.a:无效 发现以元素“ws:consumer-config”开头的内容。之一 '"http://www.mulesoft.org/schema/mule/core":注解, “http://www.mulesoft.org/schema/mule/core”:描述, “http://www.springframework.org/schema/beans”:豆子, "http://www.springframework.org/schema/beans":bean, "http://www.springframework.org/schema/context":property-placeholder, "http://www.springframework.org/schema/beans":ref, "http://www.mulesoft.org/schema/mule/core":global-property, “http://www.mulesoft.org/schema/mule/core”:配置, "http://www.mulesoft.org/schema/mule/core":通知, “http://www.mulesoft.org/schema/mule/core”:抽象扩展, "http://www.mulesoft.org/schema/mule/core":abstract-shared-extension, “http://www.mulesoft.org/schema/mule/core”:抽象混合内容扩展, “http://www.mulesoft.org/schema/mule/core”:抽象代理, "http://www.mulesoft.org/schema/mule/core":abstract-security-manager, "http://www.mulesoft.org/schema/mule/core":abstract-transaction-manager, "http://www.mulesoft.org/schema/mule/core":abstract-shared-transaction-manager, “http://www.mulesoft.org/schema/mule/core”:抽象连接器, “http://www.mulesoft.org/schema/mule/core”:抽象共享连接器, "http://www.mulesoft.org/schema/mule/core":abstract-global-endpoint, “http://www.mulesoft.org/schema/mule/core”:抽象异常策略, “http://www.mulesoft.org/schema/mule/core”:抽象流构造, “http://www.mulesoft.org/schema/mule/core”:流, "http://www.mulesoft.org/schema/mule/core":子流, “http://www.mulesoft.org/schema/mule/core”:抽象模型, "http://www.mulesoft.org/schema/mule/core":abstract-interceptor-stack, “http://www.mulesoft.org/schema/mule/core”:抽象过滤器, “http://www.mulesoft.org/schema/mule/core”:抽象变压器, “http://www.mulesoft.org/schema/mule/core”:处理器链, “http://www.mulesoft.org/schema/mule/core”:定制处理器, “http://www.mulesoft.org/schema/mule/core”:抽象空处理器, “http://www.mulesoft.org/schema/mule/core”:调用, "http://www.mulesoft.org/schema/mule/core":set-payload, "http://www.mulesoft.org/schema/mule/core":abstract-global-intercepting-message-processor, "http://www.mulesoft.org/schema/mule/core":custom-queue-store, "http://www.mulesoft.org/schema/mule/core":abstract-processing-strategy' 是期待。 (org.mule.api.lifecycle.InitialisationException) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)

它所指的流xml是:

http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

<ws:consumer-config name="Web_Service_Consumer" service="Mat_RFCService" port="MAT_RFC" 
  serviceAddress="$service.address" 
  wsdlLocation="MAT_WSDL.wsdl" doc:name="Web Service Consumer" connectorConfig="MAT-HTTP-Endpoint"/>

下面是我的 pom.xml:

<modelVersion>4.0.0</modelVersion>
 <groupId>com.mycompany</groupId>
 <artifactId>myapplication</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <packaging>mule</packaging>
 <name>Mule myapplication Application</name>
 <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <mule.version>3.8.1</mule.version>
     <mule.tools.version>1.2</mule.tools.version>
     <munit.version>1.2.1</munit.version>
     <mule.munit.support.version>3.8.0</mule.munit.support.version>
     <!-- This is the domain where the app will be 
     deployed: i.e. mydomain.cloudhub.io -->
     <cloudhub.domain>mydomain</cloudhub.domain>
 </properties>
 <build>
     <plugins>
     <plugin>
       <groupId>org.mule.tools.maven</groupId>
       <artifactId>mule-maven-plugin</artifactId>
       <version>2.1.1</version>
       <!-- <configuration>
             <deploymentType>standalone</deploymentType>
             <muleVersion>$mule.version</muleVersion>
         </configuration> -->
         <configuration>
             <deploymentType>cloudhub</deploymentType>
             <muleVersion>3.8.2</muleVersion>
             <username>username</username>
             <password>mypassword</password>
              <applicationName>myapplication-maven-1.0</applicationName>
              <!-- <businessGroup>engineering\devops</businessGroup> -->
             <target>CloudHub</target>
             <!-- One of: server, serverGroup, cluster -->
             <domain>$cloudhub.domain</domain>
             <targetType>server</targetType>
             <environment>DEVELOPMENT</environment>
         </configuration>
         <executions>
             <execution>
                 <id>deploy</id>
                 <phase>deploy</phase>
                 <goals>
                     <goal>deploy</goal>
                 </goals>
             </execution>
         </executions>
     </plugin>
        <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-app-maven-plugin</artifactId>
                <version>$mule.tools.version</version>
                <extensions>true</extensions>
                <configuration>
                    <copyToAppsDirectory>true</copyToAppsDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>add-resource</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>src/main/app/</directory>
                                </resource>
                                <resource>
                                    <directory>mappings/</directory>
                                </resource>
                            <resource>
                                    <directory>src/main/api/</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.mule.tools</groupId>
                <artifactId>maven-mule-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <excludeMuleDependencies>false</excludeMuleDependencies>
                    <inclusions>
                        <inclusion>
                            <groupId>org.mule.modules</groupId>
                            <artifactId>mule-module-objectstore</artifactId>
                        </inclusion>
                    </inclusions>
                </configuration>
            </plugin>
        <plugin>
                <groupId>com.mulesoft.munit.tools</groupId>
                <artifactId>munit-maven-plugin</artifactId>
                <version>$munit.version</version>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <coverage>
                        <runCoverage>true</runCoverage>
                        <formats>
                            <format>html</format>
                        </formats>
                    </coverage>
                </configuration>
            </plugin>
        </plugins>
        <testResources>
            <testResource>
                <directory>src/test/munit</directory>
            </testResource>
        <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
    </build>

    <!-- Mule Dependencies -->
    <dependencies>
        <!-- Xml configuration -->
        <dependency>
            <groupId>com.mulesoft.muleesb</groupId>
            <artifactId>mule-core-ee</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <!-- Xml configuration -->
        <dependency>
            <groupId>com.mulesoft.muleesb.modules</groupId>
            <artifactId>mule-module-spring-config-ee</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <!-- Mule Transports -->
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-file</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-http</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.muleesb.transports</groupId>
            <artifactId>mule-transport-jdbc-ee</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.muleesb.transports</groupId>
            <artifactId>mule-transport-jms-ee</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-vm</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <!-- Mule Modules -->
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-scripting</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-xml</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
        <!-- for testing -->
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-functional</artifactId>
            <version>$mule.version</version>
            <scope>test</scope>
        </dependency>
    <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-apikit</artifactId>
            <version>$mule.version</version>
            <scope>provided</scope>
        </dependency>
    <dependency>
            <groupId>com.mulesoft.munit</groupId>
            <artifactId>mule-munit-support</artifactId>
            <version>$mule.munit.support.version</version>
            <scope>test</scope>
        </dependency>
    <dependency>
            <groupId>com.mulesoft.munit</groupId>
            <artifactId>munit-runner</artifactId>
            <version>$munit.version</version>
            <scope>test</scope>
        </dependency>
    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-objectstore</artifactId>
        <version>1.3.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mule.modules/mule-module-spring-extras -->
    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-spring-extras</artifactId>
        <version>3.8.1</version>
    </dependency>

    </dependencies>

    <repositories>
          <repository>
            <id>Central</id>
            <name>Central</name>
            <url>http://repo1.maven.org/maven2/</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>http://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>mulesoft-release</id>
            <name>mulesoft release repository</name>
            <layout>default</layout>
            <url>http://repository.mulesoft.org/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

任何线索都会有很大帮助。

编辑:

按照 Dds 的指示添加依赖项后,我现在遇到以下错误: [ERROR] Failed to execute goal com.mulesoft.munit.tools:munit-maven-plugin:1.2.1:test (test) on project myapplication: Execution test of goal com.mulesoft.munit.tools:munit-maven-plugin:1.2.1:test failed: org.mule.api.config.ConfigurationException: Configuration problem: Failed to import bean definitions from URL location [classpath:myapplication-get-id.xml] [ERROR] Offending resource: URL [file:/D:/RamG/Eclipses/Workspaces/Mule-Workspace-28thOct/myapplication/target/test-classes/myapplication-apikit-test.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [myapplication-get-id.xml]; nested exception is org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [com.mulesoft.weave.mule.config.WeaveNamespaceHandler] for namespace [http://www.mulesoft.org/schema/mule/ee/dw]: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError: scala/Option (org.mule.api.lifecycle.InitialisationException): scala.Option [ERROR] -> [Help 1] 当我浏览信息时,我看到又发布了一个 SO 问题但没有得到回答。它指的是 dataweave + scala/Option 这与我得到的错误相同。

由于某种原因,这个 dataweave 组件没有被完全下载,尤其是 jar 文件没有被下载。经过一些练习,我下载并复制到相应的 .m2 文件夹手动。但之后我看到了上述错误。所以,它要么有一些像“scala/Option”这样没有解决的依赖项!!我不确定。

谢谢

【问题讨论】:

【参考方案1】:

您好,从 Maven 运行时出现这些错误通常表明您的 pom 文件中缺少依赖项。

包含 Web 服务使用者的应该是:

<dependency>
  <groupId>org.mule.modules</groupId>
  <artifactId>mule-module-ws</artifactId>
  <version>$mule.version</version>
  <scope>provided</scope>
</dependency>

请将那个添加到您的 pom 中并试一试。 高温

【讨论】:

这对我很有帮助。我将标记为已回答。该问题继续出现另一个错误:[DEBUG] BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext。你能告诉我这个依赖或问题指的是什么吗?谢谢 这看起来不像缺少依赖项,而是像 mule app/munit 测试配置文件的问题。我真的不知道只有那个堆栈跟踪。我会建议您打开另一个问题并尝试确定问题的范围。可能是您正在部分加载您的应用程序(在 spring 导入中)并且可能缺少某些内容

以上是关于Maven 为 Munits 构建 - Mule的主要内容,如果未能解决你的问题,请参考以下文章

1-1 maven 学习笔记构

Ant 到 Maven - 多个构建目标

无法使用 Jenkins 管道在本地部署 mule 4 应用程序

xcode maven插件无法构建库

通过 Mule 4 发送电子邮件时 JSON 数组到表结构格式

Maven 教程