Google App Engine 跨项目代码重用
我刚刚开始学习 Java、GAE 等。
我已经在 Eclipse IDE 中启动了一个使用 GAE 的项目。我正在使用 GAE、Jersey、JAXB 等创建一个网站和一个 RESTful Web 服务,这包括项目的 src 目录中的几个代码文件,用于处理 HTTP 请求、将数据保存到数据存储等。我在war 目录中的 html 文件、jsp 等是我拥有的任何 Web UI。
我想为第二个网站启动第二个项目,但我不想在新项目中重新创建或复制现有的 java 代码,我希望能够重用第一个项目中的代码行,并且在维护该代码时它在所有项目中都会更新。
在 .net 开发中,这很简单,因为所有内容都会编译成一组程序集(dll 文件),我可以在许多项目中重用它们。一旦我进行更改并编译重用的代码,引用这些程序集的所有项目都会自动具有新版本。
在GAE开发中如何实现类似的代码复用?
I am just starting out learning Java, GAE etc.
I have started a project with the GAE in the Eclipse IDE. I am creating a website AND a RESTful web service using GAE, Jersey, JAXB etc This includes several code files in the src directory of the project which handle the HTTP requests, persist data to the data store etc. I also have several files in the war directory html files, jsp etc which are any web UI I have.
I want to start a second project for a second website but I don't want to have to recreate or copy the existing java code in the new project I want to be able to reuse the codeline from the first project and as I maintain that code it is updated in all projects.
In .net development this is simple because everything compiles up into a set of assemblies (dll files) that I can reuse in many projects. As soon as I make changes and compile up the reused code all the projects referencing those assemblies automatically have the new version.
How can I achieve similar code reuse in GAE development?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你在使用 Eclipse 吗?在这种情况下,您可以(在您的项目上)执行 new->folder,然后选择高级选项,检查文件系统中文件夹的链接。将其链接到另一个项目中的源(子)文件夹。
这样,您甚至可以在两个项目中编辑此共享代码,并且当您编译其中一个项目时,编译的类将位于(该特定项目的)war 包中。
注意:我实际上采用了“通用”代码并将其放入一个单独的项目中。
[编辑:随后通过项目->构建路径->源将此文件夹指定为“源文件夹”]
Are you using Eclipse? In that case, you could do (on your project) new->folder and then select advanced options, check link to folder in the file system. Link this to your source (sub)folder in another project.
This way, you can even edit this shared code in both projects, and when you compile one of these projects, the compiled classes will be in your war package (of that particular project).
Note: I actually took the 'common' code and put it into a seperate project.
[Edit: subsequently designate this folder as a 'source folder' via project->build path->source]
是的,java 仍然没有模块系统,这使得重用比 .net 稍微困难一些,但是您可以创建两个项目并重用 .jar 或进行 eclipse 引用。
需要考虑的一件事是,某些库(例如 jersey)可能需要额外的步骤才能重用,而不仅仅是设置类路径。请参阅 JAX-RS REST 服务作为库
如果您想将你的灵魂从 .jar 地狱中拯救出来,使用 Maven :)
yes, java still does not have a module system and that makes reuse a little harder than in .net, but you can create two projects and reuse the .jar or make eclipse references.
One thing to consider is that some libraries, like jersey, may require aditional steps to reuse, not only setting the classpath. see JAX-RS REST Services as a library
And if you want to save your soul from .jar hell, use maven :)