Eclipse plugin> java project like

i created a new plugin in eclipse that adds a new project entry, which can then be used to add a new project.

however, when I go to the project properties, I get the following:

my project properties

instead of this:

java project properties

So my question is how to make my project also include all java things (for example: Java build path, etc.), since I want this project to be based on the default java project.

how am i doing the project now (code):

@Override public boolean performFinish() { if (project != null) { return true; } final IProject projectHandle = wizardPage.getProjectHandle(); URI projectURI = (!wizardPage.useDefaults()) ? wizardPage.getLocationURI() : null; IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName()); desc.setLocationURI(projectURI); WorkspaceModifyOperation op = new WorkspaceModifyOperation() { protected void execute(IProgressMonitor monitor) throws CoreException { createProject(desc, projectHandle, monitor); } }; try { getContainer().run(true, true, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { Throwable realException = e.getTargetException(); MessageDialog.openError(getShell(), "Error", realException.getMessage()); return false; } project = projectHandle; if (project == null) { return false; } BasicNewProjectResourceWizard.updatePerspective(config); BasicNewProjectResourceWizard.selectAndReveal(project, workbench.getActiveWorkbenchWindow()); return true; } 

edit ***

ok, so the solution is to add a face to the project. if I do it manually after creating a new project through my plugin - from the right click, the project properties - it works. How to add this facet programmatically?

edit 2 ***

ok, so this is done through:

 description.setNatureIds 

but not really.

this is what the project looks like when I manually add a facet to it (and so I want it to look):

enter image description here

and this is how it looks when I add the nature identifier "org.eclipse.jdt.core.javanature" programmaticaly (not the way I want it)

enter image description here

, therefore ... how to fix it? Do I need a different nature?

here is the contents of the .project file when I manually add the facet:

 <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>test</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.wst.common.project.facet.core.builder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription> 

a .classpath file is also added (when adding a face manually, but there is no such file when it is added programmatically):

 <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> <attributes> <attribute name="owner.project.facets" value="java"/> </attributes> </classpathentry> <classpathentry kind="output" path="bin"/> </classpath> 

here is also my createProject () method:

 private void createProject(IProjectDescription description, IProject proj, IProgressMonitor monitor) throws CoreException, OperationCanceledException { try { monitor.beginTask("", 2000); proj.create(description, new SubProgressMonitor(monitor, 10)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } proj.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 10)); IContainer container = (IContainer) proj; [ *** ] } finally { monitor.done(); } } 
+4
source share
2 answers

Your created project lacks Java and WST natures and developers.

 desc.setNatureIds(new String[] {org.eclipse.jdt.core.JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature"}); org.eclipse.core.resources.ICommand[] commands = new ICommand[] { desc.newCommand(), desc.newCommand }; commands[0].setBuilderName(org.eclipse.jdt.core.JavaCore.BUILDER_ID); commands[1].setBuilderName("org.eclipse.wst.common.project.facet.core.builder"); desc.setBuildSpec(commands); createProject(...) { ... proj.create(description, ...); IFolder srcFolder = proj.getFolder(new Path("src")); srcFolder.create(false, true, new NullProgressMonitor()); org.eclipse.jdt.core.IJavaProject javaProject = org.eclipse.jdt.core.JavaCore.create(proj); org.eclipse.jdt.core.IClasspathEntry src = JavaCore.newSourceEntry(srcFolder.getFullPath()); IClasspathEntry jre = JavaCore.newContainerEntry(new Path(org.eclipse.jdt.launching.JavaRuntime.JRE_CONTAINER), new IAccessRule[0], new IClasspathAttribute[] { JavaCore.newClasspathAttribute("owner.project.facets", "java")}, false); IClasspathEntry[] entries = new IClasspathEntry[] { src, jre }; javaProject.setRawClasspath(entries, proj.getFullPath().append("bin"), new NullProgressMonitor()); 

Cheers, Max

+5
source

Without changing the plugin, you can add the Java facet to a new project. Look at the “Project Boundaries” setting, if necessary, convert the project to a facet form and select Java as the facet to use. This should include the settings you are looking for.

+1
source

All Articles