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
Related
I have a maven project in Eclipse and I added some local jar files to the buildpath. If I do not add any dependency to the pom.xml file I am able to execute maven install. Then, if I add those dependencies to the pom the command maven install continues working as well. Now in this situation if I run maven clean then maven install fails. Why?
I also tried to run Maven -> Update Project but the result is the same. What is the problem?
If you are using non maven dependencies then it will fail to build eg from CLI and in your case in Elipse after cleaning the project as well. In order to make it work you have to installl tha JAR you are using as Maven artifact and the ninclude it in POM dependencies like every other library.
Here you have info on how to install 3rd party JARs to local repo
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
I got the same problem and resolved by adding the 3rd party in the pom.xml manually
my_project has upstream_project as a dependency in its pom.xml, but I have no idea why this is necessary. How can I find out which class in my_project is importing from upstream_project, using either Maven command-line or IntelliJ?
I'm using Maven 3.3.3 and IntelliJ 14.1.
Quick and dirty trick:
Remove the dependency from your pom file.
Run mvn clean install -U and see what breaks.
Comment-out your upstream_project dependency, and try running maven compile on command-line. If your project is missing classes from upstream_project you will get compilation errors for missing symbolic names.
This feels like a really stupid question but I haven't been able to find an answer.
I'm working on a maven project but I do most of my development in eclipse. Is there any way for me to force maven to generate all of my dependencies under target even if there are errors in the code? I set my eclipse project's build path to use the jars under target/dependencies/jars, but calling mvn clean kills them and if there are any errors in my code causing it to not compile mvn package won't create the dependencies but will instead just crash saying BUILD FAILURE. This makes the problem even worse since instead of seeing the actual errors my eclipse will just bombard me with errors everywhere since all of its dependencies just died.
Or maybe the way I'm working with it is just stupid and there's a better way.
Are you using the m2e plugins for Eclipse to process maven projects, or simply importing the projects as general ones?
If the latter, you should use the m2 plugins (simply go to the Eclipse Marketplace and search for Maven), as they interrogate your POM and set up your dependences properly. You can then concentrate on any compile errors in your code.
You should not point to the jars in the target folder for dependent JAR's since this is where the products of building your project are stored. Performing a mvn clean removes this folder.
To use Maven with Eclipse install the m2e plugin in Eclipse. This makes Eclipse understand the structure of Maven projects.
Once installed you can import your Maven project into Eclipse. I use Import... | Existing Maven Projects for this. But you can also directly import form a versioning system.
During the import Eclipse will set up the Eclipse project to use the Maven dependencies to locate the required JAR's. These are taken from the repository as configured with the used Maven installation.
Trying to compile Maven with clean parameter:
C:> mvn clean
and got the exception below:
Cannot execute mojo: clean. it requires a project with an existing pom.xml, but the buid is not using one.
can anyone tell me how I can associate my existing project to maven.
Maven uses a file called pom.xml to build. It should be located in the root of your project.
Maven works on the basis that your project conforms to the Maven way of doing things and so I would recommend reading the Maven Getting Started Guide to familiarize with the standards before starting to use Maven.
I think you need to read up on a bit of documentation. Basically it is the pom.xml file it is complaining about that defines how maven should handle your project.
This explains how you can use maven to generate an example project.
This goes in more depth and also provides some links to other resources.
suppose your project is in 'C:\MyProject' where you can see a pom.xml file, open command prompt, go to C:\MyProject and type 'mvn clean' as follows:
> cd C:\MyProject
> mvn clean
The project you are compiling is not a maven project.
We recently started using maven for dependency management. Our team uses eclipse as it's IDE. Is there an easy way to get eclipse to refresh the maven dependencies without running mvn eclipse:eclipse?
The dependencies are up to date in the local maven repository, but eclipse doesn't pick up the changes until we use the eclipse:eclipse command. This regenerates a lot of eclipse configuration files.
Have you tried using the m2eclipse plugin? I use it with eclipse and it maintains the eclipse .classpath when I add dependencies. It'll also check for updated dependencies.
You generate the special eclipse files with mvn eclipse:eclipse, but once you've done that, you should let a plugin handle the dependencies while inside eclipse.
That's how we do it at my work place, and it generally works well.