10

In our project we use Eclipse launch configurations which are under version control to be shared with all developers. Now it is necessary to include an external archive to a launch configuration file's classpath. Fortunately the required archive is in every developer's local Maven repository.

I already found out that there is a classpath variable called M2_REPO which references to the local Maven repository (being valid for any developer).

But how to use this variable in the following classpath definition to replace the absolute path?

<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
    ...
    <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;runtimeClasspathEntry externalArchive=&quot;C:/Dokumente und Einstellungen/050967/.m2/repository/com/google/gwt/gwt-dev/2.0.3/gwt-dev-2.0.3.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;"/>
    ...
</listAttribute>

Or is there a way to include an environment variable (e.g. Windows' %USERPROFILE% could help)?

informatik01
  • 16,038
  • 10
  • 74
  • 104
thommyslaw
  • 532
  • 1
  • 4
  • 13

2 Answers2

22

Edit your launch configuration. Go to the "classpath" tab. Focus on "User Entries". Click the "Advanced" button.

  • To add an entry based on a classpath variable, select Add classpath variable and click OK. A dialog will open. Focus on M2_REPO and click the "Extend" button. Select your JAR file.
  • To add an entry based on a system environment variable, select Add variable string, and in the editbox below, type: ${env_var:your-environment-variable-name}/path-to-jar. For example, if your system environment variable is MYVAR and the JAR file is under subdir/myfile.jar, you should type ${env_var:MYVAR}/subdir/myfile.jar.
Isaac
  • 16,458
  • 5
  • 57
  • 81
  • Is it possible to do the same with the M2_REPO variable? If i do what you say in the first point it doesn't keep the variable expression in the launch file instead it replaces it with the full path of the JAR which works only on my computer. Editing the file by hand is not a solution either because Eclipse adds my path on the first launch aswell. Is there any way to get around this? I make a new question from this. – NagyI Sep 19 '13 at 14:41
  • Here is it: http://stackoverflow.com/questions/18897954/how-to-keep-m2-repo-variable-dynamic-in-aspect-path-of-an-eclipse-java-aspectj-r – NagyI Sep 19 '13 at 14:52
  • If it doesn't keep the `M2_REPO` variable in the launch configuration, then you're (possibly) doing it wrong or you're using a buggy Eclipse. I just did this myself here and it works fine: the ".launch" file contains a variable-based expression. – Isaac Sep 19 '13 at 18:02
  • I've did exactly what you described in your post. And i'm using the latest Spring Tool Suite version (3.3.0) which is based on Kepler. As i've described in the linked question the unresolved expression appears correctly until i close the configuration dialog. If i reopen it again it's replaced with the full path. – NagyI Sep 20 '13 at 09:12
  • Hmmm. I'm not sure what Spring Tool Suite is - never used it. I just know that this works perfectly when using plain vanilla Kepler with M2E. Which M2E version are you using? – Isaac Sep 20 '13 at 18:24
0

You could load that value from maven properties.

Maven stores repository path in maven.repo.local property.

Place ${maven.repo.local} into your configuration file.

<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
    ...
    <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;runtimeClasspathEntry externalArchive=&quot;${${maven.repo.local}}/com/google/gwt/gwt-dev/2.0.3/gwt-dev-2.0.3.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;"/>
    ...
</listAttribute>

Then setup filtering in pom.xml for your configuration file so ${maven.repo.local} will be replaced with property value.

amra
  • 16,125
  • 7
  • 50
  • 47
  • 2
    Unfortunately that does not work. When trying to run my launch file from Eclipse's "Run..." menu I get an error message like "The archive ${${maven.repo.local}}/com/google/... does not exist". Obviously the variable is not resolved. Any other ideas? – thommyslaw Aug 30 '10 at 06:39