简体   繁体   English

如何从一个 Maven 项目到另一个 Maven 项目获取文件夹、资源和 pom 文件?

[英]How to get folders, resources and pom file from a maven project to another maven project?

I am trying my luck in eclipse to achieve something that I am able to successfully achieve using Visual Studio(.net project).我正在 Eclipse 中碰碰运气,以实现我能够使用 Visual Studio(.net 项目)成功实现的目标。 I have a core-framework maven project with additional files and folders apart from the normal folders that maven provides.我有一个核心框架 maven 项目,除了 maven 提供的普通文件夹之外,还有其他文件和文件夹。 I exported it as jar file and added it as an external library to another maven project.我将它导出为 jar 文件并将其作为外部库添加到另一个 maven 项目中。 Is there a way that when I add it as a library to the second project, the second project gets all the folders, files from the first maven project overwriting the pom file in the second maven project too?有没有办法当我将它作为库添加到第二个项目时,第二个项目从第一个 maven 项目中获取所有文件夹、文件,也覆盖第二个 maven 项目中的 pom 文件? Inshort I want to make sure whoever takes the framework jar as reference follows the same folder structure as framework with required files such as config file, pom.xml file to avoid errors on missing path/files.简而言之,我想确保将框架 jar 作为参考的人遵循与框架相同的文件夹结构,其中包含所需的文件,例如配置文件、pom.xml 文件,以避免丢失路径/文件时出错。 I read about dependency management but even for that I have to define all the dependencies in child pom file which I want to avoid.我阅读了依赖管理,但即使如此,我也必须在子 pom 文件中定义所有我想避免的依赖。 Any help would be appreciated, I didn't find much info around the query.任何帮助将不胜感激,我没有找到有关查询的太多信息。

  1. Copying JAR files to lib folders is old-school.将 JAR 文件复制到lib文件夹是过时的做法。 Such you also set aside Maven's sophisticated dependency (and transitive dependency) resolution.这样你也搁置了 Maven 复杂的依赖(和传递依赖)解析。 The clean Maven way is to put your core-framework JAR to a Maven repo (remote or local at the users machine ) and let the users of it declare it as dependency in their projects.干净的 Maven 方法是将您的核心框架 JAR 放入 Maven 存储库( 用户机器上的远程或本地),并让其用户在其项目中将其声明为依赖项。

  2. What do you exactly mean by " additional files and folders apart from the normal folders that maven provides "? 除了maven提供的普通文件夹之外的其他文件和文件夹”究竟是什么意思? What is there more than code and resources?除了代码和资源还有什么?

  3. To make your users' life easier concerning dependencies you could a) use a BOM (Bill Of Material) dependency or b) use inheritance (ie <parent> ← child relationship).为了使您的用户在依赖项方面的生活更轻松,您可以 a) 使用BOM物料清单)依赖项或 b) 使用继承(即<parent> ← 子关系)。

Adding a dependency will not change your project in any way.添加依赖项不会以任何方式改变您的项目。 You cannot add folders from a dependency to the project.您不能将依赖项中的文件夹添加到项目中。

You can write a Maven archetype that is a kind of project template.您可以编写一个 Maven 原型,它是一种项目模板。 Then people can use it to create new projects where the files are at the right places.然后人们可以使用它来创建文件位于正确位置的新项目。

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

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