简体   繁体   English

通过将其导出为jar文件在不同项目中重用我的Java代码

[英]reusing my java code in different projects by exporting it as jar file

I have a Spring web MVC framework project. 我有一个Spring Web MVC框架项目。 I am going to add a service to my project to send emails using Apache Commons Email (service has external dependencies). 我将向我的项目中添加一个服务,以使用Apache Commons Email发送电子邮件(该服务具有外部依赖性)。 I am thinking to use this Email service in my other projects as well and I do not want to copy the classes between projects. 我正在考虑在其他项目中也使用此电子邮件服务,并且我不想在项目之间复制类。 The solution could be: Email service can be an independent project with some interfaces to accept the Email information (msg, To, From, ...). 解决方案可能是:电子邮件服务可以是一个独立的项目,具有一些接受电子邮件信息的接口(msg,To,From,...)。 Then export this project as a jar file to any other project. 然后将此项目作为jar文件导出到任何其他项目。 If this is a valid solution, how can I export my Email service Spring mvc project as a jar file? 如果这是一个有效的解决方案,如何将我的电子邮件服务Spring mvc项目导出为jar文件? (consider I have external dependencies) (考虑到我有外部依赖性)

If this is not a good/valid solution, how can I reuse the Email service in different projects with minimum effort? 如果这不是一个好的/有效的解决方案,我如何以最小的努力在不同的项目中重复使用电子邮件服务? PS I am using Maven already in my project. PS我已经在我的项目中使用Maven。

I'd use Maven. 我会用Maven。 Using the pom for the email service you can specify it's dependencies. 使用电子邮件服务的pom可以指定其依赖性。 Build using mvn install to add your jar to the repository. 使用mvn install进行构建以将jar添加到存储库。

Then on your future projects add your email service as a dependency. 然后在您的未来项目中,将您的电子邮件服务添加为依赖项。 It will pull all required dependencies through. 它将拉动所有必需的依赖项。

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

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