how should we remove dependency jar conditionally from maven - maven-2

we have project that run on two different server. Tomcat and Weblogic.
but there are few dependency jars which are conflicting in weblogic because weblogic built in library have those jars.
So we have to delete those jars manually.
We are planning to delete do through pom.
One solution is we can make two separate for pom (one for tomcat and one for weblogic).
which is actually not sounds good.
We are thinking some how we can do profile based dependency exclusion. but any able to find any like for the same.
Please let me know if someone has some better suggestion.
We already tried to exclude jar from weblogic lib but unable to do it successfully.
All suggestions are openly invited.

You can use maven profiles for building slightly different versions of your project for different application servers.
You can read about maven profiles
Here
Hope this helps

Related

Using Hive in a maven project

I have a project that I am migrating from ant to maven. The project makes use of a lightly-customized Hive build. I figured I would just import this build into our internal maven repo and list it as a dependency in the project's pom file. The problem I'm running into is that the Hive build just generates a bunch of jars in build/dist/lib. Some of these are the core Hive jars themselves and some are jars that Hive depends on. What's the best way to deal with these? Should I put all the core hive jars into our internal repo and just deal with undocumented dependencies in the new project's pom file? Or just jar up everything as a jar of jars and deploy that to the repo? Would that approach even work? Kind of a maven newbie still, thanks for any help.
You should create a POM for your modified Hive build, and deploy it to your internal artifact repo along with the jar. This POM should specify any dependencies (i.e., those other jars). If some of those are also custom versions, you should create POMs for those as well, otherwise just use the standard public groupId/artifactId. This is the Maven way. Note that you don't necessarily need to use the POM for building Hive, just during deployment.
Why you should do this:
If you don't specify the dependencies correctly, you might run into issues when someone forgets to include the full set of dependencies in their project, or specifies the wrong version for one of them
If you create a jar of jars, you might run into issues when someone tries to use the custom Hive "uber jar" as well as a different version of one of those dependencies at the same time. You'll end up with multiple versions of the overlapping classes in the classpath.
The best thing for Maven is always if you tell it everything that is going on. Don't try to tell it what you think it wants to hear.

Problems with Maven 2

I recently started to use Maven2 in one of my Java web application projects. Now I had many issues with it, some times project fails to build for no apparent reason and then it suddenly starts to work when nothing was done at all to project. Or some times our project members must delete project from their harddrive and download project again from SVN. There seems to be many very odd bugs in Maven in eclipse, but there some issues I would like know if it is possible to solve this issues.
1) I have understood that Maven2 should be able to get dependencies for added jars, but when I add a new dependency in Eclipse, it fails when I build it, it says dependecies are missing. How can I make maven to download those missing dependecies automatically?
2) I have Tuckey UrlRewrite Filter in use, but public repositories have only old version of this dependecy, so when I use this old version (3.1 when I need 3.2). How can I include this to project? We have many programmers in this project, so setting up local repository would mean that all our programmers would have to install that local repository.
Now I had many issues with it, some times project fails to build for no apparent reason and then it suddenly starts to work when nothing was done at all to project. (...)
Ok and what is the point of this free rant? I use Maven and my builds are 100% reproducible, there are well known practices to follow to achieve this. Maybe you're just not following them. Anyway if you're not happy with it, what can I say, don't use it.
I have understood that Maven2 should be able to get dependencies for added jars, but when I add a new dependency in Eclipse, it fails when I build it, it says dependencies are missing. How can I make maven to download those missing dependencies automatically?
I think you misunderstood, Eclipse won't guess what Maven coordinates to add if you don't provide the required informations for them. Dependencies must be declared in the POM, either by editing the POM manually or by using m2eclipse wizards.
And if this is what you did (and if I misunderstood the question) then please provide the <dependency> declaration and the exact error trace.
I have Tuckey UrlRewrite Filter in use, but public repositories have only old version of this dependecy, so when I use this old version (3.1 when I need 3.2). How can I include this to project? We have many programmers in this project, so setting up local repository would mean that all our programmers would have to install that local repository.
This question has already been asked several times, see for example Maven, how to add additional libs not available in repo where I suggest two possible solutions (use a corporate repository like Nexus or a "file-based" repository, the former suggestion being the preferred one for a long term solution).

converting websphere portal project to maven

I am working on converting websphere portal project to maven framework for CI build. I am wondering if there is a way to reference websphere jars other than via dependencies in pom.xml and loading them all to maven repository? I cannot imagine loading them ALL to the repository...
Please advice! Thanks!
When using Maven, it is advisable that all dependent jars are installed in the repository. Even Websphere ones.
Ideally a corporate repository will come in handy here, so that you keep a separate repository for all the Websphere jars accessible to all the users in your project. See http://maven.apache.org/repository-management.html for more.
If this is not an option, then use the local file repository explained on a previous questions - here.
You'll still need to add each dependency in POM.
Also read http://sdudzin.blogspot.com/2007/09/maven-2-and-websphere-automated-build.html
if you have a lot of projects that require this, you can also create a parent pom that would have all the dependencies so your project/module/portlet poms are cleaner.

hunting maven dependencies

I want to start using maven in code I distribute but I can't find an efficient way to work with dependencies. Every new dependency takes me far too long to add.
As a simple example, I need to add Tomcat for compilation. Do I really have to manually trawl the repo in my browser to find the group-id, artifact-id and version number?
In every case it seems easier to find the non-maven downloads. I hope I've missed something obvious.
Do I really have to manually trawl the repo in my browser to find the group-id, artifact-id and version number?
No. Use a repository search engine. Some are mentioned here, more here. Some IDE also offer facilities to search and add dependencies (e.g. Eclipse with m2eclipse).
First of all, using some IDE really helps. Eclipse has m2eclipse plugin and if you define locations of remote maven repositories in your pom definition, you can add dependencies in its pom editor and it will automatically search the proper artifacts for you.
What is really helpful is using repository manager like Nexus / Artifactory, where you gather the most important maven repositories and then you don't need to declare particular repository locations in your pom definition for various artifacts, but everything will be proxied via Nexus.

How do I add 3rd-party OSGi bundles to a deployment package with Maven?

I'm building my application to run in an OSGi container. I use Maven and the Maven Bundle Plugin from Apache Felix to set up the OSGi manifests for my own modules and that works great.
Now, I'm deploying my bundles into an OSGi container together with several 3rd party libraries. Some of these are already OSGi-fied when I get them from the Maven repos, others, I want to convert into OSGi-compatible jars. I want to set up a Maven project that collects all dependencies, and puts each in its own OSGi jar. The ultimate goal is to collect these jars and my own into an assembly that I can use as a standalone deployment package.
I know how to convert standard jars to OSGi jars, and I have a (somewhat hackish) approach to merge multiple OSGi bundles, even if I probably shouldn't. But if I have a dependency that's already fine as it is, and I just want to copy it from the repo into my assembly, what part of Maven do I use? The bundle plugin is wrong, it messes up the manifests if a dependency is already OSGi-compatible. Do I use the dependency-plugin, the assembly plugin or something else?
I have the feeling I'm overlooking something very simple here.
Did you have a look at the PAX tools? In particular Pax-Runner and
pax-construct... They do not only give you a nice template to start with, but also solve most the problems you mentioned for free.
We use many libraries which are not OSGified by the vendor and which are not available on the Spring bundle repository. We also have many of these and want to deploy them all together hassle free. For this we have created a 2-layer maven setup:
Individual maven projects that either download or contain (as 'system' scope depends) the 3rd party lib in question, and OSGify these using the Apache Felix bundle plugin
One container project that has a dependency on all of these small projects and makes an assembly of them using the core assembly maven plugin. This POM also uses the copy-dependencies goal of maven to make sure everything is in place.
Once it is turned into an assembly (ours is a tar file) we deploy this to our servers. We have gone one step further and used this assembly of 3rd party libraries as the Target Platform for our Eclipse build environment. But this may be irrelevant for you.
You can get OSGi friendly versions of many common artifacts from the Spring bundle repository. So you may not have to do it yourself.
See details of how to configure the bundle repository for Maven.
(will update with some ideas for those that aren't available as bundles already)