Eclipse: share code among multiple projects

若如初见. 提交于 2019-11-29 17:50:39

问题


I have different projects in Eclipse (java me midlets) which all need to share code. Currently I duplicate things, but this is not ideal. What is the best way to do this? Thanks!

EDIT: I tried to add another project in the Build Path, but then, when running the Midlet in a Emulator, I get the following ERROR:

Uncaught exception java/lang/NoClassDefFoundError: clientlibrary/ov9292/Ov9292Client.


回答1:


You can create a Java Project which will contain the shared code and have other projects reference it. When deploying you can pack this project as a separate jar file.




回答2:


Have you considered creating a shared library instead of just shared code? Export to a JAR file and import that into the dependent products.

The up-side of doing this (vs just referencing the shared code) is that it will force you into more rigorous practices. You will now have an API that must be maintained and versioned cleanly. It will also make you better consider what's shared and what's not. This will likely lead to better encapsulation, and hopefully better testing.

I'm not saying you lack these things now. Just that creating a common-foo.jar can often encourage better habits.



来源:https://stackoverflow.com/questions/4595452/eclipse-share-code-among-multiple-projects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!