Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JDT New Maven Project(JDT New Maven Project)
JDT New Maven Project [message #893895] Thu, 05 July 2012 20:54 Go to next message
Mike M is currently offline Mike M
Messages: 2
Registered: July 2012
Junior Member
I am creating a new project wizard and am able to create a new java project (org.eclipse.jdt.core.IJavaProject) without a problem. I am at the point where I am trying to add Maven nature to the project, but things aren't looking quite right. Does anyone know of any tutorials or examples walking through creating a new Maven project programmatically? The .classpath file it is creating looks correct:
<?xml version="1.0" encoding="UTF-8"?>
	<classpathentry kind="src" path="src/main/java"/>
	<classpathentry kind="src" path="src/main/resources"/>
	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
	<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
			<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
	<classpathentry kind="output" path="target/classes"/>

Instead of seeing Maven Dependencies in the Java build path section of the project, it shows as org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER. Also, in the package explorer, it is only showing the JRE container and doesn't show Maven dependencies at all.

Here are some lines i hacked together to attempt getting maven nature:

String[] natures = {JavaCore.NATURE_ID, IMavenConstants.NATURE_ID};
desc.setNatureIds(natures); //desc is IProjectDescption
proj.setDescription(desc, new SubProgressMonitor(monitor, 1000)); //proj is IProject
IJavaProject javaProject = JavaCore.create(proj);
IPath mavenContainer = new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER");
IClasspathAttribute[] mavenClassPathAtr = {JavaCore.newClasspathAttribute("org.eclipse.jst.component.dependency", "/WEB-INF/lib")};
entries.add(JavaCore.newContainerEntry(mavenContainer, null, mavenClassPathAtr, false));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject.getPath().append("target/classes"), new SubProgressMonitor(monitor, 1000));

Any ideas are greatly appreciated.
Re: JDT New Maven Project [message #893898 is a reply to message #893895] Thu, 05 July 2012 21:20 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1024
Registered: July 2009
Senior Member
a stupid question: do you have m2e installed? If not org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not mean much to the JDT Smile

Re: JDT New Maven Project [message #893907 is a reply to message #893895] Thu, 05 July 2012 23:08 Go to previous message
Mike M is currently offline Mike M
Messages: 2
Registered: July 2012
Junior Member
Yes, m2e is installed. I'm using MyEclipse Blue which is packaged with it.
Previous Topic:change modifier of a variable
Next Topic:Phantom syntax errors
Goto Forum:

Current Time: Sun Oct 26 09:38:07 GMT 2014

Powered by FUDForum. Page generated in 0.01789 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software