Tag Archives: maven

Maven Surefire PermGen error


In case you are getting PermGen error while running tests using the Maven Surefire plugin, here is the solution:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>${surefire.version}</version>
  <configuration>
    <argLine>-Xmx512m -XX:MaxPermSize=256m</argLine>
  </configuration>
</plugin>

Setting the JVM args as part of the plugin did the trick!

Setting MAVEN_OPTS would not help because Maven Surefire plugin forks the JVM process while running the tests, and so the MAVEN_OPTS settings do not take effect.

Proxied…


If you work in a corporate behind a firewall, most likely you would need to configure proxy for any of the dev tools that talk to the internet. The write-up below talks about configuring proxy for:

  • Maven – Build and management tool for any Java-based project
  • Git – Distributed version control system
  • npm – Node Packaged Modules (Package manager for Node.js)
  • Bower – Front-end package manager

In order to work with any of the above tools, you would need to have access to the internet. And if your company/client uses a proxy server, you would need to configure these tools to use that proxy in order to talk to the internet.

  • Maven

Add the following section in your maven settings.xml (typically located at ${user.home}/.m2/settings.xml).

<settings>
  .
  .
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
  </proxies>
  .
  .
</settings>

For a detailed description on the different settings, please refer to this link.

  • Git

For using git over HTTP, execute the following command.

git config --global http.proxy http://<proxy_server>:<proxy_server_port>
  • npm

Execute the following command. You might want to put it as part of your .bash_profile (for bash) or the profile file of your favorite shell so that you do not need to set it up whenever you open up a new command shell.

npm config set proxy http://<proxy_server>:<proxy_server_port>
  • Bower

Set the following environment variable:  HTTP_PROXY or HTTPS_PROXY (as per your needs).

export HTTPS_PROXY=http://<proxy_server>

Again, you might would want to put it as part of your .bash_profile (for bash). In case of windows, add a new User environment variable.

Maven Exec Plugin vs Maven AntRun Plugin for running command-line tool


Maven Exec Plugin supports the following two goals:

  1. exec: to execute external programs (including Java) in a separate process
  2. java: to execute Java programs in the same JVM

Maven AntRun Plugin supports only one goal:

  1. run: to execute the Ant target specified

If you have a requirement to run a command-line tool, e.g. cURL, in an synchronous (blocking) way, you can use the Maven Exec Plugin (exec goal). However, in case you need to run it in an asynchronous (non-blocking) fashion, you can use the Ant exec task (with ‘spawn’ option set as true) with Maven AntRun Plugin. You might want to consider something like this before executing the integration tests which could be dependent on the database being in a clean state. Here is an example:

  • Using Maven Exec Plugin
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2</version>
  <executions>
    <execution>
      <id>drop DB => db_name</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>exec</goal>
      </goals>
      <configuration>
        <executable>curl</executable>
        <arguments>
          <argument>-s</argument>
          <argument>-S</argument>
          <argument>-X</argument>
          <argument>DELETE</argument> 
          <argument>http://${db.server}:${db.port}/db_name</argument>
        </arguments>
      </configuration>
    </execution>
  </executions>
</plugin>
  • Using Maven AntRun Plugin
<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.6</version>
  <executions>
    <execution>
      <id>drop DB => db_name</id>
      <phase>pre-integration-test</phase>
      <configuration>
        <target>
          <exec executable="curl">
            <arg value="-s" />
            <arg value="-S" />
            <arg value="-X" />
            <arg value="DELETE" />
            <arg value="http://${db.server}:${db.port}/db_name" />
            <spawn value="true">
          </exec>
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>