i have a project which is using several components to perform the functionality.All the components are managed by maven dependency control.now i want to change the code of one of the component just to enhance the functionality.That component is visible to me in eclipse project explorer i can access the files present in that component.But when i change the code in component,that change is not accessible to main project which is using that component as dependency.i have tried maven:clean , update dependencies but nothing works.i am just new to maven so i am sure i am missing something.
any help is really appreciated.Thanks
When using maven with eclipse, dependencies can be used either directly as jar (as they were downloaded from the repositories) or, if the dependency is also defined in a project open in the same workspace, eclipse should use this project instead of the original jar.
You should check :
that "disable workspace resolution" is not checked (when your right-click on your project in the project explorer, in the "maven" sub-menu).
that in your project properties, in the "Java Build Path"( "Librairies" tab ) eclipse displays your dependency as a project and not as a jar from the local maven repository.
Also be careful to rename the component (and to publish it somewhere or to include the modified code in your project) to make sure that another developer building the project use the same modified dependecy and not the original one.
After you updated pom file with dependency, have you tried maven install ?
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'm using eclipse with the m2eclipse plugin now I just want to resolve a - imho - easy problem: I've got two maven projects, I want to add project A as dependency to project B.
Well how do I achieve this in a manner way? If I add the project A to the build path of project B eclipse recognizes the classes but this project isn't resolved by eclipse on build time.
I got it working by installing project A to my local repo and adding this as dependency to my pom. This works but is cumbersome because I always have to install a new version of project A when something changed.
Shouldn't the plugin handle such a situation for me?
Providing that you have both maven projects open in your workbench then make sure you have the "Enable Workspace Resolution" option enabled in the Maven context menu.
Yes Eclipse handle this situations.
You can add both the Projects A and B in the same work-space.
I could help you creating a simple work-space from the scratch.
I am assuming that you have already installed the MAVEN plugin M2Eclipse for Eclipse.
Start a new Eclipse in a blank Work-space
Right click on Project Explorer --> Go to Import dialog and add a Maven Module.
Locate the POM directory and add that directory.
It will list all the projects in all the sub folders.
Add as many as Maven Based modules in a single work-space.
By doing this you dont need to install the dependencies. Any change will be reflected on the derived module.
Hope that will help you.
The way you did it is correct, because it assumes that project B will be using the dependency of project A that will be in the artifactory, so you can develop both independently.
And anyway, for the project A, if you are using maven, don't you use maven clean install for compiling and deploying? That way you are sure you always have the latest version
The other option is, in case both of the are more dependent of each other, you should consider make one of them as a module of the other, or maybe make a project C that contains both modules, but that would mean both of them are part of the same project (like an ear containing two jars), depends on the situation
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.
So every time I add a dependency to a library using maven in my pom.xml, it doesn't get deployed until I go to module settings and then click on 'fix'.
This happened when I added freemarker.
Why doesn't IDEA do this for me? Am I missing a step?
Not sure about previous versions but with IntelliJ 9, IntelliJ shows me a Import Changes link when I modify a pom.xml and also offers to Enable Auto-Import:
alt text http://www.imagebanana.com/img/emcut3ku/screenshot_008.png
The auto-import option is also available from the Maven Integration dialog: File > Settings > Maven > Importing > Import Maven projects automatically.
IDEA stores all of your module's dependencies in either a .iml or .classpath file (based on your preference).
When you change the pom.xml file, it needs to resolve the new set of dependencies (Re-import) and update the file accordingly. I can only imagine that they don't do this automatically for you because they can never really know when you are done working with the file, and causing resolution of dependencies to start while you're still typing would make working with pom.xml from within idea very irritating.
AFAIK, you're doing it right. In my version of IDEA, I see a "re-import" button that appears in the pom file editor (which saves a couple of clicks)... or you can go to the "Maven Projects" window and click the "Re-Import Maven Projects" button, but these should do the same thing as your "Fix" button in the project settings.
The original question referred to a library that wasn't deployed -
IntelliJ uses artifacts to deploy build output and required libraries to application/web servers, and currently those can include a constant list of dependencies. Clicking the "fix" simply adds module dependencies to the artifact, if they weren't already there.
Since in most use-cases this is 1:1, i.e. artifacts contain all module dependencies, I have opened an feature issue for it:
http://youtrack.jetbrains.com/issue/IDEA-99458
Right now, I have two Eclipse projects - they both use Maven 2 for all their jar-dependency goodness.
Inside Eclipse, I have project Foo included in project Bar's build path, so that I can use Foo's classes from project Bar. This works really well in Eclipse land, but when I try:
mvn compile
inside Bar's directory, it fails because Maven doesn't know about the project-to-project relationship in Eclipse's build path.
If I were using Ant, I would just use it to do something silly like copy foo.jar into project Bar's classpath, but as far as I can tell, things are done a lot less hackishly in Maven-land.
I'm wondering if there's a standard workaround for this type of problem - it seems like it would be fairly common, and I'm just missing something basic about how Maven works.
Maybe you are referencing the other project via Eclipse configure-> build path only. This works as long as you use Eclipse to build your project.
Try running first mvn install in project Bar (in order to put Bar in your Maven repository), and then add the dependency to Foo's pom.xml.
That should work!.
Check out the m2eclipse plugin. It will automatically and dynamically update the project build path when you change the pom. There is no need for running mvn eclipse:eclipse.
The plugin will also detect if any dependency is in the same workspace and add that project to the build path.
Ideally, if you use m2eclipse, you would never change the project build path manually. You would always edit pom.xml instead, which is the proper way to do it.
As has been previously stated, Maven will not know about the Eclipse project build path. You do need to add all dependencies to the pom, and you need to make sure all dependencies are built and installed first by running mvn install.
If you want to build both projects with a single command then you might find project aggregation interesting.
I just needed to do this and I needed it to build with the external mvn clean install command. Here is the proper way to configure this in Eclipse. (With project B as a dependency of A)
Open the pom.xml for project A in Eclipse.
Go to the Dependencies tab.
Click the Add... button in the middle of the page (for the left side Dependencies box)
In the popup, there should be a box under a line with text above it saying Enter groupId, artifactId or sha1 prefix or pattern (*):. Enter the artifact ID for project B into this box.
Double click the jar you want to add as a dependency to this project
You may need to update the project after.
Right click project A in you Package explorer
Maven -> Update Project...
Then hit OK in the popup.
You might want to try an alternative approach, where you have a parent maven project and two children project. let's say:
Parent (pom.xml has references to both children projects/modules)
--> A (depends on B)
--> B
then when you run mvn eclipse:eclipse from the root of Parent, maven will generate eclipse projects for A and B, and it will have B as a required project in the classpath of A.
You can run mvn install from the root of Parent to get both projects to compile.
To complete your setup, you'll have to import both A and B into Eclipse, making sure you don't check "Copy projects into workspace".
I think the best way to handle it is to make Bar a Maven project just like Foo, and then mvn install it so it is available in your local Maven repository. The drawback is that you have to install that project every time you want Maven to see the changes you make to Bar.
Not a complete answer:
Bar's pom needs to include Foo in order to use maven to compile it.
I'm interested in this question too, but from the perspective of how to get eclipse to recognise a maven-added dependency is actually another project in the same workspace. I currently alter the build path after performing mvn eclipse:eclipse
If you reference a local project, but its version has been updated (usually increased), it could maybe only be found in your local repo and you have to update the (likely fixed) version of it in your POM(s).
We have a "common project" (used everywhere) which does not necessarily need to be versioned since we tag it via source control. so either
keeping it at a fixed version or
referencing it with the special LATEST version
are good workarounds to always be on the safe side.