Question

In my Java EE Maven webapplication running on Tomcat I want to use http://sizeof.sourceforge.net or a comparable library requiring a -javaagent: call.

Using SO research, I have come to the following additions in my pom.xml:

  1. for actually using the SizeOf library:

    <dependency>
        <groupId>net.sourceforge.sizeof</groupId>
        <artifactId>SizeOf</artifactId>
        <version>0.2.1</version>
        <type>jar</type>
    </dependency>
    
  2. to make the -javaagent call

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4</version>
        <configuration>
             <forkMode>once</forkMode>
             <argLine>
                 -javaagent:"${settings.localRepository}/net/sourceforge/sizeof/SizeOf/0.2.1/SizeOf-0.2.1.jar"
             </argLine>
             <useSystemClassloader>true</useSystemClassloader>
        </configuration>
    </plugin> 
    

Everything builds just fine. When I call a method using SizeOf, I'm getting an error Instrumentation is not set, indicating setting -javaagent failed.

I appreciate your help.

Était-ce utile?

La solution

I was being a big noob concerning Maven and Surefire. The above configuration works as expected: It sets a javaagent for tests during buildtime. That's however, not what I wanted.

Through my Netbeans IDE, I managed to set the -javaagent correctly as a VM Option on my TomEE/Tomcat server:

In Netbeans (OS X, 7.3): 
Tools > Servers > (your server) > Platform.
Fill in next to VM Options: -javaagent:/path/to/javaagent.jar

enter image description here

P.S.: A Maven solution would be infinitely better. If you have one, please share it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top