Include java webapp lib in maven build - maven

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.

Related

Maven artifact not uploaded with pom file

I have a backend multimodule maven project, that is build on jenkins with mvn clean package command (maven version 3.3). After a sucessfull build I upload two of the maven subprojects target/*.jar to private nexus (using Nexus artifact uploader plugin). The jars from target folders are uploaded correctly, but the pom is not (there is no option in the plugin to upload the pom).
Then I have my webapp project, where I have dependency to the two artifacts on my private nexus. They are found and downloaded, but not the pom. Building the webapp project fails, because the dependencies are not resolved for the two jars. A warning is printed out during build:
[WARNING] The POM for <groupId>:<submodule-artifactId>:jar:1.0.0 is missing, no dependency information available
That is reasonable - I can clearly see in nexus repository that it has only jar, md5 and sha files. How should I build my multimodule maven project in a way I would be able to reference only submodules in my webapp project? Or should I upload the submodule projects poms manualy?
I am open to upload the whole backend project to nexus, but I would like to be able to add only subprojects as dependencies to my webapp.
Since you are using a private nexus, you need to specify in your maven where to look for your artifact. Usually the way to do it is to specify a repository configuration in your pom.xml as specified in this link. This will tell maven to contact your private nexus for your artifacts.

How non maven project can be added as a dependency in maven project

One project A is added in project B as a source.
I want to add in POM.xml of project B.
1-A is non maven project.
2-B is Maven project
How non maven project can be added as a dependency in maven project as a dependency.And I don't want to run it as a separate project and place the jar in local repository.
You need to put the "non-maven-jar" into the local (or a remote) repository. You can either build it and use mvn install:install-file to install it locally (or the deploy plugin to use a remote repository) or you need to change project A into a Maven project.
Technically, it is also possible to include a dependency by a path (<systemPath>), but this is not recommended.

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

tycho plugin + maven-dependency-plugin: copy dependencies from local projects instead repositories

Main Goal: deploy a project as jar and eclipse-plugin
current state: project builds fine as jar package
Now i want to create a second project which wraps the jar project as eclipse plugin
use tycho-maven-plugin to create eclipse-plugin
add the jar of the original project (with copy-dependency)
add an Activator
export packages from jar
create correct MANIFEST.MF
i tried to copy the jar with copy-dependencies bound to create-resources. This works as long the jar is found in repository, but the local project gets ignored.
This results in a build failure since the jar is not found.
Is it possible to tell copy-dependencies to take the jar from the target directory of the project? Or should i use some other method than using tycho?
Edit:
I solved my problem with 4 projects:
normal project (nothing special here)
the wrapper project using tycho maven and copy-dependencies.
bound copy dependencies to some goal before compile (e.g. generate-resources). Excluded all artefactid which were set as dependency in the MANIFEST.MF.
a prepare project, which calls the normal project and installs it into the repo. This is needed because the tycho-maven-plugin is bound to validate and it is not possible to call the exec plugin beforehand (at least not easy).
a multi module project which calls the prepare project before the wrapper project.
Build your local project (which artifact was missed) with "mvm install". It will be deployed in your local repository ($USER_HOME$/.m2/repositories). After this dependency should be resolved.
Alternatively you can "mvn deploy" if you have local company maven repository like Artifactory or Nexus.

Resources