I wanted to enable assertions while running Jetty and Tomcat plugin’s with Maven and have not found any postings talking about how to enable assertions other than with surefire unit tests, and with a custom eclipse or intellij IDEA runner.

So what about on the command line?

Java assertions are enabled by the following syntax:

--ea[:...|:] or enableassertions  (to enable assertion at a particular package and class level)

But how can I enable them for the Tomcat Maven plugin?

I had tried the following options with no success:

export JAVA_OPTS="-ea"
export JAVA_ARGS="-ea"
export CATALINA_OPTS="-ea"
...
export JAVA_OPTS="-enableassertions"
export JAVA_ARGS="-enableassertions"
export CATALINA_OPTS="-enableassertions"

But the solution for adding MAVEN_OPTS as depicted:

export MAVEN_OPTS="-ea"
... or ...
export MAVEN_OPTS="-enableassertions"

Hopefully this can help other to use more assertions.

Mick Knutson

Java, JavaEE, J2EE, WebLogic, WebSphere, JBoss, Tomcat, Oracle, Spring, Maven, Architecture, Design, Mentoring, Instructor and Agile Consulting. http://www.baselogic.com/blog/resume

View all posts

Java / JavaEE / SpringFramework Channel

BLiNC Supporters

BLiNC Adsense