简体   繁体   English

在Ear Project Structure Eclipse下的两个Java Dynamic Web项目之间共享src文件夹

[英]Share src folder between two Java Dynamic Web project under Ear Project Structure Eclipse

i just wanted to clarify and know , how we can share codebase between project under Ear Project , following is my project layout 我只是想澄清和知道,我们如何在Ear Project下的项目之间共享代码库,以下是我的项目布局

I Have one EAR Project, which has two appengine dynamic web application project added to it, as app1 and app2 我有一个EAR项目,其中添加了两个appengine动态Web应用程序项目,分别为app1和app2

i have all of my model java class and service class in app1 , and now i dont wanted to rewrite or have duplicate of these files in app2 , i just wanted to use these classes in app1 from app2. 我在app1中拥有所有模型Java类和服务类,现在我不想在app2中重写或复制这些文件, 我只是想在app2 中的app1中使用这些类。

Note : am not using maven, since there is a lot of issue with (maven + appengine + eclipse) and i dont want to complicate things. 注意我不使用maven,因为(maven + appengine + eclipse)存在很多问题,我不想使事情复杂化。

In short, two web application project with shared src folder or part of it, is it possbile? 简而言之, 两个具有共享src文件夹或其中一部分的Web应用程序项目,可能吗?

Any help is highly appreciated, Thanks! 感谢您的任何帮助,谢谢!

You can't share code between two war files and you shouldn't. 您不能在两个war文件之间共享代码,也不应该。

You'll have to move shared code to a jar project, that is the correct way. 您必须将共享代码移至jar项目,这是正确的方法。

If you don't have maven, you can have an ant file doing that 如果您没有Maven,则可以使用ant文件

In my opinion, yes it is possible and it most often makes sense to outsource libraries in own projects to share them. 在我看来,是有可能的,将自己项目中的库外包以共享它们通常是有意义的。

Relevant places for including resources in Java (EE) projects are: 在Java(EE)项目中包含资源的相关位置是:

  1. the Java build path Java构建路径
  2. the linked resources list in Eclipse Eclipse中的链接资源列表
  3. the referenced libraries setting in Eclipse Eclipse中引用的库设置
  4. The entries in files like application.xml, web.xml or other servlet container specific files. 文件中的条目,例如application.xml,web.xml或其他servlet容器特定的文件。

Further, you can make usage of file system links to folders or source files. 此外,您可以使用到文件夹或源文件的文件系统链接。

Which one is useful and visible in the Eclipse project settings depends on the project type, the Eclipse version and plugin and the servlet container. 在Eclipse项目设置中哪一个有用并可见,取决于项目类型,Eclipse版本和插件以及servlet容器。 Some entries in xml files are managed by Eclipse setting dialogs, others are not. xml文件中的某些条目是由Eclipse设置对话框管理的,其他则不是。

In your situation, I suggest you create a new library project, say "appLib", and put the common code in there. 根据您的情况,建议您创建一个新的库项目,说“ appLib”,然后在其中放入通用代码。 It contains only the code that is common to app1 and app2. 它仅包含app1和app2通用的代码。 Then add a project reference from app1 and from app2 to appLib. 然后从app1和app2向appLib添加项目引用。

Links like this may also be helpful: How do I include a jar file into a lib folder of an ear file using ant? 这样的链接也可能会有所帮助: 如何使用ant将jar文件包含在ear文件的lib文件夹中?

If you share a library like this, you might run into situations where you alter it because of a need in app1, and then you have to test app2 again because the edits have become visible to app2 and vice versa. 如果共享这样的库,则可能会由于app1的需要而遇到更改库的情况,然后您必须再次测试app2,因为编辑对app2可见,反之亦然。 Thus moving errors from one to another project. 从而将错误从一个项目转移到另一个项目。 This may be very stressful. 这可能非常压力。 Finally, maybe it's best to have a versioned source code library for your library and to checkout and include the source into app1 and app2 project. 最后,也许最好为您的库提供一个版本化的源代码库,并检出源并将其包含到app1和app2项目中。 So you can change one app and the library without disturbing the other app immediately, and then merge the sources into the library later controlled, avoiding disturbing side effects. 因此,您可以更改一个应用程序和库,而不会立即干扰另一个应用程序,然后将源合并到以后控制的库中,从而避免了干扰的副作用。

Hth :-) 高度:-)

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

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