我知道关于这个话题有很多其他的问题,我已经搜索并阅读了它们,但到目前为止甚至那些也没有帮助。
shared-resources的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。
有人能给我指点迷津吗?我做错了什么?谢谢。
编辑:添加引用shared-resources作为依赖项的pom部分。
<dependency>
<groupId>com.myorganization</groupId>
<artifactId>myapp-resources</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
编辑2: 添加了共享资源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>
这个应该是空的吗(除了源编码设置)?
编辑3:
我查看了用于remote-resource.xml
的xsd模式,似乎这个应该不为空,而应该包含要在过程目标中使用的远程资源列表。这意味着这个文件没有正确生成。
编辑4:
执行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
设置为默认值。