gpt4 book ai didi

Maven远程资源插件问题

转载 作者:行者123 更新时间:2023-12-04 10:51:46 25 4
gpt4 key购买 nike

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

共享资源的 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设置被设置为默认值。

最佳答案

我最终设法找到了解决方案。问题实际上是我必须在 pom 配置中明确指定包含 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目标没有影响,资源在插件中指定的默认路径上解包。

关于Maven远程资源插件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21755839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com