Corrupt JARS in zip using maven - java

I have maven project that i want to package in a zip file including the jar binaries(in a folder /jars). After the packaging, I've unzipped and extracted the jar file but get the below error when i invoke this:
PS C:\Users\kenochrome\Downloads> jar xf service-0.1.jar
java.util.zip.ZipException: invalid literal/length code
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:139)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:142)
at sun.tools.jar.Main.extractFile(Main.java:715)
at sun.tools.jar.Main.extract(Main.java:678)
at sun.tools.jar.Main.run(Main.java:191)
at sun.tools.jar.Main.main(Main.java:904)
Below is a snippet of parent and child poms.
Parent POM
<build>
<finalName>release_1.0</finalName>
<resources>
<resource>
<directory>${basedir}/hello/world/00006/jars</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>assembly/bin.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Child POM
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jar</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<finalName>service-${project.version}</finalName>
<outputDirectory>../../jars</outputDirectory>
<resources>
<resource>
<directory>jars</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
I'm sorry if the information is not adequate or if this question is not correctly formatted.
Many thanks for going through this post and much appreciated in advance.

Was looking through another forum and found out that the issue that I was having was using the <lineEnding>unix</lineEnding> element in my descriptor assembly xml.

Related

how to build maven dependencies into jar and pack it into a war file

In my maven project, i wanted to build all java source code into one jar (rtcc.jar) and all maven dependencies into another jar (external-lib.jar) and finally pack both these jars into a war file (rtccClient.war). rtcc.jar gets generated properly but jar with dependencies (external-lib) is not getting generated. .Below is my pom.xml. Please update where i am doing mistake.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>default-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
</archive>
<finalName>rtccJar/lib/rtcc</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>only-library</classifier>
<excludes>
<exclude&>**/Main*</exclude>
</excludes>
<finalName>rtccJar/lib/external-lib</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>test</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<phase>test</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archiveDirectory>${basedir}/target/rtccJar/lib</archiveDirectory>
<archiveDirectory>${basedir}/target/lib/lib</archiveDirectory>
<includes>
<include>rtcc.jar</include>
<include>vcsireader1-1.1.jar</include>
<include>vcsutil1-1.1.jar</include>
<include>yaml1-1.1.jar</include>
<include>yamldefs1-1.1.jar</include>
</includes>
<keystore>${basedir}/extFiles/jarSigner/jarsignercert2.p12</keystore>
<alias>jarsigner</alias>
<storepass>scarbo</storepass>
<keypass>mykpass</keypass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>package</phase>
</execution>
</executions>
<configuration>
<webResources>
<resource>
<directory>${basedir}/target/rtccJar</directory>
</resource>
<resource>
<directory>${basedir}/target/lib/lib</directory>
<includes>
<include>vcsireader1-1.1.jar</include>
<include>vcsutil1-1.1.jar</include>
<include>yaml1-1.1.jar</include>
<include>yamldefs1-1.1.jar</include>
</includes>
<targetPath>lib</targetPath>
</resource>
<resource>
<directory>${basedir}/extFiles/extlib</directory>
</resource>
</webResources>
<packagingExcludes>**/com/**</packagingExcludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName> ${artifactId} </warName>
</configuration>
</plugin>
</plugins>
</build>

How to create single jar with dependencies in maven

I am trying to create single fat jar using maven assembly plugin but somehow after running maven clean install it give 2 jars, one is client-1.0-SNAPSHOT.jar and other one is client-1.0-SNAPSHOT-jar-with-dependencies.jar.
I am only interested to create a jar with dependencies so dont know why the other jar is also creating by this assemble plugin.
Can someone tell me how to eliminate this jar Or should i use some other maven command rather than clean install ?
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- download source code in Eclipse, best practice -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
-->
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.app.MainApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- overwrite! -->
<overwrite>true</overwrite>
<outputDirectory>${project.basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

buid-helper-plugin with multiple active profiles

I have a project which may take different sources / resources based on the selected profiles. Some profiles are mutually exclusive, some should be combinable, for example the profiles local and wildfly defined in the snippet below should be combinable
<profiles>
<profile>
<id>local</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>add-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>profiles/local/src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>profiles/local/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>wildfly</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>add-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>profiles/wildfly/src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>profiles/wildfly/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
If I do this under eclipse I notice that only the latter is actually applied - I only see the sources / resources defined in the wildfly profile.
Also in the resulting complete POM I notice that only the latter (wildfly) profile's configuration is applied, thus removing the sources and the resource defined in the local profile.
Is this the way the plugin is supposed to work, or am I missing something?
Ok.... It was just me.
I gave the executions the same name, hence they were overridden. My bad.
This question might be closed / removed by moderators.

How to convert snippets to asciidoc html in eclipse

how to convert generated snippets to ASCII-doc html in spring boot.
i have already tried added the ASCII plugin.
i have already created .adoc file in src/main/asciidoc, but after maven build, it does not generate the html
include::{snippets}/test_find_by_id/http-request.adoc[]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Documentation.java</include>
</includes>
<systemPropertyVariables>
<org.springframework.restdocs.outputDir>
${snippetsDirectory}
</org.springframework.restdocs.outputDir>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<attributes>
<snippets>${snippetsDirectory}</snippets>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<!-- <phase>process-resources</phase>-->
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
You need to reference the ASCII Doc Maven plugin in your pom.xml. See: https://github.com/asciidoctor/asciidoctor-maven-plugin#installation
mvn prepare-package
is the solution

Maven manifest file issue

I have been struggling with this for some time. I have a Maven project that builds and packages just fine with one problem. I have a jar I am using that is NOT in my companies version of NEXUS. I added the jar to my .m2 repository through this command line command:
mvn install:install-file -Dfile=c:/u/lib/terajdbc4-15.00.00.20.jar -DgroupId=com.teradata -DartifactId=terajdbc4 -Dversion=15.00.00.20 -Dpackaging=jar
This jar will NOT append to the manifest file when the jar is built. So, when I need this jar, the code dies because it can't find the resource it's looking for (the teradata driver)
Is there any way to add this single jar to the manifest file IN ADDITION TO the other jars I'm already adding to the manifest?
Here is the build section from the parent pom file:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/Crunchify</outputDirectory>
<resources>
<resource>
<directory>resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/Crunchify/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>ap.invalert.handler.InvAlertHandler</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<finalName>Crunchify/Crunchify</finalName>
</configuration>
</plugin>
</plugins>
</build>

Categories

Resources