简体   繁体   English

使用Maven部署jar文件和外部资源文件

[英]Deploying a jar file and external resource files with Maven

I am new to Maven and wanted to automate some build steps by automatically deploying several files and folders to the production environment: 我是Maven的新手,想通过自动将几个文件和文件夹部署到生产环境来自动化一些构建步骤:

my-app-0.7.0-jar-with-dependencies.jar (main application file)
conf.properties (configuration file that can be edited on the fly)
files_folder (folder that contains html, css etc. that can be edited on the fly)

My project structure look like this: 我的项目结构如下所示:

src
   main 
      java
      resources (contains resources that should be included in the .jar)
conf.properties.jar 
files_folder 

.

I started by adding <resources> element in the pom.xml 我首先在pom.xml添加<resources>元素

<resources>
    <resource>
        <directory>.</directory>
        <includes>
            <include>conf.properties</include>
            <include>files_folder/**/*.*</include>
        </includes>
        <targetPath>..</targetPath>
    </resource>
</resources>

This moves conf.properties and files_folder to the target directory and this is fine (I can copy .jar, conf.properties and files_folder and run them). 这会将conf.propertiesfiles_folder移到target目录,这很好(我可以复制.jar,conf.properties和files_folder并运行它们)。

However these files are not moved to the local repository in C:\\Users\\my_name\\.m2\\... or external repositories (in install and deploy phases). 但是,这些文件不会移动到C:\\Users\\my_name\\.m2\\...或外部存储库中的本地存储库中(在安装和部署阶段)。

My thinking is that these resource should be moved to the repositories because: 我的想法是,应将这些资源移至存储库,因为:

  • they are necessary for the program to run 它们是程序运行所必需的
  • it would be possible to rollback to any previous version very fast (just locate the version folder and everything you need would be there; it would not be so easy if conf.properties and files_folder would not be automatically included in there) 可以非常快速地回滚到任何以前的版本(只需找到版本文件夹,您需要的所有内容都将存在;如果不自动将conf.properties和files_folder包含在其中,那么将不会那么容易)

So the main questions are: 因此,主要问题是:

  1. Is this line of thinking reasonable? 这种思路合理吗?
  2. If it is reasonable, how is it possible to include these external resources in the repositories? 如果合理,如何将这些外部资源包括在存储库中?

Like other response I'd suggest you need to look at a continuous integration approach. 像其他响应一样,我建议您需要考虑一种持续集成方法。 I have had good experience working with Jenkins before. 我以前在Jenkins上有很好的经验。 It's free, and comes with a lot of functionatlity. 它是免费的,并具有很多功能。 It also has a large community that have developed a range of plugins: 它还拥有一个开发了一系列插件的大型社区:

https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

Depending on what you're deploying and how you want to deploy it some plugins that may be helpful to your process are: 根据您要部署的内容以及您希望如何部署它,一些可能对您的过程有帮助的插件是:

Instead of keeping this files in the classpath, you can keep these files at src/main/resources/META-INF. 您可以将这些文件保留在src / main / resources / META-INF中,而不是将这些文件保留在类路径中。 So when you build your project using maven and if you have chosen the packaging as ear <artifactId>ProjectName</artifactId> <version>Version</version> <packaging>ear</packaging> 因此,当您使用Maven构建项目时,并且如果已将包装选择为ear <artifactId>ProjectName</artifactId> <version>Version</version> <packaging>ear</packaging>
then all these files will be packaged inside the jar and will be available in your maven repository 那么所有这些文件都将打包在jar中,并将在您的maven存储库中可用

Maven is a build tool and not a deployment tool. Maven是构建工具,而不是部署工具。 For deployment to environments like Test, Q&A or Prod other tools are more suitable like Chef, Puppet or may be a simply shell script etc 对于部署到诸如Test,Q&A或Prod之类的环境,其他工具则更适合诸如Chef,Puppet,或者可能只是一个简单的shell脚本等。

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

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