Maven远程资源插件问题 [英] Maven remote resource plugin issue

查看:76
本文介绍了Maven远程资源插件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道关于此主题还有很多其他问题,我已经搜索并阅读了所有这些问题,但到目前为止还没有帮助.

I know there are many other question in regards to this topic, I've searched and read them all but even that haven't helped so far.

共享资源的pom看起来像这样

The pom for shared-resources looks like this

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.myorganization</groupId>
        <artifactId>myapp</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>myapp-resources</artifactId>
    <name>Resources Bundle</name>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>      
    </build>
</project>

它基本上说:拾取资源目录中的所有内容,并且确实做到了,所有资源最终都位于jar文件的根目录中.将remote-resources.xml也放置在META-INF/manifest目录下的jar中.因此,一切似乎都很好,并且符合预期.

It basically says: pick up everything you have in the resource directory, and it really does that, all the resources end up in the root of jar file. with the remote-resources.xml also placed within jar under META-INF/manifest directory. So, everything seems just fine and according to expectations.

现在,另一个更困难,不起作用.使用上面指定的共享资源的模块pom文件摘录

Now, the other, harder, not working part. The excerpt of pom file for the module using the shared resources specified above

<plugin>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <id>process-remote-resources</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <resourceBundles>
                                <resourceBundle>com.myorganization:myapp-resources:1.0-SNAPSHOT</resourceBundle>
                            </resourceBundles>
                            <outputdirectory>${project.build.directory}/shared-resources</outputdirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

因此,它说的是,处理来自resourceBundle的资源并将其放入shared-resources目录中.但是,什么也没有发生.当我尝试执行mvn remote-resources:process时,出现错误消息,提示resourceBundles的参数丢失或无效.如果我运行mvn install并没有错误,但是当我尝试从shared-resources目录复制(Maven资源插件)任何内容时,它只会跳过不存在的资源目录.

So, here it says, process the resources from resourceBundle and put them in the shared-resources directory. But, nothing happens. And when I try to execute mvn remote-resources:process I got the error message saying that parameters for resourceBundles are missing or invalid. If I run mvn install there's no error, but when I try to copy (maven resources plugin) anything from shared-resources directory it just skips that as non-existing resource directory.

另外,我尝试为resourceBundle输入错误的名称,这给了我一个即时错误,提示它不存在,所以我确定我正确地指定了resourceBundle.

Additionally, I tried to put the wrong name for resourceBundle and that gave me an instant error that it does not exist, so I'm sure I have specified resourceBundle correctly.

有人可以启发我吗?怎么了?谢谢.

Can anyone enlighten me? What am doing wrong? Thanks.

添加pom将共享资源引用为依赖的部分

Adding the part of the pom referencing shared-resources as dependecy

<dependency>
            <groupId>com.myorganization</groupId>
            <artifactId>myapp-resources</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

添加共享资源jar中包含的remote-resources.xml的内容:

Adding the content of remote-resources.xml contained within shared resources jar:

<?xml version="1.0" encoding="UTF-8"?>
<remoteResourcesBundle xsi:schemaLocation="http://maven.apache.org/remote-resources/1.1.0 http://maven.apache.org/xsd/remote-resources-1.1.0.xsd"
    xmlns="http://maven.apache.org/remote-resources/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <sourceEncoding>UTF-8</sourceEncoding>
</remoteResourcesBundle>

这应该是空的吗(除了源编码设置)?

Should this one be empty like that (with except of source encoding settings)?

我看过用于remote-resource.xml的xsd模式,看来这不应该为空,而应包含要在过程目标中使用的远程资源的列表.这意味着该文件无法正确生成.

I've taken a look at the xsd schema used for remote-resource.xml and it seems this should not be empty but contain the list of the remote resources to be used in the process goal. That would mean that this file is not generated properly.

附加执行mvn remote-resources:process时抛出的错误:

Attaching the error thrown when executing mvn remote-resources:process:

The parameters 'resourceBundles' for goal org.apache.maven.plugins:maven-remote-resources-plugin:1.5:process are missing or invalid -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-remote-resources-plugin:1.5:process (default-cli) on project lte-troubleshoting-solution: The parameters 'resourceBundles' for goal org.apache.maven.plugins:maven-remote-resources-plugin:1.5:process are missing or invalid
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:220)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'resourceBundles' for goal org.apache.maven.plugins:maven-remote-resources-plugin:1.5:process are missing or invalid
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:581)
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:534)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:97)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 19 more

而且有趣的是,似乎完全没有选择插件配置中的outputDirectory设置,因为在调试日志中,我可以看到outputDirectory设置被设置为默认值.

And what is also interesting, it seems that the outputDirectory setting in the plugin configuration is not picked up at all since in the debug log I can see that the outputDirectory setting is set to default value.

推荐答案

我最终找到了解决方案.问题实际上是我必须在pom配置中明确指定include,以正确生成remote-resources.xml,并在稍后的处理目标中选择要获取remote-resource.xml中列出的所有资源.

I managed to find a solution in the end. The problem was in fact that I had to explicitly specify includes in the pom configuration to have remote-resources.xml generated properly and later in the process goal to pick up all the resource listed in the remote-resource.xml.

因此,共享资源模块的最终pom应该如下所示(如果您想包含所有内容):

So, the final pom for shared-resources module should look like this (if you want to include everything):

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.myorganization</groupId>
        <artifactId>myapp</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>myapp-resources</artifactId>
    <name>Resources Bundle</name>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>      
    </build>
</project>

附加说明 看来process目标的outputDirectory没有任何效果,资源已在插件中指定的默认路径上解包.

Additional note It seems that outputDirectory for process goal has no effects, resources are unpackaged on the default path specified in the plugin.

这篇关于Maven远程资源插件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆