How to enable assertions in jetty-maven-plugin? By default they are disabled.
4 Answers
Set environment variable MAVEN_OPTS
to -ea
. Jetty by default runs within Maven process and thus is affected by this setting.
There is also interesting library called Force Assertions which hooks into Java 1.6 compilation process. During compilation all assert cond : detail;
are transparently compiled to if (!cond) throw new Assertion(detail);
blocks, which means assertions will work always no matter what JVM parameters are. Worth to check.

- 16,869
- 1
- 76
- 58
-
Is it possible to do the same inside `pom.xml`? – yegor256 Mar 02 '11 at 17:06
-
I'm afraid not, jetty plugin doesn't have fork setting, where you can set its JVM configuration separately. – gertas Mar 02 '11 at 17:16
-
forceassertions is interesting indeed. anyone know how to use it with maven? – bungrudi Oct 18 '11 at 01:53
If your are using Netbeans (tested with Netbeans 8.0), this is the way to do it imo:
Add this to your nbactions.xml file (in the project root directory):
<actions>
<action>
<actionName>CUSTOM-jetty:run</actionName>
<displayName>jetty:run</displayName>
<goals>
<goal>jetty:run</goal>
</goals>
<properties>
<Env.MAVEN_OPTS>-ea</Env.MAVEN_OPTS>
</properties>
</action>
</actions>
No other setup needed. You can just use jetty:run.
See also https://netbeans.org/bugzilla/show_bug.cgi?id=166874

- 12,062
- 4
- 64
- 92
If it's to only run tests and you are using maven-surefire-plugin, use this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<enableAssertions>true</enableAssertions>
</configuration>
</plugin>

- 2,396
- 1
- 24
- 25