如何在eclipse项目之间共享网页内容 [英] How to share web content between eclipse projects

查看:144
本文介绍了如何在eclipse项目之间共享网页内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然J2EE模块引用功能允许您创建常见的Java库项目,但我无法找到一种整洁的方式来完成Web内容。

While the J2EE module reference feature allows your to create common Java library projects, I can't find a neat way to do this for web content.

我有常用的JSP,CSS文件,JavaScript库以及我想在多个动态Web项目中使用的描述符片段,以便我们只在一个地方编辑这些文物,但会导出到每个Dynamic WebProject WAR文件中。

I have common JSPs, CSS files, JavaScript libraries and even descriptor fragments that I would like to use across a number of Dynamic Web Projects, so that these artefacts are edited i only one place, but will be exported into each of the Dynamic WebProject WAR files.

我很惊讶,我没有找到一种方法来提升网络空间中的可重用性,而无需编写自己的脚本并挂接到导出过程中。

I am surprised that I can't find a way to promote reusability in the web space without writing my own scripts and hooking into the export process.

有没有办法做到这一点?
谢谢。
Matt。

Is there a way to do this? Thanks. Matt.

推荐答案

我一直在摔跤同样的问题很久,最后偶然发现好的解决方案:链接文件夹。这是一个类似于符号链接的Eclipse功能,它允许您将单个物理文件夹映射到多个项目中。该解决方案的好处在于它不需要任何特殊的构建步骤,因此Eclipse可以自动将更改部署到本地Tomcat服务器进行测试。

I've been wrestling with the same problem for a long time, and finally stumbled onto a good solution: "Linked Folders". This is an Eclipse feature that works similarly to symlinks -- it allows you to map a single physical folder into multiple projects. The nice thing about this solution is that it doesn't require any special build steps, so Eclipse can automatically deploy changes to your local Tomcat server for testing.

我的配置是如下所示:我有一个名为SharedContent的Eclipse项目。在WebContent目录中,是一个子目录shareRoot。所有可重用的文件 - .jsp,.css等位于SharedContent / WebContent / shareRoot下的某个位置。这是一个动态Web项目,所以所有适当的编辑器都被启用,但我从来没有实际构建或部署它。

My configuration is as follows: I have an Eclipse project named "SharedContent". Inside the WebContent directory, is a subdirectory "shareRoot". All reusable files -- .jsp, .css, etc. -- are located somewhere under SharedContent/WebContent/shareRoot. This is a Dynamic Web Project so that all of the appropriate editors are enabled, but I never actually build or deploy it.

在我的其他项目中,我添加一个链接的文件夹指向shareRoot。在Eclipse 3.6中,步骤是:

In my other projects, I add a Linked Folder pointing to shareRoot. In Eclipse 3.6, the steps are:


  1. 在包资源管理器中,右键单击需要的项目的WebContent目录包含可重复使用的文件。

  1. In the Package Explorer, right-click on the WebContent directory of the project that needs to include the reusable files.

选择新建 - >文件夹。

Select New -> Folder.

高级>>>按钮

选择链接到备用位置(链接文件夹)单选按钮。

Select the "Link to alternate location (Linked Folder)" radio button.

在刚刚下的文本框中,单击浏览。

In the textbox just under this, click Browse.

在源代码树中,导航到SharedContent / WebContent / shareRoot。然后单击确定/打开/完成按钮,直到所有对话框都消失。

In your source tree, navigate to SharedContent/WebContent/shareRoot. Then click OK/Open/Finish buttons until all the dialogs go away.

共享内容现在映射到项目。令人烦恼的是,在引用这些文件时,必须在URL中包含shareRoot /,但您可以使用自己喜欢的URL重写过滤器来解决此问题。

The shared content is now mapped into your project. Annoyingly, you have to include "shareRoot/" in the URL when referencing these files, but you can work around this using your favorite URL rewriting filter.

您可以使用Java源代码树中的类似技巧将Java文件映射到多个项目中。我已经开始这样做,而不是将共享代码构建到.jar文件中,因为它避免了每次要测试本地Tomcat服务器上的更改时重建.jar的需要。

You can use a similar trick in the Java source tree to map Java files into multiple projects. I've started doing that, instead of building the shared code into a .jar file, because it avoids the need to rebuild the .jar every time you want to test a change in your local Tomcat server.

这篇关于如何在eclipse项目之间共享网页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆