Disable deploy of jnilib - java

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.

Related

War external dependency overlay - move jars from WEB-INF/lib-new to WEB-INF/lib

I am working on a maven project with a war external dependency (let's call this war dependency WAR-DEP)
After the build and during the package phase I am taking the content of WAR-DEP and merging it with the content of the current build using the overlay feature of the maven-war plugin.
In WAR-DEP we have some required jars in it's WEB-INF/lib folder so with the overlay we end up getting everything we need in our final war but our problem started when the project providing us with the WAR-DEP war added a new folder in the WEB-INF/lib-new and moved some of the jars we had before in the WEB-INF/lib folder to this new folder WEB-INF/lib-new.
After building with this new version of the WAR-DEP the overlay worked as expected so we ended up having two folders in the WEB-INF (lib and lib-new) and our application stopped working since this WEB-INF/lib-new is not recognized by tomcat server. So without changing the classpath on tomcat side is there a way I can move the content of lib-new into the lib folder before generating the war ? I mean for example during the overlay but I am not sure how to do this.
Thanks for your inputs.
maven-war-plugin does not have required functionality, however maven-dependency-plugin may help, smth. like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>unpack-lib-new</id>
<goals>
<goal>unpack</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>dep-group-id</groupId>
<artifactId>dep-artifiact-id</artifactId>
<version>dep-version</version>
<type>war</type>
<outputDirectory>${project.build.directory}/${build.finalName}/WEB-INF/lib</outputDirectory>
<includes>WEB-INF/lib-new/*</includes>
<fileMappers>
<org.codehaus.plexus.components.io.filemappers.FlattenFileMapper/>
</fileMappers>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
...
<overlays>
<!-- current project -->
<overlay/>
<overlay>
<id>dep-skip-lib-new</id>
<groupId>dep-group-id</groupId>
<artifactId>dep-artifact-id</artifactId>
<excludes>
<exclude>WEB-INF/lib-new/*</exclude>
</excludes>
</overlay>
</overlays>
...
</configuration>
</plugin>

Maven: Unzip nested zip files.

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?

Create a .war file that includes a jar-with-dependencies.jar for JNLP using Maven

I have a Maven project that builds a Swing client as a jar-with-dependencies.jar file. I want to use Java Web Start to distribute this my.gui-0.1.0-jar-with-dependencies.jar file. I've created a separate Maven project that builds a .war file with the JNLP artifacts for this purpose. I need to include the my.gui-0.1.0-jar-with-dependencies.jar in this .war file.
I haven't been able to determine the Maven coordinates for the jar-with-dependencies.jar file. If I use the Maven coordinates for the GUI project it puts the dependency .jar files for the GUI project in the WEB-INF/lib, which is not what I want. I need to have the my.gui-0.1.0-jar-with-dependencies.jar file itself in the .war file. (I suppose it could be in WEB-INF/lib.)
How do I tell Maven that the dependency is the jar-with-dependencies.jar file itself?
If there is another way besides the mechanism to tell Maven to include the jar-with-dependencies.jar itself that would work too. The jar-with-dependencies.jar has to be somewhere in the .war file I'm creating to support Java Web Start.
I know there is a Maven Webstart plugin, but that looks like a nightmare so I'm just building a .war file myself with the necessary JNLP artifacts.
Firstly, what you want is the JAR file to be available to be downloaded by users of the WAR file. Including the file in WEB-INF/lib as a standard dependency of the WAR project is not what you want. What you most likely want is the JAR to be put in a different directory in the WAR (such as /downloads).
To achieve this in Maven, you can use the Maven Dependency Plugin.
1: Use the dependency plugin to copy your JAR file to a temporary build directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.group</groupId>
<artifactId>myartifact</artifactId>
<version>1.0</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/webapp-downloads</outputDirectory>
<destFileName>myartifact.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
here we are copying your JAR file to the ${project.build.directory/webapp-downloads directory
2: configure the WAR plugin to include the resources generated by the dependency plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory/webapp-downloads</directory>
<targetPath>downloads</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
This will cause the JAR file to be bundled in you WAR under the downloads directory. Users can then download it by going to /downloads/myartifact.jar to download it.
In the case of webstart, you would configure your JNLP with the appropriate path instead of having the user directly download the JAR.
If you want to copy the .jnlp file too, like in my case, you could use the unpack goal. This works because the webstart-maven-plugin can pack the jars and the jnlp file into a zip.
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>1.0</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/webapp-downloads</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>

Maven assembly : add different version of the same artifact

I create my application archive with the maven assembly plugin.
All the dependency present in my pom are included without any problem.
Now I need to include two or more version of the same artifact.
If in my pom I put
<dependencies>
[...]
<dependency>
<groupId>db.test</groupId>
<artifactId>my-model</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>db.test</groupId>
<artifactId>my-model</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
Of source the dependenvcy resolver remove the old version and only the 1.1.0 is packaged in the archive
I try to include the jar by using assembly xml descriptor file. And I didn't find any solution.
A possible solution will be to manually put all the needed model.jar inside a folder and tell the assembly to copy it in the archive. But I'm looking for a more configurable solution.
Any idea ?
I found a solution by using maven-dependency-plugin to copy resolved pom dependencies and additional jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
<execution>
<id>copy-model</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.test.pkg</groupId>
<artifactId>my-model</artifactId>
<classifier>server</classifier>
<version>1.0.3</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>my.test.pkg</groupId>
<artifactId>my-model</artifactId>
<classifier>server</classifier>
<version>1.1.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
Now I just have to add the following lines in my assembly xml
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>/lib</outputDirectory>
<filtered>false</filtered>
<includes>
<include>*.jar</include>
</includes>
<fileMode>0600</fileMode>
</fileSet>
Maven assumes it doesn't make any sense to have more than one version of a module at once. It assumes that a newer version replaces the older version. If it doesn't it is not the same module. I suggest you give the newer module a different name and make sure it has different packages to avoid choising a random module.
In general Maven tried to encourage good application design and deliberately makes it difficult to do things it has determined to be a bad idea.
Another ugly solution might be to use WAR file overlays, exploiting the fact that this mechanism pays no attention to the versions of component JAR files when applying the overlays.
I agree, different versions means replacing the older one. If we have to consume two different versions of a webservice for some business requirement. It is a good idea to generate the stubs in different packages and while adding to maven you can specify different them in groupid. This should work.

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