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="<?xml version="1.0" encoding="UTF-8"?><runtimeClasspathEntry externalArchive="C:/Dokumente und Einstellungen/050967/.m2/repository/com/google/gwt/gwt-dev/2.0.3/gwt-dev-2.0.3.jar" path="3" type="2"/>"/>
...
</listAttribute>
Or is there a way to include an environment variable (e.g. Windows' %USERPROFILE% could help)?
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_REPOand 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 isMYVARand the JAR file is undersubdir/myfile.jar, you should type${env_var:MYVAR}/subdir/myfile.jar.
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="<?xml version="1.0" encoding="UTF-8"?><runtimeClasspathEntry externalArchive="${${maven.repo.local}}/com/google/gwt/gwt-dev/2.0.3/gwt-dev-2.0.3.jar" path="3" type="2"/>"/>
...
</listAttribute>
Then setup filtering in pom.xml for your configuration file so ${maven.repo.local} will be replaced with property value.
来源:https://stackoverflow.com/questions/3557369/how-to-use-variables-for-classpath-definition-in-eclipse-launch-configurations