I am facing an issue with maven.
I created a project A, build it and did maven install. I see the jar file copied in local repo.
I included the project A's POM dependency in Project B. Project B is now able to reference the project A. The concern here is in eclipse when I expand Maven dependencies in Project explorer it shows me reference to project A instead of jar.
Now when I close project A in workspace of eclipse, the project B could not reference the project A.
Could you please help me understanding and fixing this issue.
Regards,
Amandeep
The M2E plugin in Eclipse is able to see whether a workspace project already satisfies a dependency in another project. You observed it already. If the project is not in the workspace, the dependency will be served by the local and/or the remote repository.
If you close a dependency project, you first have to make a Maven Update. Simply rightclick your project, select "Maven", then "Update". This will recalculate the project settings and its dependencies.
Related
I have some projects with many json files that when compiling them with maven generate many java bean classes and I have a main project that has the maven dependency of these other projects. Well, if the other projects are closed, when updating the maven dependencies it gets the compiled projects in my .m2 folder and the main project does not show errors in STS, but, instead, the projects are open, STS changes that dependency from the .m2 folder to the open project, and it does not find the java classes in the source folder because they are in the target.
How can I tell STS not to use the projects that are named the same as the maven dependencies? This way I compile the projects independently from the console and update the dependencies to the main project when necessary.
Right-click on the project, select "Maven" and then "Disable Workspace Resolution". I do this for every project. I wish there was a way to set this as a global preference. I wrote a shell script that whacks on all the .settings files in my project to set this flag for all my existing projects.
I have a Java project in eclipse:
Project A contains an Ivy dependency on Project B.
Locally, I checked out and made changes to Project B. I then wanted to test the new functionality from Project B in Project A, so I added Project B as a project dependency of Project A by adding it to the Java Build Path (Java Build Path->Projects->Add...).
I no longer wish to have that dependency on Project A, but simply removing it from the Projects Build Path hasn't worked. With that dependency removed, I would expect that any references to the new local code would result in a syntax error, since those changes have not been incorporated into a new artifact for Ivy to pull in.
How can I remove any references to Project B from Project A? I've tried deleting both projects and re-checking them out and that did not work.
The way to resolve this issue is to:
Close Project B in eclipse.
On Project A run Project-Clean
Resolve Ivy dependencies on Project A
Now the dependencies from Project B should use the Ivy artifact rather than the local changes.
I have two Maven Java projects in Eclipse. I added Project B is a dependency in Project A's pom.xml file. Each time a code change is made to Project B, I have to do 'run maven install' on B, and then do a 'maven update project' on A, in order for the changes to appear in A. Is there a better/faster yet proper way to manage this?
I have tried to remove the maven dependency in A's pom.xml and use Eclipse's the project dependency, that result in class not found error when I try to run A.
You can add "Refresh Resources" -> Entire Workspace after completion in your Maven Run Configuration
I'm using NetBeans 7.4 RC1 to create Maven projects.
Let's say I create two Maven projects, named A and B, and a third named X which includes the other two projects as dependencies.
On building X Maven searches the local Maven repository (and the connected company-proxy) for the dependencies and obviously does not find any initially.
If I run the build command of NetBeans on projects A and B, it performs a maven install, which then installs the projects into my local repository. Now, when I build X it will find the dependency and all is well.
Is there a way to configure Maven (or NetBeans) to automatically build the dependencies (and install it to my local repository)? I know there's a solution to do this with POM Projects (Reactor POM) where the modules (in this case A, B and X I suppose) can be added to it, and the POM project specified as a parent in all the modules - this will allow me to select the "Build with Dependencies" option, which will then build all the modules in the POM project. But this is not a good solution if say project A is a utility project, used in many other projects.
Essentially what I'd like to avoid is building all the dependencies for a project every time I want to test my project; especially when I'm working on the project and its dependencies at the same time.
The key is to try and to this in NetBeans itself, and without modules, if it's possible.
I hope I'm missing the point.
With Compile on Save turned on, Netbeans will attempt to link the opened projects together no matter what reactor they belong to. However this will not build the projects (eg. doesn't create an updated jar file in local repository), just link the current project's maven build to the target/classes of these projects.
i just started with java, and created a project.
its maven project (i hadn't use maven yet)
so my project have two modules A and B.
and B depends on A, and A depends on some from remote maven repo. and B also depends on some remote repo.
its works fine in Idea IntelliJ and build jars fine.
but afaik .iml files are Idea IntelliJ specific. and pom.xml is maven specific.
and when i inspect files why all depedecy of project is written in .iml files and .idea dir instead of pom.xml(s)
if you want to see the real world source then here it is but its alpha project for learning java deeply.
and when i try to build project on travis-ci.org it unable to resolve dependencies of project
Meghraj,
I have forked your WebTrimmer repo here : https://github.com/ajorpheus/WebTrimmer and fixed a couple of issues which were preventing a successful build:
The travisci fails because you have three jars in the lib folder which are not available to the CI since it's doing a maven build. The fix was to remove those three jars and introduce corresponding maven dependencies as in this commit.
While adding the maven dependencies an exclusion was needed as noted here : The following artifacts could not be resolved: javax.jms:jms:jar:1.1
The WebTrimmerUI depends on the classes in it's sibling module WebTrimmerEngine, therefore a corresponding dependency is needed.
I have converted the project into a pure maven project which is IDE-agnostic. With the above changes, I can build the project from command line and expect that the travisci should be able to as well.
Regarding the question about why the dependencies are duplicated in .iml --- That's not the reason the CI job fails. The dependencies in that file are a snapshot of the dependencies in the pom.xml. This snapshot is updated when the maven project is re-imported manually by the user, or automatically if the maven project is set to 'Auto-Import'.
As Peter Lawrey mentioned in his comment above, if you add a jar to the project, maven does not know about it and it will be present only in the .iml file.
In general, to search and add a maven dependency, the following has always worked for me: https://stackoverflow.com/a/10178586/325742
Hope this helps !
You need to add dependencies to the pom yourself. The .iml files are for storing project specific settings for whatever project you are currently working on.
Having the pom files allows your maven builds to be IDE independent where as the .iml files require you to have IntelliJ.
You can exclude the .iml files from and version control you are using. You can also open an existing maven project directly via IntelliJ by opening its pom.xml and IntelliJ can auto import everything specified in the pom file and will generate new .iml files.