Warm tip: This article is reproduced from serverfault.com, please click

anypoint studio-无法从Project Libraries(jar)中引用Mule 4 dataweave中的DWL脚本文件

(anypoint studio - Unable to reference to DWL script files in Mule 4 dataweave from Project Libraries(jar))

发布于 2020-12-12 11:01:58

我最近在Maven Central Repo中托管了一个ule子应用程序。该应用程序包含两个Java文件和一个dwl文件。dwl文件使用这些java文件执行某些操作。这是我要在另一个应用程序(app2)中作为pom依赖项引用的主要应用程序(app1)。

主数据库的名称是encryption-1.0.5-mule-application.jar

包含的dwl脚本的名称是encryption.dwlJava文件位于jar文件/company包中。

情况1:如果我将此主m子应用程序(app1)打包为jar并将其安装到我的本地.m2存储库中,然后将其作为pom依赖项和另一个辅助m子应用程序的mule-maven-plugin共享库( app2)。app2能够识别dwl脚本,并且在部署后可以正常工作。

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>${mule.maven.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <sharedLibraries>
                        <sharedLibrary>
                            <groupId>com.github.xyz</groupId>
                            <artifactId>encryption</artifactId>
                        </sharedLibrary>
                    </sharedLibraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.github.xyz</groupId>
            <artifactId>encryption</artifactId>
            <version>1.0.5</version>
        </dependency>
    <dependencies>

情况2:如果我将app1依赖项包括在app2 pom.xml文件中,其作用域为<system>,则在其中包含<systemPath =“ jarfilelocation / app1.jar”>并添加共享库,然后将jar添加到根目录中app2的文件夹,并且部署后一切正常。

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>${mule.maven.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <sharedLibraries>
                        <sharedLibrary>
                            <groupId>com.github.xyz</groupId>
                            <artifactId>encryption</artifactId>
                        </sharedLibrary>
                    </sharedLibraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.github.xyz</groupId>
            <artifactId>encryption</artifactId>
            <version>1.0.5</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/encryption-1.0.5-mule-application.jar</systemPath>
        </dependency>
    <dependencies>

情况3:如果我将app1作为依赖项包含在app2 pom.xml中,其作用域为<provided>,并添加一个共享库,则从上游下载jar并将其添加到app2的项目库中。但是app2无法识别Project Libraries中可用的dwl脚本。如果不添加作用域,那么pom会使部署无效,从而导致失败。

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>${mule.maven.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <sharedLibraries>
                        <sharedLibrary>
                            <groupId>com.github.xyz</groupId>
                            <artifactId>encryption</artifactId>
                        </sharedLibrary>
                    </sharedLibraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.github.xyz</groupId>
            <artifactId>encryption</artifactId>
            <version>1.0.5</version>
            <scope>provided</scope>
        </dependency>
    <dependencies>

我的目的是让app2识别出app1的dwl文件以及Studio使用pom依赖关系成功下载jar之后,Studio将它们自动添加到app2的mule包浏览器的项目库(PL)中的所有其他文件。添加。

我已经可以在encryption-1.0.5-mule-application.jarapp2的PL中看到所有可用的app1文件,这些文件是使用pom依赖项获取的。

我仍然无法在app2 ule子XML数据编织中识别出这些文件。我需要帮助弄清楚这一点。

注意:我还使用mule-artifact.json包括了各种组合

{
    "name": "MyApp",
    "minMuleVersion": "4.3.0",
    "classLoaderModelLoaderDescriptor": {
        "id": "mule",
        "attributes": {
            "exportedPackages": [
                "company"
            ],
             "exportedResources": [
                "encryption/encryption.dwl",
                "encryption.dwl",
                "*/encryption.dwl",
                "company/encryption.dwl"
            ]
        }
    }
}
Questioner
Thinker-101
Viewed
0
Thinker-101 2020-12-14 19:49:05

我已经解决了这个问题。

起初,我认为这<scope>provided</scope>是导致问题的原因。我没有完全理解范围的概念。我也尝试过<classifier>mule-application<classifier>分类器不能属于上述类型是没有道理的mule-application当我尝试与分类器一起使用mule-plugin并重命名以前下载的本地存储库jar并在Studio中重新部署我的mule应用程序时,就知道这一点

实际上,问题出在我发布给OSSRH的jar的名称上。打包一个值为的罐子是无效的mule-application像这样<packaging>mule-application</packaging>

后来,我发布了发布的版本,其中的pom.xml更改<packaging></packaging>jar我也删除了,mule-maven-plugin因为它不允许使用type包装jar注意:这是App1。

在向上游发布后,我只是在App2中引用了App1生成的Nexus依赖关系,并且运行良好。

现在,也无需像下面在App2中那样传递共享库依赖关系。另外,你不需要向中添加任何内容mule-artifact.json

            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>${mule.maven.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <sharedLibraries>
                        <sharedLibrary>
                            <groupId>com.github.xyz</groupId>
                            <artifactId>encryption</artifactId>
                        </sharedLibrary>
                    </sharedLibraries>
                </configuration>
            </plugin>