Maven uses dependencies from workspace not .m2 folder - java

So I have the following project structure Sporium is a working set with the maven multimodule spigot-parent my problem now is when I define this pom.xml in my project it will not use the created dependency in the .m2 folder but instead it will use the files in the maven module project of my IDE's workspace which doesn't work because they are raw, unpatched and uncompiled files
as seen here. Any idea how I can tell maven to not use the version in my workspace and only search in the local repo .m2 folder?

Right click on the project, choose "Maven" and then disable Workspace resolution.
Then the projects are not resolved from your workspace any more.

Related

Add multiple dependencies of Maven project into a non-Maven project in Java

I am trying to add the Maven dependencies of a Maven project into a non-Maven project. However, there are too many and adding them one by one would be too tedious. Could someone suggest a shortcut to add them all at once?
What do you mean by adding dependencies to a non-maven project?
If you want to make it a maven project, right-click the project and in configure click convert to maven project. Otherwise, you can copy-past the jars into your build path. If you have the other maven project in your computer, you can locate the jars in .m2 folder in your user directory and add them to the project or download them one by one.
Run the following maven command in the main directory of your maven project:
mvn dependency:copy-dependencies
Then you will be able to find all of the downloaded jar files of your dependencies here:
{PROJECT-MAIN-DIRECTORY}/target/dependency/
You can add the -DoutputDirectory parameter to have the jar files placed somewhere else.
Afterwards you may simply add the jars to the build path of your non-maven project.

How to build pom.xml in a maven project which is downloaded from github?

I am so so new in maven that's way I need help for this problem. Firstly I downloaded this folder from the github. I want to use these libs in that folder. I created a clear new maven project on eclipce but that's all. There is a pom.xml inside it too. I do not know what I have to do with these both folder and new maven project. How can I use these libs on my project ?
If you have a Maven project downloaded and unpacked on your file system, and you have a Eclipse with maven support, you should not create a new maven project but instead open the import dialogue from
File -> Import...
and choose
Maven -> Existing Maven projects
and click next. Then click "Browse" and navigate to the folder where pom.xml file for the project you checked out is. After clicking Ok, the projects will be imported and made available in Eclipse.

Eclipse, Tomcat & Maven workspace resolution: wrong folder structure?

I am trying to build a spring-mvc project that has another project (core, as .jar) as dependency.
If I disable "Resolve dependencies from workspace projects" in eclipse, install the core into my maven repo and run it from eclipse, the application works!
What I want to do, is re enable "Resolve dependencies from workspace projects", but there is the problem: When I try to run the project on tomcat (after maven clean, project clean), I get a "FileNotFoundException". The file in question is under src/main/resources/META-INF/spring/applicationContext-core.xml
It seems, the File can not be found in the classpath.
I looked up the deployment location and found out, that everything of the core is under the following folders:
WEB-INF
classes
So the file I am missing can be found here:
/WEB-INF/classes/META-INF/spring/applicationContext-core.xml
But it schould be here:
/META-INF/spring/applicationContext-core.xml
Why is the structure of my core dependency so messed up when I enable the workspace resolution and how can I fix this?
I am using eclipse mars with m2e..
Thanks for any help.
Edit:
Project structure (core) looks like this:
project structure

How do I rebuild/make .iml files in maven multi-module project in Intellij 13.1.4

I'm working in a multi-module maven project in Intellij. There was a snapshot update in another module which required an update in a few POMs. Normally I will click the "Re-import all maven projects" from the maven plugins tool then do a full build.
However, this time the .iml files associated with the changed POMs weren't being updated. It wasn't until I did "Build->Rebuild Project" that the .iml files were updated. Does anyone know how to update .iml files as part of a build configuration?
Note: Before rebuilding the project, I know mvn at least picked up on the change because my local .m2 repo had the latest snapshot.
EDIT #1: So, this is also true if I add a maven runtime dependency in a module. It won't pick up the change unless I do rebuild project.
I've experienced similar issues with newer versions of IntelliJ (2018.2.7) where my .iml is out of date. It happens inconsistently, so I'm not sure what the root cause is, but the following work around allows me to avoid doing a full rebuild:
Delete the .iml file and .idea folder for the project
Reimport the pom.xml for the project
IntelliJ will automagically regenerate an updated .iml file.
Had the same issue and in addition to deleting the .iml file as in the previous answer, delete the .idea folder as well and restart the IDE or import the project by pom file.
new .iml file is created with all maven dependencies

m2e maven eclipse plugin not configure the build path

I import a project to my workspace and convert it to Maven project using m2e and ran the pom file with goal specify "clean install".
But my project build path is not populating with the jars already downloaded to my local repository which still gives compilation errors in the source.
When i expand "Maven Dependency" variable in the library tab of build path, i can not see the jars already downloaded?
Was there existing Eclipse metadata when you imported the project, perhaps from another developer? This is a frequent cause of failure in Eclipse, especially if you have metadata from the earlier m2eclipse plugin.
I have encountered the situation many times (in Juno and Kepler) where the .classpath is incorrect, resulting in the symptom you describe, and I either have to rewrite the .classpath myself or nuke it and encourage Eclipse to try again.
In your case:
delete the project from your Eclipse workspace (but not the filesystem)
delete the subdirectories .settings and target, and the files .classpath and .project from the project directory
re-import the project into Eclipse via File -> Import... -> Existing Maven Project
The Eclipse dot-directories will be created from scratch, and the project should already be configured as a Maven project; artifact retrieval should start in the background.
If this fails, check the 'Maven Console' in Eclipse for clues, and/or the Eclipse Error Log.
As other people have commented, you need to ensure that your m2 settings file is being correctly interpreted by m2e.
Can you build successfully from the command line?

Categories

Resources