简体   繁体   English

使用maven exec插件传递命令行参数javaagent

[英]Pass command-line argument javaagent with maven exec plugin

I have a caching app in Java and I need to put objects of different size in cache. 我在Java中有一个缓存应用程序,我需要在缓存中放置不同大小的对象。 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. 问题是我真的不知道如何计算自定义对象的大小,我找到了解决方案 - 使用该库: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. 要使用库运行程序,我需要指定命令行参数-javaagent。 So, how can I do it if I'm using maven??? 那么,如果我使用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.


PS I know, that such kind of question already exists, but it has no proper answer. PS我知道,这样的问题已经存在,但它没有正确的答案。

On a Linux/Unix machine the "mvn" command will use a shell variable "MAVEN_OPTS" to pass in options. 在Linux / Unix机器上,“mvn”命令将使用shell变量“MAVEN_OPTS”来传入选项。 This is useful if you want to give Maven more memory. 如果你想给Maven更多的内存,这很有用。 In your .profile or .bash_profile put a line like this in: 在.profile或.bash_profile中添加如下行:

export MAVEN_OPTS=-javaagent 导出MAVEN_OPTS = -javaagent

On windows: 在Windows上:

in shell (cmd.exe) type "set MAVEN_OPTS=..." 在shell(cmd.exe)中键入“set MAVEN_OPTS = ...”

or 要么

add MAVEN_OPTS to your environment 将MAVEN_OPTS添加到您的环境中

On NetBeans: 在NetBeans上:

In ~/.netbeans/6.5/, create etc/netbeans.conf. 在〜/ .netbeans / 6.5 /中,创建etc / netbeans.conf。 Add your environment variables there, eg: 在那里添加您的环境变量,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM