Why do I get an error? When I run Maven compile I get errors package org.hibernate does not exist, but I add Hibernate to lib. errors
Defining in your project a lib directory and adding it in the classpath within your editor is not really how Maven works. Take a look at the Dependency Mechanism in Maven. In short you have to define the dependency coordinates in the Maven POM file and Maven will take care of the rest.
Related
I'm trying to resolve a maven dependency in my eclipse project.
The dependency has already been downloaded into my maven dependencies folder (as can be seen below)
However, the import statement still isn't resolving.
In my java build path, the Maven Dependencies folder is present.
So far, I've tried rebuilding the project on the command line and refreshing it in eclipse; I've tried rebuilding it in in eclipse itself; and I've tried updating the project in eclipse.
Nothing seems to work. Any help would be appreciated.
EDIT: Here's my POM file for those of you who asked.
Your dependency is set as under the test scope. This means that it's only available in test classes (e.g. src/test/java). If you want to use it in your main app src/main/java remove the test scope.
I don't use eclipse but the general idea is to delete all dependencies in your dependency folder and rebuild or you can also change the version of the dependency that is throwing the error. Sometimes, the name of the class you are calling may be changed in the version you are using.
With a right-mouse click on the project node in the Package Explorer and selecting menu Maven -> Update Project..., you can update the Maven dependencies.
You also have to keep in mind, that Maven has often dependencies in a "test" scope in the pom.xml. In that case you can use these dependencies only under the src/test/java path.
I have a Maven project, imported from Eclipse, where the dependencies are set to scope provided. When the project is deployed, the jars are deployed as well so that works fine.
While developing, however, I use a "debugging project" that calls the Maven project, and when it runs I get a bunch of Class Not Found errors when the Maven dependencies are set to provided.
If I change the scope of the Maven dependencies to Compile then the project works fine.
If I change the scope of the dependencies to compile, would that change the output of the project? i.e. add a bunch of jars? That would be undesirable.
I also tried to change the Debug Configuration settings and specified the Maven project in "Use classpath of module", but then the files of the debugging project are not found.
How can I specify the classpath to be of both the Maven project and the debugging project, so that classes from both projects including the dependencies will be on the classpath?
Thanks!
There are 3 types of dependency scope: compile, test, and provided,
compile: the dependency library will be used in all steps: compile , test and run,
test: the dependency library will only be used in the test
provided: the dependency library will only be used in compile and test, but in the run time, the dependency library must be provided by the container otherwise it will throw class no find issues.
Your issues is that you did not provide the dependency library in the run environment ( container) when running your project.
hope this can help you
How did you import the project to Idea? If the project is opened as a Maven projects, it should work out of box.
Can you try to open the project by selecting pom.xml?
I am converting my simple working web application (runs from eclipse) to a maven project. This is my first maven project. I have 3 external jar dependencies to it and i added then to the pom.xml my build is failing saying that it can't find those 3 dependencies. here my pom.xml file
The build is saying that the 3 packages does not exist.
package javax.servlet does not exist
package org.apache.commons.codec.binary does not exist
package org.apache.commons.configuration does not exist
What i am missing? I am running my application from Mac and in the .m2/repository i see these 3 libraries/packages present.
You need to either remove the dependencyManagement tags that surround dependencies or add the dependencies again but nested within the project tag, i.e. at the same level as dependencyManagement.
dependencyManagement allows you to fix information about dependencies across a multi-module project - e.g. like version numbers - however you still need to provide a dependencies section alongside that so that Maven knows to include them.
If your project is not a multi-module project I would be tempted to not use a dependencyManagement section at all.
Just remove dependecyManagement tags
I have maven java project that is compiled fine in command line, but when I import in eclipse I receive compilation errors about CollectionUtils.
org.apache.commons.collections.CollectionUtils
Seems that project has transitive dependencies that has reference to old versions of apache commons collections.
How to track exactly error?
How to fix?
Thanks.
Perhaps you could track down the transitive dependencies by issuing mvn dependency:tree to figure out which dependency in your pom is pulling in the older version of Apache commons.
Alternatively, inside eclipse when you open the pom.xml file (with the m2e plugin installed) you should see the Dependency Tree tab at the bottom of the Editor like so :
In the Search field you could type the name of the apache commons jar to find out which dependency is pulling it in. Once you have that add the appropriate exclusion add it should all be peachy.
Question
How did you import the maven project inside eclipse. Did you do a mvn eclipse:eclipse and then import it as a normal eclipse project ? If so, I would recommend installing the m2e plugin (linked above) and then importing the maven project using Import Existing Maven Project from within eclipse.
Looks to me like the classpath (.classpath file) in Eclipse is not correctly configured. You can have maven configure this for you by using the Maven Eclipse Plugin. Simply execute the following from the command line:
mvn eclipse:eclipse
Maven will then correctly fill the .classpath file with all dependencies (including transitive dependencies) defined in your POM. Then refresh the project in Eclipse and all of the red crosses should disappear (hopefully...)
How to track exactly error? How to fix?
invoke
mvn clean compile -e
it will give you error stacktrace that would help you to fix this error
I've been trying to add a custom .jar (ftp://ftp.ncbi.nlm.nih.gov/pub/eutils/soap/v2.0/java/axis2_1.5.2_jdk_6.0.12/eutils_axis2.jar) to a project that doesn't have a central corporate maven repository and that instead will have the custom JARs checked into SCM in the project directory tree. I was following this post to make it happen: Maven: add a dependency to a jar by relative path (awesome post btw).
What I did was:
Add local repository to pom.xml
install the file into the local repository
Add dependency to pom.xml
Based on what I see in m2eclipse, the library has been successfully recognized by Maven and added to the dependency list (or it'd be called ? : ? or something similar)
The problem is that Eclipse still doesn't see the referenced lib, so this still fails:
import gov.nih.nlm.ncbi.www.soap.eutils.*;
Pardon my maven newbiness, but what are changes / next steps I need to make to get to:
Have Eclipse see the library so that autocomplete works (and the import can be resolved)
Be able to compile the project
Be able to execute the jar produced by mvn package?
Thanks!
If you see the JAR under "Maven Dependencies" in your project, Eclipse should be able to see and use it. If it's not there, then m2eclipse wasn't able to resolve the dependency properly.
If it is missing, m2eclipse was unable to download the dependency from your local repository for some reason. Check the Maven 2 Console for errors and the Problem View.
Lastly, the JAR itself might be corrupt. Maven doesn't check for that, it simply adds the file to the classpath. If Eclipse can't open the JAR, you can also get the errors you mentioned.