Maven Include dependencies in Executable Jar - maven

Am new to Maven...
Trying to create a simple applet.
Include dependencies for the applet.
For this I have tried :
<repository>
<id>lib</id>
<name>lib</name>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/lib</url>
</repository>
I have these files included in the lib folder under my project structure.
this lib contains couple of jar files and a JNI dll which I need to use in my applet.
Is there any better option to create repository than the above,Kindly share?
Packaging applet jar with dependencies.
For this I have tried :
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
I expect the above to wrap my dependencies into one single jar, but its not been the case.
the generated jar file size doesnt contain the dependency jar files.(I can say coz the size of the jar file remains unchanged for both jars with and without dependencies are same)
Am I in the right way of doing things with Maven?

Take look at shade plugin, this plugin creates executable "uber jar" or if you realy need something really complicated assembly plugin.

Related

Not able to download Jars from nexus

I have project A which is dependency of project B. Since project B should get latest jar version of Project A . I purge Project A jar from local so Project B will get Project A jar from nexus since it has been deleted from local.
I can see in the logs that It can download jar from nexus . but still getting pom for jar is missing
below are the logs
Downloading from : ://10.245.240.43:8081/nexus/repository/maven-snapshots/com/sgl/smartpra/master/model/smartpra-master-model/0.0.1-SNAPSHOT/smartpra-master-model-0.0.1-20191126.094645-53.jar
[INFO] Downloaded from : ://10.245.240.43:8081/nexus/repository/maven-snapshots/com/sgl/smartpra/master/model/smartpra-master-model/0.0.1-SNAPSHOT/smartpra-master-model-0.0.1-20191126.094645-53.jar (183 kB at 1.7 MB/s)
The POM for com.sgl.smartpra.master.model:smartpra-master-model:jar:0.0.1-20191126.094645-53 is missing, no dependency information available
You can see that it can able to pull jars from nexus still getting artifact missing.
I added maven plugin to perge dependent jars from local so it will pull latest jar from nexus
refer Below snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>purge-local-dependencies</id>
<phase>process-sources</phase>
<goals>
<goal>purge-local-repository</goal>
</goals>
<configuration>
<includes>
<include>com.sgl.smartpra.global.master.model:smartpra-global-master-model</include>
<include>com.sgl.smartpra.batch.global.model:smartpra-batch-global-model</include>
<include>com.sgl.smartpra.master.model:smartpra-master-model</include>
<include>com.sgl.smartpra.exception.txn.model:smartpra-exception-txn-model</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Below is nexus repository configuration for downloading jars from nexus
Please check below code
refer Below snippet
I have project A which is dependency of project B. Since project B should get latest jar version of Project A . I purge Project A jar from local so Project B will get Project A jar from nexus since it has been deleted from local.
<repositories>
<repository>
<id>maven-group</id>
<url>**strong text**/10.245.240.43:8081/nexus/repository/maven-group/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>

How do I include a Maven plugin from a local repository?

I have a custom plugin that compresses files that I need to include in my maven build. So I have included this plugin in my pom.xml:
<build>
// Other tags
<plugin>
<groupId>someGroupId</groupId>
<artifactId>somePlugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Since it is a custom plugin, it is not available in any public Maven repository. So whenever I try to build, I get an error message saying:
Failed to read artifact .....
even though I have added it to my local repository. How can I refer to this plugin that is in my local repository?
If you mean local repository in the classic sense, make sure that you installed your plugin jar correctly. Install it to your local repository again with the following command:
mvn install:install-file -Dfile=/some/path/somePlugin.jar -DgroupId=someGroupId -DartifactId=somePlugin -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true
You should then be able to use your plugin in your Maven build.
If you mean local in the sense of some locally hosted repository, you need to specify the repository containing your artifact as a pluginRepository. Add the following to the top level of your pom.xml:
<pluginRepositories>
<pluginRepository>
<id>some-repo</id>
<name>Some Repository</name>
<url>http://some.host/some/path</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

Not downloading converted OSGI bundles from custom p2 site using Maven

My project is in RCP. The product is created using Maven. My RCP project depends on third party jars. Currently we are adding these jars in plugin.xml "runtime". So whenever there is change in third party jars, we have to update the plugin.xml file.
Now we are changing the process by converting the third party jars in to OSGI bundle using maven then create p2 site and while building, add the third party OSGI bundles in classpath.
We have done the conversion to OSGI bundle and creating p2 site. But when we are adding it in repository, the converted third party OSGI bundles are not always get download.
We have added below code in pom.xml to convert in to OSGI bundle and create p2:site:
<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.2.0-SNAPSHOT</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<artifact><id>com.test.proj:proj-jar1:6.01.00-SNAPSHOT</id></artifact>
<artifact><id>com.test.proj:proj-jar2:6.01.00-SNAPSHOT</id></artifact>
<artifact><id>com.test.proj:proj-jar3:1.1</id></artifact>
<artifact><id>com.test.proj:proj-jar4:1.0</id></artifact>
<artifact><id>com.test.proj:proj-jar5:1.0</id></artifact>
<artifact><id>com.test.proj:proj-jar6:6.01.00-SNAPSHOT</id></artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.5.v20120716</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppSourceDirectory>${basedir}/target/repository/</webAppSourceDirectory>
<webApp>
<contextPath>/site</contextPath>
</webApp>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>0.22.0</version>
<extensions>false</extensions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>reficio</id>
<url>http://repo.reficio.org/maven/</url>
</pluginRepository>
</pluginRepositories>
To download while build we have added:
<repositories>
<repository>
<id>extJars</id>
<url>http://localhost:8080/site/</url>
<layout>p2</layout>
</repository>
</repositories>
When we call "mvn install" it is not downloading the jars from "http://localhost:8080/site" every time.
So please let me know what is going wrong in my pom.xml
Any help is appreciated. Thanks
In Maven you cannot build something and then depend on it dynamically in one reactor. This way the build dependencies cannot be computed. You either have to
Build your p2 update site
Build the rest
or you should use something the m2e people call wrapper bundle. They used it in this pom.xml.

maven does not change the snapshot jar file in local repository

We config jfrog artifactory successfully and create a pom.xml to build and deploy our basic jar files into it as snapshot. then we configure another project to get those jar files from repository and it did successfully too, then we try to change basic libraries and deploy it again as the same snapshot name, and it did correctly but when we want to get those libraries again, maven does not change the basic libraries in local repository, unless we change the version of the snapshot but we don't want to do it.
deploy pom.xml configuration file
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>2.2.2</version>
<inherited>false</inherited>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>publish</goal>
</goals>
<configuration>
<deployProperties>
<gradle>awesome</gradle>
</deployProperties>
<artifactory>
<includeEnvVars>true</includeEnvVars>
<timeoutSec>60</timeoutSec>
<propertiesFile>publish.properties</propertiesFile>
</artifactory>
<publisher>
<contextUrl>{{ARTIFACTORY_CONTEXT_URL|"http://tls.local:9081/artifactory"}}</contextUrl>
<username>admin</username>
<password>AP5PqkrxgwKVMBeY6wxPYr66R3M</password>
<excludePatterns>*-tests.jar</excludePatterns>
<repoKey>libs-release-local</repoKey>
<snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
</publisher>
<buildInfo>
<buildName>plugin-demo</buildName>
<buildNumber>{{DRONE_BUILD_NUMBER|TRAVIS_BUILD_NUMBER|CI_BUILD_NUMBER|BUILD_NUMBER}}
</buildNumber>
<buildUrl>{{DRONE_BUILD_URL|CI_BUILD_URL|BUILD_URL}}</buildUrl>
</buildInfo>
<licenses>
<autoDiscover>true</autoDiscover>
<includePublishedArtifacts>false</includePublishedArtifacts>
<runChecks>true</runChecks>
<scopes>compile,runtime</scopes>
<violationRecipients>build#organisation.com</violationRecipients>
</licenses>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
third party pom.xml configuration file:
<repository>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://tls.local:9081/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
How can we achieve our goal?
first we must configure our jfrog repository's maven snapshot version behavior to unique and check handle releases and handle snapshot and then delete completely our local repository's snapshot

Usage of maven ${basedir} in multi-module setup

I am using a local repository as described in Maven: add a dependency to a jar by relative path.
The repository-url is defined in the topmost pom.xml as
<url>file:${basedir}/../3rdParty/maven-repository</url>
Also, the topmost pom.xml defines 2 modules
<modules>
<module>sub1</module>
<module>sub2</module>
</modules>
The problem is, that if a module (say sub1) defines a dependency that should be downloaded from the repository, and maven is called from the topmost directory, the ${basedir} is not set to this directory, but to sub1, resulting in a wrong repository-URL.
So, say the project with the topmost pom.xml resides in
/Development/myproject/pom.xml
And the repository is in
/Development/3rdParty/maven-repository
Then the repository URL should be set to
/Development/myproject/../3rdParty/maven-repository
but it turns out it is set to
/Development/myproject/sub1/../3rdParty/maven-repository
which of course does not exist.
Any idea why that is the case?
Although it is annoying in your case, this is well-known and intentional. A maven project should know about its execution directory only, no matter in what context it is executed.
I asked almost the same question: Maven variable for reactor root earlier, and the only answer that made sense was to use ${user.dir}, although it's hacky and will not work if you build from a module directory.
(There is also this very verbose solution: Maven2 property that indicates the parent directory)
You can determine the root directory of a module with this nice plugin:
<plugin>
<groupId>org.commonjava.maven.plugins</groupId>
<artifactId>directory-maven-plugin</artifactId>
<version>0.3.1</version>
<executions>
<execution>
<id>directories</id>
<goals>
<goal>directory-of</goal>
</goals>
<phase>initialize</phase>
<configuration>
<property>maven-parent.basedir</property>
<project>
<groupId>my.group</groupId>
<artifactId>maven-parent</artifactId>
</project>
</configuration>
</execution>
</executions>
</plugin>
Use the directory like this: ${maven-parent.basedir}
How about having multiple repos?
<repositories>
<repository>
<id>ibm-jars-bundle-lv0</id>
<url>file://${basedir}/ibm-jars-bundle/repo</url>
</repository>
<repository>
<id>ibm-jars-bundle-lv1</id>
<url>file://${basedir}/../ibm-jars-bundle/repo</url>
</repository>
<repository>
<id>ibm-jars-bundle-lv2</id>
<url>file://${basedir}/../../ibm-jars-bundle/repo</url>
</repository>
</repositories>

Resources