0

I have a huge project, where after even a minor change, i have to rebuild the whole project. Is this an architectural fault, or java can't do this partial compilation whatsoever?

PS:This is really convenient to solve those kind of problems in C++ with its compilation/linking stuff.

  • Consider using a build tool, like ant or maven – khelwood Jul 13 '17 at 12:31
  • There is hot swapping and such. – Murat Karagöz Jul 13 '17 at 12:31
  • You can compile modified classes one by one with javac.exe then open jar with WinRAR and put .class inside it. Anyway, better use build tool (like Ant). – Celestine Jul 13 '17 at 12:33
  • 0 down vote I think it would be the build tool actually. What build tool are you using? I can explain in detail how you implement incremental compilation in gradle. Are you relying on an IDE by any chance? – sagneta Jul 13 '17 at 12:33
  • @we use maven as our build tool and after i add a change to the code base, i have to recompile/rebuild the whole project. –  Jul 13 '17 at 12:35
  • *"PS:This is really convenient to solve those kind of problems in C++ with its compilation/linking stuff."* That statement serves no useful purpose in your question whatsoever. It's just as easy in Java, if not easier. You just don't recompile the superclass when adding/modifying a subclass, as there's exactly zero reason to. – T.J. Crowder Nov 19 '17 at 14:22
  • @T.J.Crowder any proof? –  Nov 19 '17 at 15:33
  • @Richard: I have trouble believing that's a genuine question given the various answers here and the points Kayaman made in your now-deleted other question, but I'll play along for *one* comment. It's trivial to prove this: Create a class and `javac TheClass.java`. Now, look at the date/time stamp on `TheClass.class` (the compiled class). Now, create a subclass of it in `TheSubClass.java` and `javac TheSubClass.java`. Look at the date/time stamp on `TheClass.class`. It hasn't changed. – T.J. Crowder Nov 19 '17 at 15:39
  • And of course, there's the minor detail that the JDK classes are delivered in compiled form, and we subclass them all the time without recompiling them. – T.J. Crowder Nov 19 '17 at 15:46
  • @T.J.Crowder Well, let me think. "Some object-oriented languages are not sufficiently modular and require recompilation of superclasses when compiling subclasses." If it's not java(not sufficiently modular language), what language does author speak of? –  Nov 19 '17 at 15:48
  • @Richard: As I said in a comment on [your sockpuppet question](https://stackoverflow.com/questions/47377330/what-programming-languages-lack-a-decent-modularization-oo-design) before it was deleted: It's a shockingly poor article that makes such a statement without a single example to back it up. – T.J. Crowder Nov 19 '17 at 15:52

5 Answers5

3

There are several solutions:

  • Use Maven or Gradle multimodule projects which can be compiled separately. Plus, they provide incremental compilation as well.
  • Use microservices
  • Use OSGi which adds a module system to Java with dynamic reloading
  • Use JRebel which adds easy to use code swap.

It is hard to tell which is ideal for you, each has its strengths and weaknesses.

Note that nowadays using Maven or Gradle is mandatory if you are writing code in Java. They not only let you to modularize your project but they are also dependency management and build tools as well.

OSGi is a quite niche product it is most probably not useful for you and microservices is a quite complex topic in itself so I'd suggest going with a tool like Gradle and use JRebel or some other code swap tool while you develop your app.

Anton Arhipov
  • 6,479
  • 1
  • 35
  • 43
Adam Arold
  • 29,285
  • 22
  • 112
  • 207
0

How about splitting the projet and using some part as maven artifacts ? In that case, if you have to recompile a part, you just increment the version number.

In that case you need a repository installed in your local network.

JFPicard
  • 5,029
  • 3
  • 19
  • 43
0

first thing is to disable Make, then from debug/run configuration compile action, from file context menu.

A very nice explanation here

RANVIR GORAI
  • 1,226
  • 11
  • 10
0

It depends a lot on the build tool you are using. I don't know a lot about other build tools, but I know for sure Gradle does this. In a modularized project such as the one I am currently running (GWT, J2EE, Tests) I easily exclude parts I don't want to compile with a simple command like:

gradle redeploy -x test -x compilegwt

this line just says exclude tests and gwt in the compilation. Cheers

jaletechs
  • 501
  • 1
  • 7
  • 19
-1

If you are not using a build-management tool such as Maven or Ant, you can compile specified directories with javac:

javac directory1/*.java directory2/*.java 

Here is the original question I sourced from.

I did a short search for Ant, so if you are indeed using it, check here.

Edit: Found that you are indeed using Maven. I'm not a Maven expert by any means, but if you are coding your projects in modules, it should be possible to compile specified modules, and possibly also their dependencies, correct?

Austin Schaefer
  • 695
  • 5
  • 19