Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not a full answer but will help you out in your thinking of what you need to code. </p> <p>Create a poup menu contribution to projects that have a plugin nature with a label somthing like "Add Java Projects To Class Path". </p> <p>In your action or command handler this is the code I am thinking that needs to be in place: </p> <ul> <li><p>Get a reference to your selected plugin project. </p></li> <li><p>Create a list that will contain a list of all open java projects in the workspace. </p></li> <li><p>Make sure you add <code>org.eclipse.core.resources</code> to you bundle dependencies. </p></li> <li><p>Get the list of Projects in the workspace by calling </p> <pre><code>ResourcesPlugin.getWorkspace().getRoot().getProjects(); </code></pre></li> <li><p>For each project call <code>if(project.getNature("org.eclipse.jdt.core.javanature")</code> does not return null. </p></li> <li><p>Add the project to your list of open java projects. Also make sure you are not adding the plugin project you have selected as it also has a java nature. If you want to only add java projects but not plugin projects you will need to do an additional check if it has a plugin nature and if so exclude it. </p></li> </ul> <p>Now the fun part. Get a reference to your plugin project which you should have if you are implementing a command handler or <code>IWorkbenchWindowActionDelegate</code> interface. </p> <p>Because a plugin project also has a java nature you can do this once you have a reference to your plugin IProject </p> <pre><code>IJavaProject javaProject = JavaCore.create(mySelectedProject); IClasspathEntry[] entries = javaProject.getRawClasspath(); List&lt;IClassPathEntry&gt; newEntries - new ArrayList&lt;IClassPathEntry&gt;(); // for each IProject in your active java project list. foreach(IProject project: activeProjects) { IJavaProject currentProject = JavaCore(project); IPath srcPath= currentProject.getPath().append("target/generated-sources"); IClasspathEntry srcEntry= JavaCore.newSourceEntry(srcPath, null); newEntries.add(srcEntry); } // after processing each open java project we found and adding a new IClassPathEntry we now set the // updated class path entries on the selected plugin/java project. newEntries.add(entries); IClassPathEntry[] newEntryArray = newEntries.toArray(new IClassPathEntry[newEntries.size()]); javaProject.setRawClassPath(newEntries, null) </code></pre> <p>Now the part I don't fully know: saving your changes to disk, take a look at this post: <a href="https://stackoverflow.com/questions/12878710/saving-modified-ast-in-a-new-file-with-eclipse-plugin">Saving modified AST in a new file with eclipse plugin</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload