开发者

Make classmexer and ant working together

We're working on a java project and we use ant to build and run the program. Now we are doing some performance tests and we wanted to use classmexer. The problem is that we can't get ant and classmexer work together.

Since it's necessary to pass to the jvm the argument

-javaagent:classmexer.jar

we have tried the following in our build.xml

<target name="run" description="Try running it." depends="all">
    <java jvmargs="-javaagent:classmexer.jar" jar="${OUT_DIR}/${FILE_NAME}.jar" failonerror="true" fork="true">
    </java>
</target>

but it doesn't work. At runtime the program throws the following exception

java.lang.IllegalStateException: Agent not initted
          at com.javamex.classmexer.Agent.getInstrumentation(Agent.java:33)
          at com.javamex.classmexer.MemoryUtil.deepMemoryUsageOf(MemoryUtil.java:104)
          at com.javamex.classmexer.MemoryUtil.deepMemoryUsageOf(MemoryUtil.java:80)
          at output_archive.test.provaJDOM.main(provaJDOM.java:55)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:616)
          at com.sun.star.lib.loader.Loader.main(Loader.java:141)

when MemoryUtil.deepMemoryUsageOf(Object) is called

So it seems that this is not the correct way to pass the argument to the jvm, but we can't figu开发者_如何学Gore out what to do.

Thank you for the help :)


I think you probably are passing the JVM arg successfully - you could try running ant with -verbose to confirm. It seems likely that the issue though is with the the use of the jar attribute.

According to the Ant java task docs (see also):

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

So, you'd have to have ensured that the classmexer.jar classes were included in the application jar for them to be found.

One other point: the jvmargs attribute is deprecated - you should use a nested jvmarg element instead.

An approach you might consider is to add your application jar to the classpath (along with classmexer.jar) and call the main class as specified in the jar manifest directly. Something like this:

<java classname="...YourMainClass" failonerror="true" fork="true">
    <jvmarg value="-javaagent:classmexer.jar" />
    <classpath>
        <!-- other stuff here maybe -->
        <pathelement location="path_to_classmexer/classmexer.jar" />
        <pathelement location="${OUT_DIR}/${FILE_NAME}.jar" />
    </classpath>
</java>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜