views:

21

answers:

1

I've been seeing odd behaviour from my Maven 2.2.1 installation whilst doing war installs.

Occasionally, I will update a class but the updated version is not packaged up in the artifact produced by mvn install.

So far, I have determined that an updated .class file is produced in the target directory, and that the class of the same name in the produced .war is not the same (different date modified, different size)

Running Maven from the command line with the -X flag produced debug output for the class like:

[DEBUG] * WEB-INF/classes/mypackage/MyClass.class is up to date.

I think I've also had the same problem before where the file that was cached(?) was an incomplete compile from Eclipse, causing 'Unresolved Compilation Problem' errors from the Maven build, but a working artifact from an Eclipse export.

  • How does Maven determine whether a file 'is up to date' during the install process?
  • Where are the files Maven is comparing to?
  • Can I force Maven to build a package from scratch?
  • Any other ideas would be appreciated!
+2  A: 

So far, I have determined that an updated .class file is produced in the target directory, and that the class of the same name in the produced .war is not the same (different date modified, different size)

Just to be sure, the classes should be built under target\classes, not target.

  • Can I force Maven to build a package from scratch?

You can force a full build by running

mvn clean install

This performs a clean (essentially removes the target directory) before running the install phase.

Also - check for copies of your classes outside of the Maven build directory. In this case as it is a webapp, check src/main/webapp/WEB-INF/classes

mdma
I was doing mvn clean before mvn install, didn't realise you could do both in one command. Thanks for the tip, but I just gave it a quick try and it hasn't solved the problem. Yes, the classes are in a package structure in target/classes.
Brabster
If doing a clean build does not fix the problem, then it sounds like there are build files outside of the build directory, (which will bite!) or the classes come from from a different artefact to the one you are building.
mdma
Hmmmm '...the classes come from outside the build directory...' I'll go have a root through the project
Brabster
I had an old copy of the classes under src/main/webapp/WEB-INF/classes. Looks like Maven was picking them up from there, deleted that directory and the problem vanished. Perfect! I'll edit your answer to include that detail in the main body and accept it. Thanks!
Brabster
@brabster you can call any number of goals or lifecycles in a maven command. e.g. `mvn clean install eclipse:clean eclipse:eclipse` builds both your project and your eclipse config from scratch
seanizer
@brabster in a maven project, there should never be classes in `src/main/webapp/WEB-INF/classes`, in fact there should never be any classes anywhere under src!!!
seanizer