Maven swizzle dependency doesn't work - java

I try to compile this pom file but it doesn't download
import org.codehaus.swizzle.confluence.*;
dependency. I get pom file from maven's site. Search Maven Swizzle

That's the POM of the swizzle-confluence library, i.e. the POM file that the library's project uses for its own build.
Instead, you need to add the dependency declaration for this library to your project's POM. In Maven Central search, this is available on the left-hand-side of the version information page, under Dependency Information.
So, open up the page for swizzle-conflunce:1.6.2, and you can see that this is:
<dependency>
<groupId>org.codehaus.swizzle</groupId>
<artifactId>swizzle-confluence</artifactId>
<version>1.6.2</version>
</dependency>
Also, to help yourself in the future, consider reading about the POM and how dependencies work.

Related

Adding Stanford CoreNLP 3.9.2 as Dependency via Maven

I'm trying to add Stanford CoreNLP 3.9.2 as dependency to my Eclipse/Maven project:
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
</dependency>
Next to my POM.xml file I see a little red x icon. When I open POM.xml there is no additional information regarding the error.
When I click on Java -> Properties -> Java Build Path -> Maven Dependencies I see that the Jars that were expected to be added to Maven via this dependency are missing. This is odd because I regularly add dependencies this way without any error.
Apparently, something is preventing Maven from downloading the dependencies. What could it be?
Update:
I changed POM file to version 3.5.2 (instead of 3.9.2) and now all errors are gone.
If anyone can explain WHY this solved my problem (and how to make things work with version 3.9.2) I will accept it as the answer.
Update:
When I go to my Maven repository I see that most of the required Jars have been downloaded by Maven. For example, Maven repository will contain the folders: \\maven\.m2\repository\edu\stanford\nlp\stanford-corenlp\3.9.2 However the folder will not contain the Jar: stanford-corenlp-3.9.2 - but it will contain every other Jar such as stanford-corenlp-3.9.2-models and stanford-corenlp-3.9.2-sources etc.
This makes the whole situation even more confusing. If Maven is downloading the Jars why is it skipping just one Jar? I looked in several other folders (dependencies of corenlp) and I see similar phenomenon - it's always the main Jar of that folder that is missing.
What's worse, when I download and add the missing Jars manually to Maven folder, the (missing) text next to Jar goes away but there's still a little red x icon next to POM file. I have no idea what is going on.
Any insights?
Thanks!
I have no idea why this fixed the problem but in my POM file I had an entry:
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.debug.core</artifactId>
<version>3.13.0</version>
</dependency>
I update this dependency to:
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.debug.core</artifactId>
<version>3.14.0</version>
</dependency>
Now all errors have disappeared.

NoClassDefFoundError on Maven dependency present locally

I am new to Maven Project. I am making changes to one of the open source maven project. I am facing a problem in adding a library to the project. So far i have done this :-
I added a library named jni4net.j-0.8.8.0.jar to the resources folder of the project.
I right clicked the jar(in Intellij) and clicked 'Add as library'.
Then in the pom.xml i added:-
<dependency>
<groupId>jar.0.8.8.0.jni4net</groupId>
<artifactId>jar.0.8.8.0.jni4net</artifactId>
<version>0.8.8.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/jni4net.j-
0.8.8.0.jar</systemPath>
</dependency>
But when i build this project(build is successful, test cases are running) and use this it throws following error:-
java.lang.NoClassDefFoundError: net/sf/jni4net/Bridge
Please help me resolve it. I am new to maven and pom. I have looked at various answers, but not getting it right.
PS - I named groupId and artifactID as just reverse of jar file
This is not the right way to add that dependency.
All you need is:
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
The dependency will be retrieved from Maven Central when you build.
Using <systemPath>...</systemPath> is highly discouraged as it usually ties your project to a local environment.
Since jni4net.j dependency is available in maven central, You don't have to download and put the dependency manually. Maven will download and store the dependency locally in `'.m2' folder. Just add dependency as bellow.
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>

how to add jar dependency in maven?

When I run
mvn compile
I get package com.ibm.icu.util does not exist. So I downloaded the ICU4J jar and installed it into the local repository. I confirmed it's in .m2/repository/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar. Inside that jar file is the missing class file com/ibm/icu/util/Calendar.class. Then I added the following into the dependencies section of pom.xml:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>3.4.4</version>
</dependency>
But when I run mvn compile again, I get the same error. What am I doing wrong?
You should avoid adding dependencies manually.
If you don't know a groupId and artifactId of the dependency you need, search for it at http://mvnrepository.com/. Usually, groupId matches the package names in the jar file.
For your case, the dependency is already there: http://mvnrepository.com/search?q=com.ibm.icu
So, go to http://mvnrepository.com/artifact/com.ibm.icu/icu4j and get the version of the dependency you need, e.g. 55.1: http://mvnrepository.com/artifact/com.ibm.icu/icu4j/55.1
Grab maven dependency xml and put it to your pom.xml file:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>55.1</version>
</dependency>
If you didn't find your dependency try to find it in google. Sometimes the dependency may be found in some corporate public repositories, not in a central. In this case you need to add the third-party repository to repositories section of your pom.xml.
If you're unable to find your dependency in the public repository then you have three options:
A. Install jar to internal repository server (e.g. nexus)
B. Put the JAR file in your project sources and declare project maven repository :
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/my-repo</url>
</repository>
</repositories>
Important: You should keep the maven repository layout in your local repository.
C. [Bad Practice] Use maven install plugin to install your custom jar to local repository on your machine. But it's a badIt's not recommended.
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=path-to-your-artifact-jar -DpomFile=path-to-pom
D. [Bad Practice] Use system dependency with absolute path to the JAR file, although it's a bad practice and should be avoided.
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
<scope>system</scope>
<systemPath>${user.home}/jars/my.jar</systemPath>
</dependency>
You should not be manually installing things into the maven repository directory. That directory is maintained by maven itself.
The way dependencies work is that when you run mvn compile or some other goal, it will connect to the maven central repository and download the needed dependencies and their dependencies.
If you manually install a jar file, it may not have it's dependencies. That icu artifact will likely have other things it depends on. Maven will automatically resolve these dependencies.
I would recommend using mvn clean install this will clean the target directory and rebuild everything.
If it fails to download, then you likely need to change the maven configuration. For example, if you are behind a proxy server you need to configure maven with the proxy credentials.
Also, if you manually copied anything into the .m2/repository/ directory you should delete it and let maven put it in there correctly instead.
The beauty of maven is that you don't need to worry about things like downloading jars. It just handles that for you. Let it do it's job.
If you have an internal artifactory like JFrog maybe you should check that the jar is there. Do not download manually to .m2 because it's at least strange. At most you can upload the jar in that artifactory manually.

how to determine dependencies

I'm currently learning java and want to create a project, using maven, hibernate and MySQL. I know that in order to use any of the artifacts with maven, I should find it on mvnrepository and add it to pom.xml. The question is where can I get the list of mandatory dependencies for each artifact I use, f.ex if I need hibernate, I found hibernate-core 4.3.8.Final, proceed to this link and can see it's dependencies in section "depends on". Should I add all of them into pom.xml also?
Well, I think you know about maven.
And yes, You should include all the dependencies with version on your pom.xml files (Which is the main file for all your dependencies ).
First, you need to identify all required dependencies and add on pom file.
While executing code, It primarily tries to get that dependency from local repository (.m2) And if it doesn't exists then it downloads from it's web repository.
Link: maven setup
How it works??
Suppose, You are using log4j for loggin.
You need to know the log4j Maven coordinates,
for example
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
It will download the log4j version 1.2.14 library automatically. If the “version” tag is ignored, it will upgrade the library automatically when there is a newer version.
Declares Maven coordinates into pom.xml file.
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
When Maven is compiling or building, the log4j jar will be downloaded automatically and put it into your Maven local repository.
All manages by Maven.
How to find the Maven coordinates?
Visit this Maven center repository, search the jar you want to download.
Hope, It will help.
Thanks.

How can add the proprietary library in maven project with dependency?

I have a proprietary library. I am using this library in my java desktop project but now, I have a maven project. I want to add this library in my maven project with dependency. How can I do this?
Firstly you should search if this library is available as maven dependency. Try maven search.
For example if you want to include a library commons-io-2.4.jar, you serach for it in the link above, if it is in public repository (it is), then you get maven dependency:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
You should paste this dependency to your pom to dependencies tag.
If above library is not available in public repository, you have to place your jar manually in your local repository by refering to: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Example:
mvn install:install-file -DgroupId=commons-io -DartifactId=commons-io -Dpackaging=jar -Dversion=2.4 -Dfile=home_folder_path/commons-io-2.4.jar -DgeneratePom=true
If it is not already on maven repository, simply add it to your pom.xml, and add it to your local repository.
<dependencies>
<dependency>
<groupId>com.proppath</groupId>
<artifactId>mylib.jar</artifactId>
<version>myjarversion</version>
</dependency>
And also put this prop library into
.m2\repository\com\proppath\myjarversion
Give any groupId you like but make sure that you have corresponding path on repository to find it.
Normally, in large projets these kind of propriatery libraries are stored in Nexus of your enterprise.

Categories

Resources