Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the value of eclipse classpath variable M2_REPO in run configuration VM arguments

In the run configuration of eclipse, you are provided with a set of default variables that you can use in the VM arguments, like container_path and env_var.
What I want to access is a classpath variable, M2_REPO, but can't see a way of doing this. I need to specify a javaagent in the VM arguments, which requires a path to a jar file. This jar file lives in the maven repository, but I can't find a way of specifying the path to the maven repository using the already configured M2_REPO Classpath variable (configured in windows->preferences->java->Build Path->Classpath variable).
What I would like to do is use this as my VM arguments but can't because classpath_var isn't a real variable.

-javaagent:${classpath_var:M2_REPO}/org/apache/openjpa/openjpa/2.1.0/openjpa-2.1.0.jar

Is there any other way of accessing the value of M2_REPO in VM arguments?

like image 914
httPants Avatar asked Nov 25 '11 05:11

httPants


People also ask

How to check Eclipse classpath?

In Eclipse, go to Window > Preferences > Java > Build Path > Classpath Variables. Click New, enter the following information and click OK.

Where are Eclipse classpath variable stored?

If you're asking where Eclipse stores the values you put in the classpath preferences page, then it's under the . metadata directory, probably in the plugins/org. eclipse.

What is classpath variable in Eclipse?

The CLASSPATH environment variable tells the Java Virtual Machine and other Java applications where to find the class libraries, including user-defined class libraries.


1 Answers

This isn't exactly what you asked for, but it worked for us as a way of sharing a codebase and not having hard coded paths in our run configurations. Rather than using a classpath variable, use a string substitution variable (configured in windows -> preferences -> run/debug -> String Substitution). Set it to the same path as the value of M2_REPO and save. Using the above example if your string substitution variable name was also M2_REPO, the VM Argument would be

-javaagent:${M2_REPO}/org/apache/openjpa/openjpa/2.1.0/openjpa-2.1.0.jar

To be even more clear, I would personally just create an openjpa_2_1_0_agent string substitution variable that went directly to your open jpa jar.

like image 53
M Nilson Avatar answered Sep 23 '22 00:09

M Nilson