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!
我在Eclipse中有不同的项目(java me midlet),它们都需要共享代码。目前我复制东西,但这并不理想。最好的方法是什么?谢谢!
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:
编辑:我尝试在构建路径中添加另一个项目,但是当在模拟器中运行Midlet时,我得到以下错误:
Uncaught exception java/lang/NoClassDefFoundError: clientlibrary/ov9292/Ov9292Client.
java / lang / NoClassDefFoundError异常:clientlibrary / ov9292 / Ov9292Client。
2 个解决方案
#1
9
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.
您可以创建一个Java项目,该项目将包含共享代码,并让其他项目引用它。在部署时,可以将这个项目打包为一个单独的jar文件。
#2
8
Have you considered creating a shared library instead of just shared code? Export to a JAR file and import that into the dependent products.
您是否考虑过创建一个共享库而不仅仅是共享代码?导出到JAR文件并将其导入到相关产品中。
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.
这样做的好处是,它将迫使您进行更严格的实践。现在,您将拥有一个API,它必须得到维护并进行版本控制。它还能让你更好地考虑哪些是共享的,哪些不是。这可能会导致更好的封装和更好的测试。
I'm not saying you lack these things now. Just that creating a common-foo.jar can often encourage better habits.
我不是说你现在缺少这些东西。就是创建一个通用foo。jar常常能鼓励更好的习惯。
#1
9
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.
您可以创建一个Java项目,该项目将包含共享代码,并让其他项目引用它。在部署时,可以将这个项目打包为一个单独的jar文件。
#2
8
Have you considered creating a shared library instead of just shared code? Export to a JAR file and import that into the dependent products.
您是否考虑过创建一个共享库而不仅仅是共享代码?导出到JAR文件并将其导入到相关产品中。
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.
这样做的好处是,它将迫使您进行更严格的实践。现在,您将拥有一个API,它必须得到维护并进行版本控制。它还能让你更好地考虑哪些是共享的,哪些不是。这可能会导致更好的封装和更好的测试。
I'm not saying you lack these things now. Just that creating a common-foo.jar can often encourage better habits.
我不是说你现在缺少这些东西。就是创建一个通用foo。jar常常能鼓励更好的习惯。