Maven-部署文件目标

时间:2011-06-25 04:43:04

标签: maven

我有一个maven项目,在项目运行阶段之后会生成一些xlsx文件。这些excel表也被其他一些项目使用。所以我需要将这些excel表工件发布到远程本地存储库。

我尝试使用deploy插件的部署文件目标。但是在将repcel工作表部署为repo中的jar之后,我尝试提取jar并且我可以看到excel表被破坏了。 Excel工作表转换为多个XML文件。 (Sheet1.xml,Sheet2.xml ..)

Maven命令: -

mvn clean deploy:deploy-file -Durl = file:/// C:\ repository -Dfile = Series.xlsx -DpomFile = seriesXL.pom

SeriesXL.pom: -

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test.pjt</groupId>
  <artifactId>seriesXL</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>

 <build>
  <plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <configuration>
        <includes>
            <include>*.xlsx</include>
        </includes>
    </configuration>
</plugin>
  </plugins>

</build> 


    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.6</version>
        </dependency>
    </dependencies>

</project>

请帮我解决此问题。所有投入都表示赞赏。

2 个答案:

答案 0 :(得分:1)

这是因为使用deploy-file命令会忽略pom。你必须运行mvn deploy,以便调用maven-jar-plugin(它在包阶段默认调用)。

使用您的命令,您将xslx直接部署到您的存储库中,我怀疑它是作为jar处理的,因此您获取xml,如果您解压缩jar(因为xlsx也只是一个打包文件,它包含各种xml文件。)

我建议你阅读一些关于Maven生命周期等的文档。Maven Lifecycles

答案 1 :(得分:1)

微软正在尝试推出在办公​​套件中使用ZIP和XML的新文件格式。此方法可将文件大小减小约50%。

Reference

这意味着excel文件实际上是不同xmls和其他元数据信息的打包文件。

我已经完成了解决问题的工作:

  1. 生成Excel工作表后,我使用java.util.zip.ZipEntry将该文件添加到zip(SeriesXL.zip)。

  2. 然后使用命令

    部署zip文件
    mvn clean deploy:deploy-file -Durl=file:///C:\repository -Dfile=SeriesXL.zip -DgroupId=com.test.pjt -DartifactId=seriesXL -Dversion=1.0 -Dpackaging=jar
    
  3. 我能够在本地存储库中成功部署SeriesXL.jar,在提取jar时,我可以看到Excel工作表的原始版本,而不仅仅是一堆XML文件。

    BTW感谢Dunni的支持。

相关问题