使用Maven处理大型Java Server项目

时间:2022-09-26 23:48:59

I have never worked before with Java Server development, and i need to build a large Server project with around 10 libraries.

我之前从未使用过Java Server开发,我需要构建一个包含大约10个库的大型Server项目。

The project already uses Maven for building. I have setup the building process, and now i came to development part. (need to change a small part of the code)

该项目已经使用Maven进行建设。我已经设置了构建过程,现在我来到了开发部分。 (需要更改一小部分代码)

Question
I am used to 5 - 10 seconds building (without rebuilding the whole project). How can i achieve that with maven?
Use case: Write a line of code and test it.

问题我习惯了5到10秒的建设(没有重建整个项目)。我怎样才能与maven实现这一目标?使用案例:编写一行代码并对其进行测试。

If there is no way to do it with maven, can i do it other way? Otherwise it is a big pain to wait 3 - 5 minutes every time i need to test the code.

如果没有办法用maven做,我可以用其他方式吗?否则每次我需要测试代码时等待3到5分钟是一件很痛苦的事。

Edit:
There is more than hundred linked libraries (jar), but there is around 10 projects in workspace with dependencies. mvn install takes about 5 minutes or more. There is several thousands .java files in the project and tons of resources

编辑:有超过一百个链接库(jar),但工作区中有大约10个项目具有依赖项。 mvn install大约需要5分钟或更长时间。项目中有数千个.java文件和大量资源

6 个解决方案

#1


1  

Tools for Hot Deployment like JRebel are able to do it without restarting the server. Otherwise you'll need to restart it, with no problem for 10 libraries I think.

像JRebel这样的热部署工具可以在不重新启动服务器的情况下完成。否则你需要重新启动它,我认为10个库没有问题。

I usually work with 7 or 8 and you only have to wait while the server restarts, cause the deploy is automatically managed with Eclipse+m2e-wtp. If you have the project divided in multiple modules this plugin takes care about compiling only what you want and deploying it.

我通常使用7或8,您只需等待服务器重新启动,因为部署是使用Eclipse + m2e-wtp自动管理的。如果您将项目划分为多个模块,则此插件只会编译您想要的内容并进行部署。

#2


1  

The most effective way is not rely on Maven locally, but to have you covered by the continuous integration server instead: Run only the one test for the line of code you want to change (or implement). And use your IDE build instead of Maven.

最有效的方法不是在本地依赖Maven,而是让您通过持续集成服务器覆盖:只对要更改(或实现)的代码行运行一个测试。并使用您的IDE构建而不是Maven。

Then commit to a repository which automatically triggers Jenkins builds for each commit. All the build and test time (for the full test suite) is then consumed on the continuous integration server, while you can already implement the next feature. Only after successful test, the integration server will push your change into the blessed repository.

然后提交到一个存储库,它会为每个提交自动触发Jenkins构建。然后,在持续集成服务器上使用所有构建和测试时间(对于完整的测试套件),同时您已经可以实现下一个功能。只有在成功测试之后,集成服务器才会将您的更改推送到受祝福的存储库中。

There are tons of tutorials on the Internet how to use Jenkins, Maven, Git to cover this workflow.

互联网上有很多教程如何使用Jenkins,Maven,Git来涵盖这个工作流程。

#3


0  

I am working on Web development with JBoss plugin for Eclipse, Maven plugin for Eclipse, and Eclipse where in maven I have set up auto deployment. My over all deployment time is around 1 min. If you want to reduce further then look for hot deployment.

我正在使用用于Eclipse的JBoss插件,用于Eclipse的Maven插件和Eclipse中的Eclipse进行Web开发,我在maven中设置了自动部署。我的整个部署时间大约是1分钟。如果您想进一步减少,那么请寻找热部署。

Check this Eclipse + Tomcat - Serve webapp directly from workspace

检查此Eclipse + Tomcat - 直接从工作区提供webapp

In my observation, if you change few lines in one file then maven will compile only that file but yes you have to start the maven build process.

在我的观察中,如果你在一个文件中更改了几行,那么maven将只编译该文件但是你必须启动maven构建过程。

I think number of libraries should not be problem. They are downloaded only once and then they are stored in .m2 folder. In my case it is downloaded every morning or first build then there is minimal downloads. I have worked with more than 10 libraries.

我认为图书馆的数量不应该是问题。它们只下载一次,然后存储在.m2文件夹中。在我的情况下,它每天早上下载或首次构建,然后下载量最小。我和10多个图书馆合作过。

It would be one time set up of development environment (means installing,configuring tools) then it would go smoothly.

这将是开发环境的一次设置(意味着安装,配置工具)然后它会顺利进行。

#4


0  

If your project is divided into modules with a parent-child relationship, you can have maven build just a subset of the children. See the answers to this other SO question: How to maven build child projects?

如果您的项目被划分为具有父子关系的模块,则可以让maven只构建子项的子集。查看其他问题的答案:如何构建子项目?

#5


0  

Welcome to J2EE world. I can propose sevaral hack-ish workarounds, don't take as complete guide:

欢迎来到J2EE世界。我可以提出sevaral hack-ish变通方法,不要作为完整指南:

  1. first of all, hdd speed matters a lot, if you can get ssd, that would be great.

    首先,硬盘速度很重要,如果你能得到ssd,那就太棒了。

  2. FS/OS matters. for me, on same hardware, ubuntu+ext4 build is 30-40% faster than windows+ntfs

    FS / OS很重要。对我来说,在相同的硬件上,ubuntu + ext4 build比windows + ntfs快30-40%

  3. hacks like working in offline mode (doesn't check for external dependency updates), disabling tests during active development might help speed things up, but may also shoot you in the foot.

    像在离线模式下工作的黑客(不检查外部依赖关系更新),在活动开发期间禁用测试可能有助于加快速度,但也可能会让你陷入困境。

  4. if you work on one particular feature in one module, you can build only that module and then build your ear module to deploy

    如果您在一个模块中处理一个特定功能,则只能构建该模块,然后构建要部署的ear模块

  5. use full potential of your ide. use Hot Swap. try to get it to deploy exploded artifacts, this way you won't even need maven and creating jars/wars/ears. IntelliJ IDEA is my personal favourite here. Eclipse might make do as well.

    充分利用你的想法。使用热交换。试图让它部署爆炸文物,这样你甚至不需要maven和创建罐子/战争/耳朵。 IntelliJ IDEA是我个人的最爱。 Eclipse可能也会这样做。

  6. disable antivirus (some of them love to check every single class file you create). if you're in corporate environment, ask an exorcist to do it for you

    禁用防病毒软件(其中一些人喜欢检查您创建的每个类文件)。如果你在公司环境中,请求驱魔人为你做

#6


0  

In my experience, the speed of your build is mainly influenced by hardware, especially the speed of the disk drive(s). The build tool doesn't really play a big role. Maven should perfectly be able to handle a project with 10 libraries.

根据我的经验,构建速度主要受硬件的影响,特别是磁盘驱动器的速度。构建工具并没有真正发挥重要作用。 Maven应该能够完美地处理10个库的项目。

My current project has around 92 JAR files on its classpath. Subtract a few for test purposes only, subtract a few for libraries that are built in multiple JAR files, and you're left with many more than 10 libraries. Still, a build is done in just a few seconds. Tests run in about two minutes (but there's one test which takes about half of that.

我当前的项目在其类路径上有大约92个JAR文件。减去一些仅用于测试目的,减去一些用于在多个JAR文件中构建的库,并且剩下10个以上的库。不过,构建只需几秒钟即可完成。测试在大约两分钟内完成(但是有一个测试大约需要一半的测试。

#1


1  

Tools for Hot Deployment like JRebel are able to do it without restarting the server. Otherwise you'll need to restart it, with no problem for 10 libraries I think.

像JRebel这样的热部署工具可以在不重新启动服务器的情况下完成。否则你需要重新启动它,我认为10个库没有问题。

I usually work with 7 or 8 and you only have to wait while the server restarts, cause the deploy is automatically managed with Eclipse+m2e-wtp. If you have the project divided in multiple modules this plugin takes care about compiling only what you want and deploying it.

我通常使用7或8,您只需等待服务器重新启动,因为部署是使用Eclipse + m2e-wtp自动管理的。如果您将项目划分为多个模块,则此插件只会编译您想要的内容并进行部署。

#2


1  

The most effective way is not rely on Maven locally, but to have you covered by the continuous integration server instead: Run only the one test for the line of code you want to change (or implement). And use your IDE build instead of Maven.

最有效的方法不是在本地依赖Maven,而是让您通过持续集成服务器覆盖:只对要更改(或实现)的代码行运行一个测试。并使用您的IDE构建而不是Maven。

Then commit to a repository which automatically triggers Jenkins builds for each commit. All the build and test time (for the full test suite) is then consumed on the continuous integration server, while you can already implement the next feature. Only after successful test, the integration server will push your change into the blessed repository.

然后提交到一个存储库,它会为每个提交自动触发Jenkins构建。然后,在持续集成服务器上使用所有构建和测试时间(对于完整的测试套件),同时您已经可以实现下一个功能。只有在成功测试之后,集成服务器才会将您的更改推送到受祝福的存储库中。

There are tons of tutorials on the Internet how to use Jenkins, Maven, Git to cover this workflow.

互联网上有很多教程如何使用Jenkins,Maven,Git来涵盖这个工作流程。

#3


0  

I am working on Web development with JBoss plugin for Eclipse, Maven plugin for Eclipse, and Eclipse where in maven I have set up auto deployment. My over all deployment time is around 1 min. If you want to reduce further then look for hot deployment.

我正在使用用于Eclipse的JBoss插件,用于Eclipse的Maven插件和Eclipse中的Eclipse进行Web开发,我在maven中设置了自动部署。我的整个部署时间大约是1分钟。如果您想进一步减少,那么请寻找热部署。

Check this Eclipse + Tomcat - Serve webapp directly from workspace

检查此Eclipse + Tomcat - 直接从工作区提供webapp

In my observation, if you change few lines in one file then maven will compile only that file but yes you have to start the maven build process.

在我的观察中,如果你在一个文件中更改了几行,那么maven将只编译该文件但是你必须启动maven构建过程。

I think number of libraries should not be problem. They are downloaded only once and then they are stored in .m2 folder. In my case it is downloaded every morning or first build then there is minimal downloads. I have worked with more than 10 libraries.

我认为图书馆的数量不应该是问题。它们只下载一次,然后存储在.m2文件夹中。在我的情况下,它每天早上下载或首次构建,然后下载量最小。我和10多个图书馆合作过。

It would be one time set up of development environment (means installing,configuring tools) then it would go smoothly.

这将是开发环境的一次设置(意味着安装,配置工具)然后它会顺利进行。

#4


0  

If your project is divided into modules with a parent-child relationship, you can have maven build just a subset of the children. See the answers to this other SO question: How to maven build child projects?

如果您的项目被划分为具有父子关系的模块,则可以让maven只构建子项的子集。查看其他问题的答案:如何构建子项目?

#5


0  

Welcome to J2EE world. I can propose sevaral hack-ish workarounds, don't take as complete guide:

欢迎来到J2EE世界。我可以提出sevaral hack-ish变通方法,不要作为完整指南:

  1. first of all, hdd speed matters a lot, if you can get ssd, that would be great.

    首先,硬盘速度很重要,如果你能得到ssd,那就太棒了。

  2. FS/OS matters. for me, on same hardware, ubuntu+ext4 build is 30-40% faster than windows+ntfs

    FS / OS很重要。对我来说,在相同的硬件上,ubuntu + ext4 build比windows + ntfs快30-40%

  3. hacks like working in offline mode (doesn't check for external dependency updates), disabling tests during active development might help speed things up, but may also shoot you in the foot.

    像在离线模式下工作的黑客(不检查外部依赖关系更新),在活动开发期间禁用测试可能有助于加快速度,但也可能会让你陷入困境。

  4. if you work on one particular feature in one module, you can build only that module and then build your ear module to deploy

    如果您在一个模块中处理一个特定功能,则只能构建该模块,然后构建要部署的ear模块

  5. use full potential of your ide. use Hot Swap. try to get it to deploy exploded artifacts, this way you won't even need maven and creating jars/wars/ears. IntelliJ IDEA is my personal favourite here. Eclipse might make do as well.

    充分利用你的想法。使用热交换。试图让它部署爆炸文物,这样你甚至不需要maven和创建罐子/战争/耳朵。 IntelliJ IDEA是我个人的最爱。 Eclipse可能也会这样做。

  6. disable antivirus (some of them love to check every single class file you create). if you're in corporate environment, ask an exorcist to do it for you

    禁用防病毒软件(其中一些人喜欢检查您创建的每个类文件)。如果你在公司环境中,请求驱魔人为你做

#6


0  

In my experience, the speed of your build is mainly influenced by hardware, especially the speed of the disk drive(s). The build tool doesn't really play a big role. Maven should perfectly be able to handle a project with 10 libraries.

根据我的经验,构建速度主要受硬件的影响,特别是磁盘驱动器的速度。构建工具并没有真正发挥重要作用。 Maven应该能够完美地处理10个库的项目。

My current project has around 92 JAR files on its classpath. Subtract a few for test purposes only, subtract a few for libraries that are built in multiple JAR files, and you're left with many more than 10 libraries. Still, a build is done in just a few seconds. Tests run in about two minutes (but there's one test which takes about half of that.

我当前的项目在其类路径上有大约92个JAR文件。减去一些仅用于测试目的,减去一些用于在多个JAR文件中构建的库,并且剩下10个以上的库。不过,构建只需几秒钟即可完成。测试在大约两分钟内完成(但是有一个测试大约需要一半的测试。