Maven dependency from local file - resolve any (*) symbol - java

I want to use missioncontrol module which is not published at maven repository and is installed with JDK. I could manually install it by mvn install like it's done in this script. But I'd prefer maven to resolve this dependency automatically.
The issue is I don't know exact version of module on each machine (assuming that JAVA_HOME is defined for every machine). And maven does not seem to automatically resolve the * placeholder:
<dependency>
<groupId>com.jrockit.mc</groupId>
<artifactId>com.jrockit.mc.common</artifactId>
<version>LATEST</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/missioncontrol/plugins/com.jrockit.mc.common_*.jar</systemPath>
</dependency>
Is there any proper way to do this? Or is it a bad practice for some reason? Thanks.

Does your jar file name changes with java version

Related

Maven Dependency missing artifact : jhotdraw

I am currently working on a Java project using Maven. In my pom.xml I am getting this error.
Missing artifact org.jhotdraw:jhotdraw:jar:6.0b1
I have added this dependency
<dependency>
<groupId>org.jhotdraw</groupId>
<artifactId>jhotdraw</artifactId>
<version>7.6.0</version>
</dependency>
to my pom.xml. But still the error is same.
Can someone help me?
That version of org.jhotdraw.jhotdraw does not exist on Maven Repository, the last version available on Maven Repository is 7.4.1
Either you have made an error as to the version or group id (I see there is a 7.6.0 package under org.opentcs.thirdparty.jhotdraw, but don't know if it's the same). Alternatively, you may have to manually download and install that package, check out...
How to include custom library into maven local repository

Intellij can not resolve class of external library

Need a help !
I'm trying to connect spring security library to my project using Maven.
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
Library org.springframework.security.core have been downloaded successfully.
But when i'm trying to extend my class(AuthorizedUser.class) from org.springframework.security.core.userdetails.User
Intellij says, that can not resolve it. But other classes and interfaces from: org.springframework.security.core.userdetails resolving well. See the link...
When i goes to external library tree and opened org.springframework.security.core.userdetails library i saw User.class like this See the link...
Please, if anyone knows something about this problem, I'll be very thankful for any information
Windows 7
Intellij IDEA version 2017.2.4 Ultimate
Java version 1.8.0_144
Maven version 3.5.0
Maybe, you just need to create a constructor matching with super class or first try to create a class property instead of extending it just for test. apidoc
if it does not help, probably it is not related to ide, it is possible maven could not resolve dependencies because of some misconfiguration.
You can try these:
1- check local maven repository and confirm right version of jar files are there.
c:\users{username}.m2\repository\org\springframework\security
2- try build from commandline with following command and confirm build finish succesfully
mvn clean install
3- Try reimport all maven project
4 - Also, confirm intellij use right maven version, repository and settings xml. You can write "maven settings" on search bar, ant it will lead you to maven settings page.
if you find any of them is not as expected, let me know so I will try to help.

crystal report jars for maven

I have built a non-maven project to display crystal reports with all necessary jars imported to the lib folder.
But, when I try to find the dependencies to add the same jars into my pom.xml for a maven project, I was not able to look it up online.
How can I find the crystal report dependencies for a maven project ? How to determine groupId and artifact for the crystal jar?
Below is the snapshot of jars I am looking for. Please suggest.
I tried looking into this link in the SCN but couldn't find much details.
You can specify your local jars as maven dependency using "system" scope
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${lib.path}/some_1.0.jar</systemPath>
</dependency>
define 'lib.path' in properties
Below are two solutions : One is pointing to local jars with system scope and the other is deploying the jars into m2. I felt the second solution more reliable.
First solution: I followed the link here ; but couldn't get it entirey working. So changed the scope to system and pointed to the local jars and was able to finally access the classes.
Please see below for the pom.xml
<dependency>
<groupId>com.sap.crystalReports</groupId>
<artifactId>CrystalCommon2</artifactId>
<version>1.0.0-RT</version>
<scope>system</scope>
<systemPath>${lib.path}/CrystalCommon2.jar</systemPath>
</dependency>
.....
Second solution is, from the comment in the question above, I came up with the idea of deploying all the crystal jars, one by one, which I downloaded on my local into my local m2 repository.
mvn deploy:deploy-file -DgroupId=com.crystalruntime.sdk -DartifactId=JDBInterface
-Dversion=1.5 -Dfile= point-to-the-jar-location-on your-local\JDBInterface.jar
-Dpackaging=jar -Durl=file://point-to-local-m2 repository
groupId, artifactId,version- can be modified, but it is good to keep consistency and readability, with the names chosen.
Run this command on any/all the jars that you want to install into m2. I then updated the project and did another clean build and was able to successfully run then application.
Also, I did remove the system scope from the pom.xml
<scope>system</scope>
<systemPath>${lib.path}/JDBInterface.jar</systemPath>
and modified it according to :
<dependency>
<groupId>com.crystalruntime.sdk</groupId>
<artifactId>JDBInterface</artifactId>
<version>1.5</version>
</dependency>
This made more sense to me, to use in the maven project.
This is the link I followed for reference.

Building maven project with custom version of artifact instead of the one from repo

I'm new to maven, sorry for nub question: need to build maven project using my version of artifact instead of the one from repo.
More detailed:
I downloaded jboss sources from github and built them using maven 3. It was great! I need to do some changes in jboss dependancy called "picketbox". Now it is an artifact in jboss's "pom.xml".
I built my own version of picketbox in my_picketbox.jar file. How can I tell maven to use my .jar instead of the one from repo?
Maybe I'm missing something but if you explicitly renamed the artifact then it will just be a matter of replacing picketbox with my_picketboxin the relevant JBoss POM-file(s).
<dependency>
<groupId>...</groupId>
<artifactId>my_picketbox</artifactId>
<version>...</version>
</dependency>
And of course, you make sure your artifact is in your local repo by mvn install'ing it.
Cheers,
i would install the jar file using the maven-install plugin.
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html
First, install your version of Picketbox into your local Maven repository. If your custom version is a Maven project, you can do that by running
mvn install
If your custom Picketbox version is not a Maven project, install the Jar itself into your local Maven repository like this:
mvn install:install-file -Dfile=my_picketbox.jar -DgroupId=org.picketbox -DartifactId=my_picketbox -Dversion=2.3 -Dpackaging=jar
Then change the version of Picketbox that JBoss depends on by adding this snippet to the pom.xml file of the JBoss project you're building (replace the existing dependency on pocketbox with this one):
<dependency>
<groupId>org.picketbox</groupId>
<artifactId>my_picketbox</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>x.x.x</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xxxx.jar</systemPath>
</dependency>
This allows you to reference libaries that are not stored localy rather than maven central.
Maven takes what has been specified in POM files; mind you, that the POM including the dependency you wrote about can be buried very deeply, not even within the sources you downloaded.
Search your project tree for the artifact in question and replace its version number to your version. If this does not help, do as Nils says in the other answer, but remember to install the artifact in the original version (you may have to find it first in your local repository and remove it).

Add a dependency in Maven

How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.
You'll have to do this in two steps:
1. Give your JAR a groupId, artifactId and version and add it to your repository.
If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds:
mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile
You can also deploy it to your internal repository if you have one, and want to make this available to other developers in your organization. I just use my repository's web based interface to add artifacts, but you should be able to accomplish the same thing using mvn deploy:deploy-file ....
2. Update dependent projects to reference this JAR.
Then update the dependency in the pom.xml of the projects that use the JAR by adding the following to the element:
<dependencies>
...
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
You can also specify a dependency not in a maven repository. Could be usefull when no central maven repository for your team exist or if you have a CI server
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>commons-utils</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/commons-utils.jar</systemPath>
</dependency>
Actually, on investigating this, I think all these answers are incorrect. Your question is misleading because of our level of understanding of maven. And I say our because I'm just getting introduced to maven.
In Eclipse, when you want to add a jar file to your project, normally you download the jar manually and then drop it into the lib directory. With maven, you don't do it this way. Here's what you do:
Go to mvnrepository
Search for the library you want to add
Copy the dependency statement into your pom.xml
rebuild via mvn
Now, maven will connect and download the jar along with the list of dependencies, and automatically resolve any additional dependencies that jar may have had. So if the jar also needed commons-logging, that will be downloaded as well.
I'd do this:
add the dependency as you like in your pom:
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
run mvn install it will try to download the jar and fail. On the process, it
will give you the complete command of installing the jar with the error message. Copy that command and run it! easy huh?!
I'll assume that you're asking how to push a dependency out to a "well-known repository," and not simply asking how to update your POM.
If yes, then this is what you want to read.
And for anyone looking to set up an internal repository server, look here (half of the problem with using Maven 2 is finding the docs)

Categories