简体   繁体   English

如何在eclipse项目之间共享web内容

[英]How to share web content between eclipse projects

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. 虽然J2EE模块引用功能允许您创建常见的Java库项目,但我找不到一种巧妙的方法来为Web内容执行此操作。

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. 我有一些常见的JSP,CSS文件,JavaScript库甚至描述符片段,我想在多个动态Web项目中使用它们,这样这些文件只在一个地方被编辑,但会被导出到每个Dynamic WebProject WAR中文件。

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. 我很惊讶我没有找到一种方法来提升网络空间的可重用性,而无需编写我自己的脚本并挂钩到导出过程。

Is there a way to do this? 有没有办法做到这一点? Thanks. 谢谢。 Matt. 马特。

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. 这是一个与符号链接类似的Eclipse功能 - 它允许您将单个物理文件夹映射到多个项目。 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. 这个解决方案的好处是它不需要任何特殊的构建步骤,因此Eclipse可以自动将更改部署到本地Tomcat服务器以进行测试。

My configuration is as follows: I have an Eclipse project named "SharedContent". 我的配置如下:我有一个名为“SharedContent”的Eclipse项目。 Inside the WebContent directory, is a subdirectory "shareRoot". 在WebContent目录中,是一个子目录“shareRoot”。 All reusable files -- .jsp, .css, etc. -- are located somewhere under SharedContent/WebContent/shareRoot. 所有可重用文件 - .jsp,.css等 - 位于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. 这是一个动态Web项目,因此启用了所有适当的编辑器,但我从未实际构建或部署它。

In my other projects, I add a Linked Folder pointing to shareRoot. 在我的其他项目中,我添加一个指向shareRoot的链接文件夹。 In Eclipse 3.6, the steps are: 在Eclipse 3.6中,步骤如下:

  1. In the Package Explorer, right-click on the WebContent directory of the project that needs to include the reusable files. 在Package Explorer中,右键单击需要包含可重用文件的项目的WebContent目录。

  2. Select New -> Folder. 选择新建 - >文件夹。

  3. Click the "Advanced>>>" button. 单击“高级>>>”按钮。

  4. Select the "Link to alternate location (Linked Folder)" radio button. 选择“链接到备用位置(链接文件夹)”单选按钮。

  5. In the textbox just under this, click Browse. 在此下方的文本框中,单击“浏览”。

  6. In your source tree, navigate to SharedContent/WebContent/shareRoot. 在源树中,导航到SharedContent / WebContent / shareRoot。 Then click OK/Open/Finish buttons until all the dialogs go away. 然后单击“确定”/“打开”/“完成”按钮,直到所有对话框消失。

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. 令人讨厌的是,在引用这些文件时,您必须在URL中包含“shareRoot /”,但您可以使用您喜欢的URL重写过滤器来解决此问题。

You can use a similar trick in the Java source tree to map Java files into multiple projects. 您可以在Java源代码树中使用类似的技巧将Java文件映射到多个项目中。 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. 我已经开始这样做,而不是将共享代码构建到.jar文件中,因为它避免了每次要在本地Tomcat服务器上测试更改时重建.jar的需要。

I believe writing your own scripts (eg custom build steps using ant, easily configurable in eclipse) is among the more practical solutions. 我相信编写自己的脚本(例如使用ant的自定义构建步骤,可以在eclipse中轻松配置)是更实用的解决方案。

You could also create multiple webapps and reference their respective resources - this would be easy with css, images and the like, not so much with jsp that need to access your code being available. 您还可以创建多个Web应用程序并引用它们各自的资源 - 这对于css,图像等来说很容易,而不是需要访问代码可用的jsp。

I can imagine some tricks with tomcats crossContext="true" option for the context (eg webapplication), enabling one application to access classes in an other application, but haven't tried them yet. 我可以想象上下文的tomcats crossContext =“true”选项的一些技巧(例如webapplication),使一个应用程序能够访问其他应用程序中的类,但还没有尝试过。

Sorry - I believe that's not the answer you'd like to hear... 对不起 - 我相信这不是你想听到的答案......

If you're using Subversion, you could use svn:externals to reference the common files in both projects. 如果您正在使用Subversion,则可以使用svn:externals来引用两个项目中的公共文件。 Then you can edit the common files in one place, and if you do a svn up all will be synchronized. 然后你可以在一个地方编辑公共文件,如果你做了一个svn up所有都将被同步。

haha,i give ua late surprise 哈哈,我给你一个惊喜

i'm Chinese,my english is poor, but i can help u . 我是中国人,我的英语很差,但我可以帮助你。

Olaf Kock is right ,but his answer not perfect. 奥拉夫科克是对的,但他的回答并不完美。

Here is the perfect answer. 这是完美的答案。 u have to refer the follow url, it can hep u. 你必须参考以下的网址,它可以解雇你。

click here 点击这里

in the url page, the example for the property content box is not exact, u fllow me: 在网址页面中,属性内容框的示例并不准确,请告诉我:

if need to share a file: 如果需要共享文件:

a.jsp  svn://myhome.com/svn/myproject/trunk/a.jsp

if need to share a folder: 如果需要共享文件夹:

xml  svn://myhome.com/svn/myproject/trunk/xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM