Search code examples
eclipseeclipse-jdt

Editing workspace source associated with jar file in same workspace


I have a project A in eclipse whose code is compiled into a jar and used by a separate project B. I have associated the jar to the workspace project A code. When I run project B I get stack trace on the console which references the jar. When clicking on the references the correct file opens up from project A but as read only, I want to edit this file and fix my code. What I end up doing is open the file manually using search typing the name or navigating to it in the package explorer and then edit it. I mean file is there in the project in my workspace, why is it not editable? Is there any way around it?


Solution

  • To open a Java file of project A with the Java Editor (editable) instead of with the Java Class Viewer (read-only) when you are in your project B, you have to do the following:

    1. Right-click project B and choose Properties
    2. In Java Build Path, tab Projects click Add...
    3. Select project A and click OK
    4. In Java Build Path, tab Order and Export move project A to the top by selecting project A and clicking UP several times
    5. Click Apply and Close to close properties dialog of project B

    I would recommend convert project A to a plug-in project. A plug-in JAR can be used in both, a plain Java and an OSGi application. The code would be more modular and changes in project A would not require a JAR file to be updated in project B.