开发者

Maven- Deploy file goal

I have a maven project in which the some xlsx files get generated after the project run phase. These excel sheets are used by some other projects also. So I need to publish these excel sheet artifacts to remote|local repository.

I tried with the deploy plugin's deploy-file goal. But after deploying the excel sheet as a jar in repo, I tried extracting the jar and I could see the excel sheet got corrupted. Excel sheet converted to several XML files. ( Sheet1.xml, Sheet2.xml ..)

Maven command :-

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>
   开发者_JS百科         <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>

Please help me to resolve this issue. All inputs are appreciated.


This is because with the deploy-file command your pom is ignored. You have to run mvn deploy, so that the maven-jar-plugin is called (it is as default called in the package phase).

With your command, you're deploying the xslx directly into your repository, and i suspect it is handled as a jar, thus you get the xml, if you unpack the jar (because a xlsx is also just a packed file, that consists of various xml files).

I'd recommend you read some docs about the Maven lifecycles etc. (Maven Lifecycles)


Microsoft is trying to push new file formats that are using ZIP and XML in their office suites. This method reduces the size of the file by around 50%.

Reference

That means the excel file is actually a packed file of different xmls and other metadata informations.

I have done a work around to resolve the issue:

  1. After excel sheet generation, I have added that file to a zip (SeriesXL.zip), using java.util.zip.ZipEntry.

  2. Then deploy the zip file using the command

    mvn clean deploy:deploy-file -Durl=file:///C:\repository -Dfile=SeriesXL.zip -DgroupId=com.test.pjt -DartifactId=seriesXL -Dversion=1.0 -Dpackaging=jar
    

I am able to successfully deploy the SeriesXL.jar in local repository and while extracting the jar, I could see the original version of the Excel sheet, not just a bundle of XML files.

BTW Thanks Dunni for your support.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜