-1

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

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)

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.

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.

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

Remizorrr
  • 2,322
  • 1
  • 17
  • 25

6 Answers6

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.

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.

Aritz
  • 30,971
  • 16
  • 136
  • 217
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.

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.

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

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • Are you sure it is a good way to commit not working code to repository? I mean, until you test your code, you can't be sure it is working properly. And if it is not working, i will still know that only after 5 minutes. There should be another way. Maybe the JRebel will work for me. it looks pretty interesting. – Remizorrr Jul 11 '13 at 20:00
  • Ah, I was not perfectly clear about the setup. If you use git commit triggered builds, then you typically use at least 2 repositories: One into which developers commit their changes. From that repository Jenkins pulls the changes and only after successful test pushes them to the second ("blessed") repository. The developers again pull only from the second repo. So the CI server running the tests will only forward the changes which are known to not fail the tests. – Bananeweizen Jul 12 '13 at 08:01
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.

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.

mthmulders
  • 9,483
  • 4
  • 37
  • 54
  • i didn't mean linked libraries. 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. – Remizorrr Jul 11 '13 at 15:36
  • are you also running the tests? tests of 10 projects must be taking that long, if you disable testing you will see that it is pretty fast – anvarik Jul 11 '13 at 16:13
  • tests were disabled. the time is 9m 47 sec for clean install and 6m 30 sec for mvn install -o – Remizorrr Jul 11 '13 at 19:14
  • Wow, that's bad. In a corporate environment, I'd calculate the loss of time and ask for new hardware. It's a matter of investing, I'd say. – mthmulders Jul 11 '13 at 19:16
  • 2
    Again, there's no need to execute `mvn install` during development. There are plugins which take care about what's changed and deploy only changed `.class` files themselves for you. Everything is done clicking the Eclipse 'build All' button, which is infinitely cheaper than doing a complete `mvn install` which is done, by the way, to pack the project for production enviroments. – Aritz Jul 11 '13 at 19:21
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.

Check this Eclipse + Tomcat - Serve webapp directly from workspace

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.

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.

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

Community
  • 1
  • 1
ritesh
  • 907
  • 3
  • 11
  • 31
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?

Community
  • 1
  • 1
David
  • 2,602
  • 1
  • 18
  • 32
0

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

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

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

  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

  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.

  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

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68