Showing posts with label build. Show all posts
Showing posts with label build. Show all posts

Wednesday, 15 April 2009

com.vladium.emma.EMMARuntimeException: [CLASS_STAMP_MISMATCH]

Emma is used for finding the code coverage of JUnit test classes.

When running Emma with a JEE container, the source .class files (not the .java files) are first instrumented and then deployed on the J2EE server.

Then the test classes are executed from ant command line or via an Eclipse plug-in, and this will write out the coverage data into .em or .ec files.

Sometimes, an error observed when running Emma is


emma.report:
[report] processing input files ...
[report] 2 file(s) read and merged in 172 ms
[report] com.vladium.emma.EMMARuntimeException: [CLASS_STAMP_MISMATCH] runtime version of class [com.xyz.action.MyAction] in the coverage data is not consistent with the version of this class in the metadata, possibly because stale metadata is being used for report generation.

[report] at com.vladium.emma.report.ReportDataModel.getView(ReportDataModel.java:95)
[report] at com.vladium.emma.report.AbstractReportGenerator.initialize(AbstractReportGenerator.java:207)
[report] at com.vladium.emma.report.html.ReportGenerator.process(ReportGenerator.java:85)
[report] at com.vladium.emma.report.ReportProcessor._run(ReportProcessor.java:254)





To calculate the coverage, EMMA combines data of two types:
metadata (static info about your Java classes, methods, lines, and basic blocks) and runtime coverage data (which basic blocks have been executed)

The error occurs when there is a mismatch in the versions of the classes used while recording the metadata.em and coverage.em files. The runtime version of the class in the coverage data is not consistent with the same class in the metadata

In simpler terms, the in-container application jars deployed on the JEE server are not in sync with the currently instrumented source from where the emma is being run, hence the class stamp difference in .emma files – metadata.em and coverage.em


Update -
A couple of comments posted below have some more checks and solutions to this problem.

Thursday, 2 April 2009

Running Maven offline using local Repository

Sometimes you see Maven downloading POM files for dependencies which are already in your local repository and you're wondering why it does this.

Downloading: http://repo1.maven.org/maven2//org/apache/xmlgraphics/fop/0.95/fop-
0.95.pom
Downloading: http://repo1.maven.org/maven2//org/apache/xmlgraphics/xmlgraphics-c
ommons/1.3.1/xmlgraphics-commons-1.3.1.pom
Downloading: http://repo1.maven.org/maven2//org/apache/xmlgraphics/batik-svg-dom
/1.7/batik-svg-dom-1.7.pom


The reason it does is because when these were installed in the local repository, it was not given a flag of -Dgenerate.pom=true

If you run the install with this flag, then it will generate and install a local POM file for you, and will not download the POM from the internet repository.

An example below
mvn install:install-file -DgroupId=%GROUP_ID% -DartifactId=%ARTIFACT_ID% -Dversion=%VERSION% -Dfile=%COMPONENT%.jar -Dpackaging=jar -DgeneratePom=true




There are 2 other ways to run the build without connecting to the internet or network repository each time - provided you have all the required dependencies available offline.

Note: This is just something I do when I want to run a quick repeat build and I know there are no dependencies updated in the mean time. If you do this regularly you will miss out on updates made to the maven repository by other developers.

1. Run the maven build in offline mode

mvn -o install

[INFO]
NOTE: Maven is executing in offline mode. Any artifacts not already in your loca
l
repository will be inaccessible.

...

When you see this message, you know that maven will not be updating external dependencies during the build.

2. Point the repository to the local file system.

On my local build, if running repeated code builds when I know there is no change in dependency, I have a profile set up to point the repository to a local file system.

In the repository definition, instead of
<url>http://repo1.maven.org/maven2/</url>

use the file:// path


<repository>
<id>central</id>
<url>file://D:\mavenrepo</url>
</repository>


You will still see the message indicating downloading of POM, but this time from the local file system.
And this will be much faster.
Downloading: file://D:\mavenrepo\cactus\1.7.2\cactus-1.7.2.pom
Downloading: file://D:\mavenrepo\strutstest\2.1.3\strutstest-2.1.3.pom

Friday, 13 March 2009

java.lang.ClassNotFoundException: org.apache.tools.ant.Main

This error should not be occuring when you install Ant out-of-the-box and run it. However, on the rare occasions it does occur - the solution is quite simple.



java.lang.ClassNotFoundException: org.apache.tools.ant.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:244)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)



Take a look at the ANT_HOME/lib folder - and ensure that the ant.jar is in there and showing a size of 1MB or higher.

It is usually due to a corrupted version of ant.jar in the above path.

Monday, 9 March 2009

Executing multiple mvn commands from a Windows bat file

When running Maven, if you try to run multiple Maven commands in a batch (.bat) file, it only runs the first one and exits to the command prompt
mvn clean
mvn package
This occurs since mvn itself is a bat file. To overcome this, you need to stop Windows passing control to the mvn.bat script by using the call command for each call to mvn.
call mvn clean
call mvn package

Additionally, to catch failures you will need to do this

call mvn clean
echo Exit Code = %ERRORLEVEL%
if not "%ERRORLEVEL%" == "0" exit /b

call mvn package
echo Exit Code = %ERRORLEVEL%
if not "%ERRORLEVEL%" == "0" exit /b

A failure throws an ERRORLEVEL higher than 0. Otherwise it will keep moving ahead even if it fails. Note: if you're using maven 2.0.7 or older, there is a possibility that the mvn does not return an ERRORLEVEL > 0 for the process to exit. Lots of examples are available here http://www.google.co.uk/search?hl=en&q=mvn+exit+ERRORLEVEL&meta= A simple test to check if your version allows this - run the commands below in a bat file.
call mvn unknown
echo Exit Code = %ERRORLEVEL%
You should get a Failure with exit code 1 as below. If it does not fail, then upgrade to a higher version of Maven in which the issue is fixed.
D:\maven-2.0.7\bin>call mvn unknown
[INFO] Scanning for projects...
[INFO] ----------------
[ERROR] BUILD FAILURE
[INFO] ----------------
[INFO] Invalid task 'unknown': you must 
specify a valid lifecycle phase, 
or a goal in the format plugin:goal or  
pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ----------------
[INFO] For more information, run Maven 
with the -e switch
[INFO] ----------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Mar 10 12:07:12 
GMT+05:30 2009
[INFO] Final Memory: 1M/2M
[INFO] ----------------
Exit Code = 1

Update Learnt the hard way that the call to mvn must immediately be followed by the checking of the ERRORLEVEL. Our build.bat script measures time taken for each step like below:

time /t
call mvn install
time /t
if not "%ERRORLEVEL%" == "0" exit /b

In this case, it loses the ERRORLEVEL value from the mvn command. Hence we need to ensure:

time /t
call mvn install
if not "%ERRORLEVEL%" == "0" exit /b
time /t

The cost of legacy technical debt and the need for modernization

 Legacy systems, once the backbone of enterprise IT, are now a major obstacle to innovation, agility, and resilience. Despite the rise of cl...