I am trying to revive my old project. I want to use maven for it and I want to add AbsoluteLayout dependency. I am kinda new in maven so I have no idea what is wrong. I have found that this should work:
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE802</version>
</dependency>
but I only get this error:
Failed to execute goal on project XXX: Could not resolve dependencies for project xx.xxxx:XXX:jar:1.0-SNAPSHOT: Failure to find org.netbeans.external:AbsoluteLayout:jar:RELEASE802 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
After this I manually added this dependency from my netbeans folder in my computer. And it is working. Is there another way how to add this dependency? I would like to include it in my pom file. Any ideas?
You need to add a Netbeans repository to your POM:
<repositories>
<repository>
<id>netbeans</id>
<name>Netbeans rep</name>
<url>http://bits.netbeans.org/maven2/</url>
</repository>
</repositories>
I added the below dependency block to my POM and after updating my maven indices it worked just fine.
<!-- https://mvnrepository.com/artifact/org.netbeans.external/AbsoluteLayout -->
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE802</version>
</dependency>
So you might want to try updating your maven indices and see if that does it for you. This dependency block came directly from mvnrepository.com/, and worked without me needing to add any special repo as far as I'm aware.
Look like that dependency is not exists in the public repository, you can register an account and upload it, or, from my view point is better, you can setup your own private maven repository server, there many software support to do this, for example JFrog Artifactory, it is easy to install and manipulate.
Related
I have a problem when building a default project created by NetBeans when Maven-Java Web application is created. When I add Spring MVC dependency under Properties->Framework category and build a project I get this error:
Failure to find org.springframework:spring-framework-bom:jar:4.0.1.RELEASE in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
You have a placeholder in your local repo, try to delete this placeholder
delete the folder
~/.m2/repository/org/springframework/spring-framework-bom/4.0.1.RELEASE
Then rebuild with
mvn clean install -U
This assume your maven instillation is correct.
Did you add this dependency?
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.1.RELEASE</version>
<type>pom</type>
</dependency>
and throws you that error? Could be a missed library.
Before adding it manually (or any other solution), make sure u really need the spring bom in your dependencies...
The bom should go under dependencyManagement section in your parent pom xml.
BTW the bom is only available as "POM" , not as "jar" scope.
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>
I am working on a Java project, using maven as our dependency manager/build tool. I am currently having a problem resolving a dependency's dependency to the correct version.
The dependency in question is called jasperreports-functions-6.1.0.jar which is not hosted in a maven repo but provided in jar form.
The problem I'm having is that jasperreports-functions needs commons-lang 2.6. Inconveniently, during "compile" Maven itself builds commons-lang 2.1 to create the reduced-pom. It seems this leads to jasperreports-functions trying to use commons-lang 2.1 because it is available, but this is not valid (method undefined errors at runtime.)
I have tried adding commons-lang 2.6 as a dependency but still it seems jasperreports-functions is using the 2.1 version.
pom.xml snip:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.0</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-functions</artifactId>
<version>6.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/jasperreports-functions-6.1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
Using "mvn dependency:tree" I can see that no dependency requires commons-lang.
If I delete 2.1 from ".m2\repository\commons-lang\commons-lang" it gets recreated by maven. If I empty the folder and lock the permissions on it, then run maven again I get the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project JavaLibrary: Execution default-jar of goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar failed: Plugin org.apache.maven.plugins:maven-jar-plugin:2.4 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-jar-plugin:jar:2.4 -> commons-lang:commons-lang:jar:2.1: Failed to read artifact descriptor for commons-lang:commons-lang:jar:2.1: Could not transfer artifact commons-lang:commons-lang:pom:2.1 from/to central (https://repo.maven.apache.org/maven2): C:\Users\Lowell\.m2\repository\commons-lang\commons-lang\2.1\commons-lang-2.1.pom.part.lock (Access is denied) -> [Help 1]
How can I force the jar dependency to use a certain version of a sub-dependency?
Have you tried to reorder the depency entries,
first to load commons-lang then to load jasperreports ?
Edit:
Maybe this should help you: dependency:analyze-dep-mgt
What you are doing should be enough. The newer version should override the older version AND the version you specify explicitly should override any transient dependency. I believe Maven 2.x had problems in this area which is why I updated to Maven 3.x
I suspect the problem is somewhere else. I suggest trying to delete common-lang 2.1 and I suspect this should show you what the real problem is.
Try this:
1> Maven clean.
2> Right click on project->maven -> update project configuration - > force update
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.
I am new to Maven and I am currently using the m2e plugin for Eclipse.
Question 1:
When searching for an artifact (atmosphere-runtime) in the default central repository (right click project: Maven -> add dependancy), a list of results is returned.
However upon adding the dependency I receive the following error message:
Missing artifact org.atmosphere:atmosphere-runtime:bundle:1.0.2
If I search for the artifact on the maven web site I am able to find and download the jar manually (see here). I have tried cleaning/updating/reloading the project, updating/reindexing/rebuiling the central maven repo and restarting Eclipse, but nothing seems to help.
Is there a reason why I am getting this error?
Question 2:
A tutorial I am following suggested adding the following repositories to the pom to download the above artifact:
<repositories>
<repository>
<id>Sonatype snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>Sonatype releases</id>
<url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>
</repositories>
This works and I am able to download the required artifacts if I manually specify the dependencies in the pom.xml file.
However, if I try and search for the artifacts using the eclipse search (right click project: Maven -> add dependancy), no results are returned from the two new repositories.
Is it possible to include these two new repositories in the search?
For your 1st question. Maven central has only a "jar" but you seemed to be requiring a bundle instead. So you have to change your dependency to "jar" which means to define the dependency like this:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>1.0.2</version>
</dependency>
instead of:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>1.0.2</version>
<type>bundle</type>
</dependency>
The best thing to solve the problem in your 2nd Question is to use a repository manager like Nexus and define those two repositories in the repository manager.
The https://oss.sonatype.org/content/repositories/snapshots defines the SNAPSHOT's of artifacts which are in Maven Central whereas the second one is the repository which is regularly synchronized into Maven Central. So in my opinion you don't need those two repository separately. If you want to search the content of the two above repositories you can use the search of that: https://oss.sonatype.org/ where you have the access to a Nexus repository which can be used for searching as well.
To your 2. question. Expand Project Repositories in Maven Repositories view and right click on added repositories and check Enable Full Index.
To your 1. question. Enable full index for central repository if not enabled, and try to Update Index/Rebuild Index.