Why might Maven ignore updated classes during install?

痴心易碎 提交于 2019-12-04 04:04:35

问题


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!

回答1:


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



来源:https://stackoverflow.com/questions/3281098/why-might-maven-ignore-updated-classes-during-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!