Maven项目多次在同一台计算机上运行
首先,我必须说我是一个菜鸟,所以我可能会写一些非常错误的东西,为此我感到抱歉。
我有一个由Maven 3.6.1制成的Spring Boot(2.5.3)项目,其中(继承)项目结构:
root (parent pom)
+-- api
+-- common
+-- import
api
和import
模块都有两个依赖性common
模块。
api
和导入
模块实际上是完全独立的。公共模块具有两个模块使用的类。
这些模块由CMD通过使用MVN Spring-boot运行。
现在解决问题。在某个时候,对两个模块的独立版本进行了要求。这是因为一个模块中的代码更改需要在另一个项目中进行不必要的重建。示例:import
的重建也意味着api
的重建,这又会导致api
服务interruption。
为了解决问题,我继续使用同一项目(从GIT拉出)制作两个单独的文件夹,然后构建(MVN Clean Clean install
)并运行(MVN Spring-boot:Run )每个文件夹分离。
因此,更清楚我要做什么:
folder1
"mvn clean install" at project root
"mvn spring-boot:run" only for "api" module
folder2
"mvn clean install" at project root
"mvn spring-boot:run" only for "import" module
它似乎有效,但这是一个错误的结论。对于common
模块中的一个运行模块中的类中的类,似乎是随机的,noclassdeffounderror异常,但不是另一个模块。
我注意到查看日志的内容,我可能非常错误,是在某个时候将公共模块打包到一个罐子中并复制到本地的Maven存储库中(〜/.m2/存储库)。我未经教育的猜测是,在同一项目的单独文件夹中两次运行MVN Clean slistion>以某种方式使位于本地存储库中的公共JAR无法使用或略微损坏另一个项目。
我试图了解正在发生的事情,主要是为什么,因为我的假设是蜂蜜单独的文件夹,它们不应该彼此相互作用,这是事实证明是错误的。
我必须采用哪种解决方案来实现该项目模块的独立构建?另外,当我尝试在同一台机器上运行不同配置文件时,也会发生相同的NoclassDeffoundError异常。
预先感谢您。
First of all, I must say that I am a noob when it comes to Maven, so I may write some terribly wrong things and I am sorry for that.
I have a Spring Boot (2.5.3) project made with Maven 3.6.1, with the following (inherited) project structure:
root (parent pom)
+-- api
+-- common
+-- import
The api
and the import
modules have both a dependency on common
module.
The api
and import
modules are, in fact, totally independent one to another. The common module has classes used by both modules.
The modules are run by cmd by using mvn spring-boot:run
on each module (except common, of course) and are build with a mvn clean install
in the project's folder.
Now to the problem. At some point, a requirement of independent builds of the two modules was made. This was decided because code changes in one module would require an unnecessary rebuild in the other project. Example: a rebuild of the import
would mean also a rebuild of api
which in turn would lead to an api
service intrerruption.
To solve the issue, I proceeded to make two separate folders with the same project (pulled from Git) and then build (mvn clean install
) and run (mvn spring-boot:run
) each folder separateley.
So to be more clear what I do:
folder1
"mvn clean install" at project root
"mvn spring-boot:run" only for "api" module
folder2
"mvn clean install" at project root
"mvn spring-boot:run" only for "import" module
It seemed to work, but it's a false conclusion. Seemingly random, NoClassDefFoundError exceptions are thrown for classes that are in common
module for one of the running module, but not for the other.
What I've noticed looking at logs, and I may have be very wrong, is that at some point the common module is packaged into a jar and copied into local Maven repository (~/.m2/repository). My uneducated guess is it that running mvn clean install
two times in separate folders for the same project somehow make the common jar located in local repository unusable or slightly corrupted for the other project.
I am trying to understand what is happening and mostly why, because my assumption was that beeing separate folders, they shouldn't interact with each other, an assumption that turned out wrong.
What solution do I have to achieve independent builds for the project's modules? Also, the same NoClassDefFoundError exception occured when I've tried to run on the same machine the same project with different profiles.
A big thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论