|
Re: Adding project reference programmatically. [message #227013 is a reply to message #227006] |
Wed, 19 November 2008 10:06 |
Eclipse User |
|
|
|
Originally posted by: subs._nospam_consertum.com
This is how I do it:
private void setDependencies(IProject project, IProject[] dependsOn) {
for (int i = 0; i < dependsOn.length; i++) {
IProject refProj = dependsOn[i];
try {
IProjectDescription desc = project.getDescription();
IProject[] refs = desc.getReferencedProjects();
IProject[] newRefs = new IProject[refs.length + 1];
System.arraycopy(refs, 0, newRefs, 0, refs.length);
newRefs[refs.length] = refProj;
desc.setReferencedProjects(newRefs);
project.setDescription(desc, monitor);
} catch (CoreException e) {
}
}
}
padamev297 wrote:
> 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
>
--
Derek
|
|
|
|
Re: Adding project reference programmatically. [message #1101622 is a reply to message #227026] |
Wed, 04 September 2013 18:25 |
Kevin Regan Messages: 33 Registered: May 2013 |
Member |
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03760 seconds