Adding project reference programmatically. [message #227006] |
Wed, 19 November 2008 04:53  |
Eclipse User |
|
|
|
hi
Can anybody help me on how to add project reference(dependency on another
project) programmatically.
I found out that ICConfigurationDescription.setReferenceInfo() is the way
to do the same, but didn't get any more help.
Thanks in advance
Padam
|
|
|
|
|
Re: Adding project reference programmatically. [message #1101622 is a reply to message #227026] |
Wed, 04 September 2013 14:25   |
Eclipse User |
|
|
|
I have programmatically created two projects - one which references the other in the way described above - but it does not solve the problem I expected it to solve.
Basically, project #2, which now references project #2 is trying to import and use classes that are defined in project #1. Even with this project reference set up it complains that it cannot find the class. I believe what I need is the equivalent of going to the project #2, right clicking property and going to Java Build Path, clicking on Projects tab and adding project #1.
I cannot figure out how to set this up programmitically however. This is what I have tried:
IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(m_nodeName);
description.setLocationURI(new File(m_projectLocation).toURI());
if (m_parentProject != null) {
assert (m_parentProject.getProject() != null) : "Cannot build project if parent project is not built";
description.setReferencedProjects(new IProject[] { m_parentProject.getProject() } );
// try to get the default build configuration
IBuildConfiguration parentBuildConfig = m_parentProject.getProject().getBuildConfig("");
description.setBuildConfigReferences("", new IBuildConfiguration[] { parentBuildConfig});
}
description.setNatureIds(new String[] {JavaCore.NATURE_ID, JavaNodeProjectNature.NATURE_ID});
createProject(m_nodeName, description);
createProject function:
protected void createProject(String projectName, IProjectDescription description) throws CoreException, ProjectExistsException {
m_project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (m_project.exists()) {
throw new ProjectExistsException("Project " + projectName + " already exists");
}
m_project.create(description, EclipseSupport.getProgressMonitor());
m_project.open(EclipseSupport.getProgressMonitor());
}
According to the documentation I believe I am adding the parent projects default build configuration (default build configuration always has empty string name) as a referenced build configuration to the child projects default build configuration.
I have also tried doing it after the project is created (which is done in a separate function the standard way) by doing project.getDescription, adding the build config, and then project.setDescription - but that doesn't work either.
Does anyone know what, if anything, I am doing wrong?
Thanks for your help.
|
|
|
Re: Adding project reference programmatically. [message #1103296 is a reply to message #1101622] |
Fri, 06 September 2013 11:36  |
Eclipse User |
|
|
|
In case anyone looks here trying to figure out the problem I mentioned above - the build configuration is apparently something else - in order to get a project dependency (i.e. build path in properties for a project as opposed to project references addressed in the first few posts of this thread), you just simply use the old classpath entry method:
IClasspathEntry projectDependency = JavaCore.newProjectEntry(projectLocation);
project.setRawClasspath(new IClasspathEntry[] { projectDependency }); // or something like that whatever...
|
|
|
Powered by
FUDForum. Page generated in 0.03712 seconds