Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [m2e-dev] [m2e-users] JavaLaunchDelegate : add maven dependencies to classpath

Thank you Igor,
Your tip works. I just had to extend MavenRuntimeClasspathProvider to accept my type of run and as it is sort of test I just added:

@SuppressWarnings("restriction")
public class SicMavenRuntimeClasspathProvider extends MavenRuntimeClasspathProvider {

protected int getArtifactScope(ILaunchConfiguration configuration) throws CoreException {
return IClasspathManager.CLASSPATH_TEST;
}
}

Also I needed to set IJavaLaunchConfigurationConstants before launching:

ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
wc.doSave();
        
SicMavenRuntimeClasspathProvider.enable(project);

Thanks a lot,

Marek





2014-05-07 23:57 GMT+02:00 Igor Fedorenko <igor@xxxxxxxxxxxxxx>:
This is more complicated than adding project output and test output
directories. Maven runtime classpath calculation rules are quite
different from what JDT uses by default, so you need to fully replace
both classpath and source lookup path calculation. The easiest way to do
this is by calling MavenRuntimeClasspathProvider#enable on your launch
configuration.

Also, this is question belongs to m2e-dev mailing list, please send any
followup question there.

--
Regards,
Igor


On 2014-05-07, 16:58, Marek Jagielski wrote:
Hi,
I created MyJavaLaunchDelegate that extends JavaLaunchDelegate for
running my own type of files. Files are inside JavaProject with m2e
nature. I would like to add maven dependencies to the classpath of my run.

As I know I have to put them into:

@Override
public String[] getClasspath(ILaunchConfiguration configuration) throws
CoreException {
List<String> extendedClasspath = new ArrayList<>();
Collections.addAll(extendedClasspath, super.getClasspath(configuration));
IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(configuration.getAttribute(SystemInCloudLaunchConfigurationConstants.ATTR_PROJECT_NAME,
""));
IPath path = project.getLocation();
extendedClasspath.add(path.toString() + "/target/test-classes");
extendedClasspath.add(path.toString() + "/target/classes");
...
return extendedClasspath.toArray(new String[extendedClasspath.size()]);
}

I am adding already classes of my project.
I will be thankful for any tips.

Marek


--
Marek Jagielski



_______________________________________________
m2e-users mailing list
m2e-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/m2e-users

_______________________________________________
m2e-users mailing list
m2e-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/m2e-users



--
Marek Jagielski
+48 513 402 596

Back to the top