您如何在类路径中加入一个罐子,以便Maven识别它而不按POM中的名称指定罐子?

发布于 2025-02-06 10:17:50 字数 800 浏览 1 评论 0原文

我正在使用专有的Maven插件,该插件为在第三方应用程序中创建的工件生成连接代码。专有插件需要在POM文件中进行不同的设置,具体取决于其生成代码的工件。我正在尝试做到这一点,因此我的Java应用程序不需要在部署和部署以这种方式部署和部署的POM中更改代码,我可以在测试中使用相同的JAR和产品部署。问题是连接工件,因此该插件的POM代码在测试和产品之间会有所不同。

我在工作中拥有的解决方案是运行用于测试的代码生成插件,并分别为产品运行,然后jar生成的代码,并使用脚本在类路径中包含正确的生成的代码jar,具体取决于Java应用程序JAR正在部署哪个环境到。

我能够jar生成的库,并将jar包含在classpath中,这使eclipse对依赖关系感到满意,但是当我尝试运行“ MVN编译”并为我的Java应用程序生成Jar java应用程序Maven时,Maven并没有识别生成的代码罐子我添加到了类路径上,该类路径可防止弹簧启动 - 马文 - plugin创建我的应用程序罐。

到目前为止,我到目前为止看到的所有解决方案都识别罐子似乎涉及在POM中指定罐子的名称,因为测试和生成的代码罐的名称会有所不同(例如,generated_test, 。

有没有办法让Maven在类路径上包括任何罐子,而不必按POM中的名称指定罐子?

编辑: 这可能最终比我想象的要容易。我使用Eclipse将生成的代码导出到JAR,然后最终将Jar从生成的Jar重命名为生成的test.jar。我在Eclipse的class Path中添加了生成的test.jar,并试图运行“ MVN编译”,但罐子没有被识别。当我尝试将jar的名称更改回生成。我不确定为什么两次都将适当的名称放在class路径中时,为什么更改罐子的名称有所作为。

I am working with a proprietary maven plugin that generates connection code for artifacts created in a third party application. The proprietary plugin requires different settings in the POM file depending on the artifact it is generating the code for. I am attempting to make it so my Java application doesn't require a code change in the POM between deploying to TEST and deploying to PROD that way I can use the same jar for my application in the TEST and the PROD deployment. The issue is the connection artifacts and thus the POM code for the plugin will be different between TEST and PROD.

The solution I have in the works is to run the code generating plugin for TEST and for PROD separately then jar the generated code and use a script to include the correct generated code jar in the classpath depending on which environment the Java application jar is being deployed to.

I was able to jar the generated libraries and include the jar in the classpath which makes Eclipse happy with the dependencies, but when I attempt to run a "mvn compile" and generate the Jar for my Java application Maven isn't recognizing the generated code jar I added to the classpath which prevents the spring-boot-maven-plugin from creating my application jar.

All the solutions I have seen so far for getting maven to recognize a jar seem to involve specifying the name of the jar in the POM which I wanted to avoid since the names of the TEST and PROD generated code jars will be different (ex. generated_TEST.jar, generated_PROD.jar) and the whole point of this is to not modify any code between the TEST and PROD deployments so I can use the same Java application jar in both TEST and PROD.

Is there a way to get maven to include any jars on the classpath without having to specify the jar by name in the POM?

EDIT:
This might end up being easier than I thought. I used Eclipse to export the generated code to a jar, then I ended up renaming the jar from Generated.jar to Generated-TEST.jar. I added Generated-TEST.jar to the classpath in Eclipse and tried to run "mvn compile" but the jar was not recognized. When I tried changing the name of the jar back to Generated.jar and added it to the classpath I was able to run "mvn compile" successfully. I am not sure why changing the name of the jar made a difference as I put the appropriate name in the classpath both times.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文