将项目中的特定文件导出到maven本地存储库

时间:2015-07-28 04:25:05

标签: maven gruntjs zip

我有一个Grunt项目,它在build文件夹中构建一个zip。 要分发此zip,我已将其转换为Maven项目并将此zip文件复制到maven目标文件夹中。

  <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
      <execution>
        <id>copy-resources</id>
        <!-- here the phase you need -->
        <phase>install</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/target</outputDirectory>
          <resources>
            <resource>
              <directory>build</directory>
              <includes>
                <include>*.zip</include>
              </includes>
              <filtering>true</filtering>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>

但是这个zip文件没有复制到我的本地maven存储库。 是否有配置或插件允许我指定maven repo文件夹的内容?

更新
项目结构:

myproject  
   |_ pom.xml  
   |_ build  
   |_ dist  
        |_ myproject.js
        |_ myproject.css
        |_ libs/

我想压缩的目录是:/ build / dist /

使用的描述符:

<assembly>
<formats>
    <format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
    <fileSet>
        <directory>build/dist</directory>
        <includes>
            <include>**/*</include>
        </includes>
    </fileSet>
</fileSets>
</assembly>

结果拉链如下:

myproject-1.0.0.zip
 |_ build
      |_ dist
           |_ myproject.js
           |_ myproject.css
           |_ libs/

我的要求是:

myproject.zip
 |_ myproject.js
 |_ myproject.css
 |_ libs/

1。 zip name =“myproject.zip”而不是“myproject-1.0.0.zip”
2.使用中间文件结构build / dist。

1 个答案:

答案 0 :(得分:1)

  

但是这个zip文件没有复制到我的本地maven存储库。

Maven存储库的目的不是存储单个文件,而是构建过程的结果(jar,war,pom)。

如果要构建包含程序和某些资源作为目录结构的zip(logging-dir,tmp-dir,config-dir,...),可以使用maven-assembly-plugin。这是一个example

更新1

这是我自己的一个例子。看一下<outputDirectory>元素。

这是汇编描述符myAppDescriptor.xml:

<assembly>
    <id>myAppAssembly</id>

    <formats>
        <format>zip</format>
    </formats>

    <baseDirectory>${project.build}/${artifactId}-${version}</baseDirectory>
    <includeBaseDirectory>false</includeBaseDirectory>

    <!-- Adds dependencies to assembly under lib directory -->
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>

    <fileSets>
        <!--
           Adds startup scripts to the root directory of zip package. The startup
           scripts are located to src/main/scripts directory as stated by Maven
           conventions.
       -->
        <!-- adds jar package to the root directory of zip package -->
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
            <excludes>
                <exclude>*source*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <directory>${project.build.scriptSourceDirectory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.cmd</include>
            </includes>
            <filtered>true</filtered>
        </fileSet>
        <fileSet>
            <directory>${project.build.scriptSourceDirectory}/config</directory>
            <outputDirectory>/config</outputDirectory>
            <filtered>true</filtered>
        </fileSet>
        <fileSet>
            <directory>${project.build.scriptSourceDirectory}/log</directory>
            <excludes>
                <exclude>*.*</exclude>
            </excludes>
            <outputDirectory>/log</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.build.scriptSourceDirectory}/sql</directory>
            <outputDirectory>/sql</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.build.scriptSourceDirectory}/mailing</directory>
            <excludes>
                <exclude>*</exclude>
            </excludes>
            <outputDirectory>/mailing</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.build.scriptSourceDirectory}/tmp</directory>
            <outputDirectory>/tmp</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

这是pom.xml:

<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <grpoupId>com.enterprise</grpoupId>
    <artifactId>MyApp</artifactId>
    <version>0.6.1</version>
    <packaging>jar</packaging>

    <name>MyApp</name>
    <url>http://www.enterprise.com</url>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/myAppDescriptor.xml</descriptor>
                    </descriptors>
                    <finalName>MyApp</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.enterprise.MyApp</mainClass>
                        </manifest>

                        <manifestEntries>
                            <Class-Path>.</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- your dependencies -->
    </dependencies>

    </project>

zip具有以下结构:

Myapp.zip
    |__ config
    |__ lib
    |__ log
    |__ mailing
    |__ sql
    |__ tmp
    myApp-0.6.1.jar
    myApp.cmd

更新2: 关于将zip部署到存储库的要求:

  

项目结构:

myproject  
  |_ pom.xml  
  |_ build  
       |_ dist  
            |_ myproject.js
            |_ myproject.css
            |_ libs/

我不熟悉JavaScript与Maven相结合,但我认为项目布局应该与此类似:

myproject  
  |_ pom.xml
  |_ src
       |_ main
           |_ webapp
                *your js and css files here ???*
  |_ target  
       |_ ...

名为&#34; build&#34;的目录默认情况下,maven不会将其识别为源目录。目录target是在maven执行期间创建的。

另一种解决方案可能是将目录build配置为build部分中pom.xml中的源目录:

<build>
    ...
    <sourceDirectory>build</sourceDirectory> 
    ...
</build>

查看maven standard directory layout,并将这些信息与有关&#34; maven和JavaScript&#34;的一些研究结合起来。

然后应该可以生成一个zip并通过mvn installmvn deploy将其部署到任何存储库。