How to reference a different Java project in Eclipse

后端 未结 2 935
渐次进展
渐次进展 2020-12-02 18:42

I have Project1 and Project2. Project1 is dependent of Project2. I am sort of tired that every time I make some code changes in Project2, I have to Export Project2 JAR file,

相关标签:
2条回答
  • 2020-12-02 19:28

    In Eclipse, when a Java project is built, every .java file from source folders is compiled and the .class file is saved into an output folder. The non-java files from the source folder are copied unchanged to the corresponding folder hierarchy in the output folder.

    When adding "referenced projects" within a workspace in Eclipse via Java Build Path, i.e. adding Project2 to Project1's build path, what you are actually doing is telling the project builder to use the output folder of Project2 when building Project1 (NOTE: not only the output folder, but also exported libraries).

    So if the answer from kozyr does not work for you, check the "output folder" configuration of Project2.

    0 讨论(0)
  • 2020-12-02 19:33

    Right click on Project1, then click on Properties. In the dialog that comes up, select Java Build Path, and then click on the Projects tab. There, add Project2 to the build path.

    If Project1 is a web app, you need to make sure your Deployment Assembly (same Properties UI) has Project2 there as well.

    0 讨论(0)
提交回复
热议问题