WebLogic client jar - maven

I want to use Java with JMX to monitor WebLogic. I need to use wlclient.jar which is provided into WebLogic lib directory.
Is there any maven repository which I can use to download the wlclient.jar?
The only way that I found is to manually import the jar file into my repository but this is not a option for me.

Another alternative is to create an in-project repository. This makes your project truly portable. This method is similar to the 'Use Dependency with system scope' mentioned by A. Di Matteo, except that it has the added benefit of being able to use any scope (and not just 'system').
I had the same issue as you, using a jar which was not available in Maven Central and after exploring all of the possible options, I settled on the in-project repository which I believe is better that system-scoping a dependency since it frees you to choose the scope.
Steps to do this:
Create a sub-directory called 'lib' in your project
Add this lib as a repository in your pom
<repositories>
<repository>
<id>lib</id>
<name>In Project Repo</name>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
Install the artefact to your lib directory:
mvn install:install-file -Dfile=myArtifact.jar -DgroupId=x.y.z -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -DgeneratePom=true
And, finally use the dependency like you would use any other dependency
<dependencies>
....
<dependency>
<groupId>x.y.z</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</dependency>
</dependencies>

If you can't find the jar in any Maven repository, you could apply any of the following actions, depending on your needs:
Internal Maven Repository
If you don't have an internal repository (like Artifactory or Nexus), normally used in companies as internal maven cache/proxy/point-of-control, but could also be an option to install it and run it locally.
You could then upload the library there, providing Maven GAV (GroupId, ArtifactId, Version) and make Maven pointing to it as a repository (for your, for your CI server if any, for your colleagues if any). You can then add the library as standard maven dependency.
This solution has longer set-up, but better maintainability.
Install the library in local cache
You could use the Maven Install Plugin and install the library to your local cache, as shown by this official example.
Basically, you could run the following command:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=path-to\wlclient.jar -DgroupId=weblogic -DartifactId=wlclient -Dversion=1.0.0 -Dpackaging=jar
It will copy the library to your local Maven cache with standard Maven GAV. However, as above, you should make sure to replicate the same set up on any CI server and any team mate machine as well. You can then add the library as standard maven dependency.
This solution has quicker set-up, but lower maintainability though.
Both solutions however affect the portability of your build (build would fail if someone tries to build it outside of your company network or team).
Use dependency with system scope
You can have the jar as part of your project and point at it via the system scope for that dependency.
<dependency>
<groupId>weblogic</groupId>
<artifactId>wlclient</artifactId>
<version>1.0.0</version>
<systemPath>${basedir}/path/to/library/wlclient-1.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
You should rename the jar though in order to be compliant with Maven conventions.
This solution is more portable, requires much less set-up, but again it needs to be maintained and requires a check-in of the concerned library as part of your versioned project (some may strongly disagree on this practice).

Related

In a Springboot Maven project, how to reference from another Jar?

I have a SpringBoot Maven project. I am dependent on another set of libraries. Currently am pointing to their repository path , downloading it to .m2 repository and using.
But the repository website is not reliable. SO I wanted to package the dependent libraries as part of JAR in the resources folder.
After putting the jars in resource folder. How can I get references of the Types/libraries ?
Currently:
<dependencies>
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-core</artifactId>
<version>5.23.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>www.dcm4che.org</id>
<name>dcm4che Repository</name>
<url>https://www.dcm4che.org/maven2</url>
</repository>
</repositories>
You can put all your libraries in a single folder either in your project or in some folder in your local. You can then add them to your maven POM.
Lets say you put all your jars in a folder called libs in your base project directory. You can then add something similar to the below in your maven POM.
<groupId>com.abc.xyz</groupId>
<artifactId>my-artifact-id</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/libs/my-jar-name.jar</systemPath>
You need to use the scope system. Excerpt from Maven website,
Scope : system - This scope is similar to provided except that you
have to provide the JAR which contains it explicitly. The artifact is
always available and is not looked up in a repository.
Maven Documentation
If you read further, it also mentions that this has been deprecated. So, its a nice quickfix or a hack but then the best thing would be to set up a repository manager as suggested by others.

How to add dependencies to pom.xml in IntelliJ 14

I have a few dependencies in Project Structure/Libraries in IntelliJ 14. How can I add them to my maven pom.xml? There is one single tutorial on IntelliJ's website that does not work for me. I don't want to manage them manually.
The proper way to do this would be to install the dependency artifacts (most likely jars) into your local maven repo, like this.
How to install artifacts to your local maven repo
And then add the dependencies into your pom.xml
<dependencies>
<dependency>
<groupId>com.something</groupId>
<artifactId>artifact</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
Yes, this does require going through each artifact manually, one at a time, but it's a one time setup process.
That is the "proper" way. After that, you can do away with library dependencies in your project structure (they will be picked up correctly via maven).
There is the alternative possibility to "hack" in your project libraries path as a sort of "embedded" maven repo in your project, but that's a little bit hacky and I wouldn't advise that.

install JAR from remote repo (clojar)

I want to download and install this Clojure library but cannot for the life of me figure it out. I researched Maven, but couldn't get it to find the repo. How can I easily install a Clojure library onto my machine?
You could add the repository containing this jar to your pom or settings file and specify the relevant jar as a dependency.
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
...
<dependency>
<groupId>clj-http</groupId>
<artifactId>clj-http</artifactId>
<version>0.4.1</version>
</dependency>
download https://clojars.org/repo/clj-http/clj-http/0.4.1/clj-http-0.4.1.jar
mvn install:install-file -DgroupId=clj-http -DartifactId=clj-http -Dversion=0.4.1 -Dpackaging=jar -Dfile=clj-http-0.4.1.jar
If you are using Leiningen you can just read all about how to connect to repository server on a recent Sonatype blog post from Tim O'Brien.
If you are using Maven you should get a repo server like Nexus and setup the clojure repo as another proxy repository and add it to your public group.
If neither of these approaches is ok with you you can use Raghurams approach or number23_cn. Both of them however are semi optimal and will not scale for teams or many artifacts..

How to include jar in Maven Netbeans proj that doesnt exist in maven repo

I am using Netbeans to build a Maven project, and have the JTidy java library as a dependency. It turns out JTidy doesnt exist in any maven repos, so I can't just add a "normal" depedency entry for it.
What is the best way of handling dependencies to libraries in Maven projects that arent available on repos?
I've currently tried adding it to my maven pom as such (after copying the jar to my projects /libs folder)
<dependency>
<groupId>org.w3c</groupId>
<artifactId>org.w3c.tidy</artifactId>
<version>9.3.8</version>
<scope>system</scope>
<systemPath>${basedir}/libs/jtidy-r938.jar</systemPath>
</dependency>
However it complains that it will be unresolvable by dependent projects.
First of all, it's under another groupId, that's why you didn't find it.
<dependency>
<groupId>net.sf.jtidy</groupId>
<artifactId>jtidy</artifactId>
<version>r938</version>
</dependency>
Jtidy
But to answer your question, one way of doing this is to manually install it in your local repo as described here.
The best way IMHO is to add it to a proxy like Nexus. That way other people can access it from there without having to install it locally. However, this means you have to set up a repository manager, which doesn't make much sense if you are the only developer on the project.

Instruct Maven to use Ivy's generated classpath

We are adding new code to an existing project that uses a custom build system developed with Ant and Ivy for dependency management.
Our new team is used to Maven and its features like testing execution, cobertura reports, etc.
Our question is: is it viable to add a pom.xml matching the current project structure, but instruct Maven to load its classpath from the "lib" dir already filled by Ivy?
In other words: we want to use Maven without its dependency management.
One really dirty approach would be to generate one big jar from the libdir and config the pom.xml to include just that... but we believe there should be cleaner approach.
Any idea or recommendation?
Note: we are not interested in generating a pom.xml with dependencies from the Ivy config, we just want Maven to rely on Ivy's generated classpath. No need to discriminate between test/runtime/compile classpath.
This is our final setup to solve this:
For each Ivy legacy project, use ivy:makepom and manual inspection to figure out the dependencies that we need to send to the new projects (Maven-based). This is a one-time process for each project.
Modify the legacy build system in a way that, every time a project is built, the identified dependencies are also exported to a mvn repo. Because de build machine holds the internal repo, we just use mvn install.
In the new maven projects, declare each dependency in the pom.xml and make sure the build system runs maven builds after the legacy builds.
Thank you all for your help!
One possibility is to use the system scope to define your dependencies in maven. This allows maven to use the jars downloaded by ivy for its dependencies.
e.g.
<dependencies>
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact</artifactId>
<version>a.b.c</version>
<scope>system</scope>
<systemPath>${basedir}/lib/artifact-a.b.c.jar</systemPath>
</dependency>
...
</dependencies>
Maybe the makepom task will be helpful, it creates a pom from the ivy file.
Example from that page:
<ivy:makepom ivyfile="${basedir}/path/to/ivy.xml" pomfile="${basedir}/path/to/module.pom" conf="default,runtime">
<mapping conf="default" scope="compile"/>
<mapping conf="runtime" scope="runtime"/>
<dependency group="com.acme" artifact="acme-logging" version="1.0" optional="true"/>
</ivy:makepom>

Resources