简体   繁体   English

如何在另一个项目中添加和使用一个项目?

[英]How to add and use one project in another project?

I have a project based on Spring which is running successfully. 我有一个基于Spring的项目,该项目正在成功运行。 Now I have created another project based on Jersey which I want to integrate with spring project in Jersey. 现在,我创建了另一个基于Jersey的项目,我想将其与Jersey的spring项目集成。

I have gone through internet and I added spring project in the build-path of the Jersey project. 我已经浏览了Internet,并在Jersey项目的构建路径中添加了spring项目。

Here the problem is whenever I run my Jersey project, it has to execute the Spring project first. 这里的问题是,每当我运行Jersey项目时,它都必须先执行Spring项目。

How to configure spring project in Jersey? 如何在Jersey中配置spring项目?

You should consider using a dependency management/build tool such as Maven or Gradle . 您应该考虑使用诸如MavenGradle之类的依赖项管理/构建工具。

This way each of your projects will be a module, which can be referenced from the other project as a dependency. 这样,您的每个项目都将是一个模块,可以从另一个项目中将其作为依赖项进行引用。 You can still use the first project alone and the two-dependent projects alone as wall. 您仍然可以单独使用第一个项目,也可以单独使用两个依赖项目。 Then the tool lets you just simply package the resulting project in a artifact such as WAR with all the dependencies. 然后,该工具使您可以简单地将生成的项目打包到带有所有依赖项的工件(例如WAR)中。

Here is a quick maven tutorial - Maven in 5 Minutes 这是一个快速的Maven教程-5分钟内的Maven

It is a good idea to use such a tool in any case as it has many additional advantages: 在任何情况下都使用这种工具是一个好主意,因为它具有许多其他优点:

  • Lets you manage also your third party dependencies without needing to manually download the libraries and add them to the classpath 使您还可以管理第三方依赖性,而无需手动下载库并将其添加到类路径
  • It is much easier to use such a project in cases like continuous integration. 在诸如持续集成的情况下使用这样的项目要容易得多。
  • You can run all your tests automatically during the build process to make sure everything works 您可以在构建过程中自动运行所有测试,以确保一切正常
  • It resolves transitive dependencies (dependencies of your dependencies) 它解决传递依赖(依赖关系的依赖关系)
  • It builds resulting archive file for you 它为您构建生成的存档文件
  • You can have multiple profiles for different environments 您可以针对不同的环境使用多个配置文件
  • ... ...

Make both of your projects modules of one Maven parent pom project. 制作一个Maven父pom项目的两个项目模块。 This way you can build them both at the same time. 这样,您可以同时构建它们两者。

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

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