Question

I have a caching app in Java and I need to put objects of different size in cache. The problem is that I didn't really know how to count the size of a custom object and I've found the solution - to use the library: http://mvnrepository.com/artifact/com.googlecode.sizeofag/sizeofag/1.0.0. To run the program using the library I need to specify command-line argument -javaagent. So, how can I do it if I'm using maven???


The program is simple:

protected static Boolean b;
public static void main( String[] args )
{
    System.out.println(SizeOfAgent.sizeOf(b));
}

This is the output:

0
Can not access instrumentation environment.
Please check if jar file containing SizeOfAgent class is 
specified in the java's "-javaagent" command line argument.


P.S. I know, that such kind of question already exists, but it has no proper answer.

Was it helpful?

Solution

On a Linux/Unix machine the "mvn" command will use a shell variable "MAVEN_OPTS" to pass in options. This is useful if you want to give Maven more memory. In your .profile or .bash_profile put a line like this in:

export MAVEN_OPTS=-javaagent

On windows:

in shell (cmd.exe) type "set MAVEN_OPTS=..."

or

add MAVEN_OPTS to your environment

On NetBeans:

In ~/.netbeans/6.5/, create etc/netbeans.conf. Add your environment variables there, e.g.:

export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top