Suppress maven dependency version suffix in local repository - maven

I have a Spring Boot project that uses SAP Crystal Reports. CR is not published in Maven Central. I imported all of the CR jar files into my Maven local repository. In my projects the jars have the version appended to the jar file name. For one jar file, this causes a runtime error. How can I have that jar not have the appended Maven version?

if you build from source using Maven then you can override the artifact final name in the POM of this project
<finalName>myJar</finalName>
If you run the mvn install manually then you have control of what you store into the Maven repository
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

This is my workaround hack.
The Jar is question is never directly referenced by my project code, it is a runtime library of the Crystal Reports java runtime. I do not need it in the classpath at build time, just in the deployed file built by maven.
My Spring Boot project is deployed as a WAR file so I need to structure my Eclipse Maven project so that the Jar is placed in WEB-INF/lib as a plain web app resource. I do not specify the jar as a maven dependency.
It's a hack because the jar file IS a dependency and SHOULD be specified as a maven project dependency in the pom.xml.
This solves my immediate problem.
I blame SAP for not considering Maven for their Crystal Reports Java runtime.

Related

Adding 3rd Party JAR to Spring Boot War Build intended for a remote Server

I am converting a local Spring boot Jar app to a War build , using an external TomCat server.
Spring Boot app is running using 2 3rd party jars placed in libs folder.
I am facing an issue trying to include these 2 jars to the final war.
Added these jars to the ClassPath intelliJ Artifact settings but no luck.
Tried putting them manually in WEB-INF/lib folder but no luck.
Tried the above method.
<dependency>
<groupId>myJarGroup</groupId>
<artifactId>myJarArtifact</artifactId>
<version>>1.7.0.1</version>
<scope>compile</scope>
<systemPath>${project.basedir}/src/main/resources/xxx/myjar.jar</systemPath>
</dependency>
Again no luck.
WEB-INF/lib is still missing my 2 jars.
Only a type can be imported. ec.ec.ada.ec.common.ec.code.testValidate resolves to a package
testValidate cannot be resolved
Error importing : 'ec.ec.ada.ec.common.ec.code.testValidate'
You will have to incluse these two jars as dependency in pom. I know this is 3rd party depencdency but you can add it like below:
mvn deploy:deploy-file -Durl=file:///path/to/yourproject/repo/ -Dfile=mylib-1.0.jar -DgroupId=com.example -DartifactId=mylib -Dpackaging=jar -Dversion=1.0
This way they will be saved in maven repository and maven war plugin will include same in war that will be generated for deployment.
Here you go!
Although rarely, but sometimes you will have 3rd party JARs that you
need to put in your local repository for use in your builds, since
they don't exist in any public repository like Maven Central. The JARs
must be placed in the local repository in the correct place in order
for it to be correctly picked up by Apache Maven. To make this easier,
and less error prone, we have provide a goal in the
maven-install-plugin which should make this relatively painless. To
install a JAR in the local repository use the following command:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
With version 2.5 of the maven-install-plugin it gets even better. If
the JAR was built by Apache Maven, it'll contain a pom.xml in a
subfolder of the META-INF directory, which will be read by default. In
that case, all you need to do is:
mvn install:install-file -Dfile=<path-to-file>
From a Maven Guide to installing 3rd party JARs.

Using jars which have no dependency tag in Maven's pom.xml

I have a web application which needs to be converted to Maven for building and deploying.
I was able to find dependency to add in pom for most of the jars but was not able to find dependency tag for few jar files.
How do I add these jars to my application so that my application compiles ?
Can I add these jars for Maven from web-inf/lib or some other location ?
You can install jars manually to your maven repository using the maven-install-plugin:
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

where to place customer jar in maven project structure

I have a dependency application jar from other maven applications,and currently added it to my application path,
I want to know how this application related jar can be automatically moved my local repository folders.
I think it should be placed in somewhere in maven project folder structure so that when maven build the module it automatically moves to the repository.
Dependent project:
If built with maven, you would issue a mvn install, when building it.
If not built with maven, install it locally using mvn install:install-file
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html

Include java webapp lib in maven build

I was having a dynamic webapplication created on eclipse. I converted it to a maven project using M2E plugin. I added maven war plugin in the pom.xml so that it can create war for my project using maven build.
But when I do the build, it fails to compile few classes which has reference to the jars of my webapp/Web-INF/lib folder. These jars I can't include as dependency in pom.xml.
How can I tell maven to include Web-INF/lib jars also while building classes and creating a war?
Its not correct way of doing this , you should not put any jar manually in WEB-INF/lib folder.
And if that jar is not available in MAVEN CENTRAL REPO , then you can download it and install it in your NEXUS CENTRAL REPO (if you have any) otherwise put that jar in your local maven repository and add it as a dependency in your pom file. If you don't want to include that jar in your WEB-INF/lib then change the scope to provided otherwise leave it as default i.e compile.
During build time MAVEN will look for that particular jar in your local repo first , and if it don't find it there then it try to download from Centra Repo.
Once it is available in your local repo , your build won't break.

Warning POM missing in the jar

I have created the jar through maven from some other project. The jar reside in the location repository. The jar contains the pom.xml file in META-INF/maven///pom.xml
and pom.properties.
I have also copied the pom.xml file while running the pom for that project using resource-copy
plugin. Still I am getting the below warning , there fore during the building of war the maven not able to include all the dependent jars of the above jars in the war file. Other option is to add thoses jars as a runtime dependency in my war pom file.
[WARNING] The POM for org.artifact:runtime.ui:war:1.0.0-SNAPSHOT is missing, no dependency information available
I found that only goal packaging will put the artifact in a local repository. But then for each artifact I need to do the install so that it will get in the files system repository with the pom file. Copying the pom file using resource plugin will not help.
Hi you need to install the specific jar to your local repository (for a start).
If this jar is properly packaged using maven you can issue the following command from the terminal:
mvn install:install-file -Dfile=<path-to-file>
If it is custom made you need to include the required parts like
mvn install:install-file -Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging
Please see the official documentation here.
Hope it helps

Resources