Search code examples
eclipseclasspathmaven-3openjpa

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?


Solution

  • 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.