Maven远程资源插件问题

时间:2014-02-13 13:36:28

标签: maven

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

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

<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中。所以,一切看起来都很好,并且符合预期。

现在,另一个,更难,不工作的部分。使用上面指定的共享资源

的模块的pom文件的摘录
<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资源插件)时,它只是将其作为不存在的资源目录跳过。

此外,我试图为resourceBundle添加错误的名称,这给了我一个不存在的即时错误,所以我确定我已经正确指定了resourceBundle。

任何人都可以开导我吗?怎么了?感谢。

修改 添加引用共享资源的pom部分作为依赖

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

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

<?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>

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

EDIT3: 我已经看了一下用于remote-resource.xml的xsd模式,看起来这不应该是空的,而是包含要在进程目标中使用的远程资源的列表。这意味着该文件未正确生成。

EDIT4: 附加执行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设置被设置为默认值

2 个答案:

答案 0 :(得分:10)

我最终设法找到了解决方案。问题实际上是我必须在pom配置中明确指定include以正确生成remote-resources.xml,然后在流程目标中获取remote-resource.xml中列出的所有资源。

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

<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>

附加说明 似乎outputDirectory目标的process没有效果,资源在插件中指定的默认路径上被解压缩。

答案 1 :(得分:1)

查看插件here的文档,我看不到任何明显的错误。

这意味着com.myorganization:myapp-resources:1.0-SNAPSHOT必须以某种方式错误/破坏。

确保您在本地仓库中确实存在此依赖关系。如果您没有,请确保Maven可以从某个地方下载或在本地安装。