Maven: Unzip nested zip files. - java

I am struggling to extract contents of nested zip file in an artifact.
Artifact has below content zipped:
Base_Config.zip
First_Pack.zip
01_first.json
02_second.json
Second_Pack.zip
01_third.json
02_fourth.json
able to extract only zip files under Base_config.zip not it's contents *.json
`<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.shashank.bss.XXX</groupId>
<artifactId>testdatagen</artifactId>
<version>24.5.0</version>
<type>zip</type>
</artifactItem>
</artifactItems>
<outputDirectory>target/assemble/shashank/deps</outputDirectory>
<includes>testdatagen-*-First_Pack.zip</includes>
</configuration>
</execution>
`
Tried multiple solution:
Failed to get content using assembly descriptor,
Tried solution available on this as well:
Custom maven assembly
Not want to use deprecated plugin and the solution available there with plugin:
truezip-maven-plugin
Unpack inner zips in zip with Maven
Is it possible to get the work done by this plugin:
maven-dependency-plugin & unpack.
Or any other simple solution available from maven?

Related

Download an xlsx file in pom.xml

I am trying to download a .xlsx file into my project's resources using the following execution:
<execution>
<id>${id}</id>
<phase>generate-sources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${url}</url>
<outputFileName>${fileOutput}</outputFileName>
<outputDirectory>${licensesDir}/em</outputDirectory>
</configuration>
</execution>
However, the file that it generates is empty and cannot be read. I know it's not a problem with the file I'm trying to download because whenever I download it directly and copy it into my project manually, I can read it it fine, and it works with my code. It also downloads other file types just fine.
Yet, whenever I try to do download it this way, in the pom.xml, the generated file is empty and my code generates a NullPointerException exception when run.
Could anyone provide some help please?
What you need is Maven Download Plugin: https://github.com/maven-download-plugin/maven-download-plugin
Add plugin to your pom and execute goal like this:
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>install-jbpm</id>
<phase>pre-integration-test</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://downloads.sourceforge.net/project/jbpm/jBPM%203/jbpm-3.1.4/jbpm-3.1.4.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/jbpm-3.1.4</outputDirectory>
<md5>df65b5642f33676313ebe4d5b69a3fff</md5>
</configuration>
</execution>
</executions>
</plugin>

Maven - How can I package sources of all dependencies when packaging

So I understand how I can package dependencies into my executable JAR, using jar-with-dependencies descriptor for maven-assembly-plugin.
However, I want to also create a source bundle(s), that not only includes sources of my project, but sources of all dependencies that are embedded in my executable JAR.
How can one achieve that?
This is what I used finally:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>src-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
It copies the sources of all known dependencies recursively into the target/source directory. Pretty handy!
Note: Use unpack-dependencies goal to instead unpack all sources in destination directory.
Reference: https://maven.apache.org/plugins/maven-dependency-plugin/index.html

MAVEN to change the file structure while execution of Unpack

I my CI setup I have deploy the zip file from nexus to tomcat server.
Below is my Deployment POM.
<execution>
<id>unpack</id>
<phase>install</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>//</groupId>
<artifactId>//</artifactId>
<version>//version</version>
<classifier>bin</classifier>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>//tomcat folder </outputDirectory>
<includes>**/*.war,appconf/dev/*.properties</includes>
</artifactItem>
</artifactItems>
<includes>**/*.properties</includes>
</configuration>
</execution>
i provided includes and property file under dev as below
<includes>**/*.war,test/dev/*.properties</includes>
So it creates a test folder and place the property files inside.I want to skip the dev folder but the property file has to copied and put directly inside the test fodler.
As of now the tomcat directory looks like test\dev\test.properties.
but I need to change test\test.properties when unpack the zip file.
help me to resolve this issue using MAVEN.

Disable deploy of jnilib

My users have been calling out for easily distributed native binaries with my library. I've got this working by distributing the natives in jars, which are extracted at runtime into a temporary directory.
However, the maven-native-plugin requires that the native is packaged as a jnilib (OS X), so (Linux) or dll (Windows). I have my own deploy target that packages a jar file and distributes that under the classifier natives. It's a bit annoying that this needs a special classifier.
How can I disable the deploy of the jnilib/so/dll?
How can I distribute my jar without any special classifier?
I do a similar thing, but I pack the native libraries inside zip files. After that, in the artifact that needs them, I pull and unpack the zip file with the maven dependency plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unzip</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0.0</version>
<type>zip</type>
<overWrite>true</overWrite>
<includes>**/*.dll</includes>
<outputDirectory>${project.build.directory}/natives</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
As you can see I don't use any classifiers.

best practice: how to host server-side code in the maven repository

What is the best way to put javascript/html/css code in the maven repository, so that is easily usable by java projects.
Is there a way to do it such that the included project can be easily made "web-visible" by the including project?
For example assume I write a very useful tricks.js file an put it in the mvn repository.
Is it possible to create a web project that adds tricks.js as a dependency and then doing
<script src="/some/thing/tricks.js"/>
causes the tricks.js file to be served?
External resources should be packaged into an artifact and published to the repository (for simplicity use a jar artifact, but you could specify an assembly to package a zip instead to make it clear what the artifact is for). The maven-dependency-plugin unpacks the jar's contents into a specified location in the war project. That folder is then specified as an external web resources directory for the maven-war-plugin.
The following configuration will unpack the contents of my-resources into the target/external-resources directory, then include the contents of that folder in the war as if they'd been defined in src/main/resources.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>name.seller.rich</groupId>
<artifactId>my-resources</artifactId>
<version>1.0.0</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/external-resources</outputDirectory>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/external-resources</directory>
</resource>
</webResources>
</configuration>
</plugin>
You can pack it into jar and then unpack it by maven plugins.

Categories