Kohei Nozaki's blog 

How to define JVM parameters


Posted on Friday Mar 07, 2014 at 08:09AM in Technology


Environment

  • WildFly 8.0.0.Final
  • JBoss Tools (Kepler) 4.1.1.Final
  • Eclipse Kepler SR1
  • Oracle JDK7u51
  • OS X 10.9.2

Test Servlet

  • This time we're going to test it with enabling of assertion.
@WebServlet("/")
public class AssertServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        assert false : "test";
    }
}

Configure standalone.conf for launching through standalone.sh

  • Add this statement to $WILDFLY_HOME/bin/standalone.conf
JAVA_OPTS=$JAVA_OPTS -ea
  • This can be done on unix systems like this:
echo "JAVA_OPTS=\"\$JAVA_OPTS -ea\"" >> standalone.conf
  • Now the Servlet throws Assertion Error when we launch WildFly through standalone.sh:
09:05:00,614 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /assert/: java.lang.AssertionError: test
    at assert0.AssertServlet.doGet(AssertServlet.java:16) [classes:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
...
  • But it won't work with WildFly instances that launched by Eclipse.

Configuring Eclipse

  1. Open Servers view and double-click WildFly instance

  2. Click “Open launch configuration”

  3. Add “-ea” to “VM arguments:” - OK

wildfly-maven-plugin

  • Like this:
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <version>1.0.1.Final</version>

                        <configuration>
                            <jboss-home>${wildfly.home}</jboss-home>
                            <modules-path>${wildfly.home}/modules</modules-path>
                            <jvm-args>-ea -Xms64m -Xmx512m -XX:MaxPermSize=256m
                                -Djava.net.preferIPv4Stack=true
                                -Djboss.server.base.dir=${wildfly.home}/standalone
                                -Djboss.socket.binding.port-offset=${wildfly.port.offset}</jvm-args>
                            <port>${wildfly.port.mgmt}</port>
                        </configuration>
...

Assertion notes

Eclipse

  • We can enable assertion for every JUnit run configuration which will newly create.

  • This won't make assertions enable for already created run configurations.

Maven Surefire Plugin

  • “By default, Surefire enables JVM assertions for the execution of your test cases. To disable the assertions, set this flag to “false”[3].

References

  1. Configure JVM settings for Standalone Mode from… | Community
  2. How to enable Assertions in eclipse (IDEs and Version Control forum at JavaRanch)
  3. Maven Surefire Plugin - surefire:test



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed