I want to reference a jar (ie vim25.jar, VMWare VSphere server management) in the POM of my project. As this file is not referenced in MavenRepository I do the following steps:
Download the file from VMWare site
Install the file using:
mvn install:install-file -Dfile=./vim25.jar -DgroupId=manuallyInstalledJars -DartifactId=vim25 -Dversion=2.5 -Dpackaging=jar
Everyting works well and I can find the jar in myLocalRepo/manuallyInstalledJars/vim25/2.5/vim25-2.5.jar
Beside the jar there is the POM, I open it and extract the dependency references:
[groupId]manuallyInstalledJars[/groupId]
[artifactId]vim25[/artifactId]
[version]2.5[/version]
("<" replaced by "[" because of the editor)
I enclose this with the [dependency] tag and put everything in the POM that uses the jar
In Eclipse I get an error (red mark in the text editor) with this comment:
"Missing artifact manuallyInstalledJars:vim25:jar:2.5"
Any idea ?
Perhaps just post the dependency xml so we can rule that out.
In any case try this in Eclipse (assuming you have m2eclipse plugin installed)
Window-> Show View -> Maven Repositories
Expand Local Repositories
Right click Local Repository -> Rebuild Index.
This sometimes help refresh the maven repo in Eclipse when youve made external changes
After the rebuild, check you can see the JAR in that local repository tree in the maven repositories view. You can also confirm that Eclipse is looking at the same local repository as your external maven installation.
If it's not, check the user settings in the eclipse preferences.
Window -> Preferences -> Maven -> User Settings
You can check it is referencing the correct maven settings xml file
Related
Is there a way to have it so that when I add a new dependency in my pom.xml file the corresponding library will be automatically downloaded. I am using IntelliJ if that is relevant.
Maven doesn't download all dependencies when added in pom.xml. At first it will looked up in your local repository. If that artifact with desired version doesn't exist locally Maven tries to download from preconfigured remote repositories.
In IntelliJ when you add a new dependency to your pom.xml a dialog box or modal will shows up with two options: Import changes and Enable Auto-Import. If you choose Enable Auto-Import then newly added dependencies will be resolved automatically.
If you want to enable this feature globally then go to: File > Settings > Build, Execution, Deployment > Build Tools > Maven > Importing and chek the Import Maven Projects automatically option. Additionally you can select which other artifact types will be downloaded. In this window there is a section Automatically download. Just enable those other types if you want.
I am new to maven.
The POM file in maven contains all the dependencies that we need in our project.
So we don't have to externally add any JAR's to the buildpath in eclipse.Right?
That's right. Maven will download dependencies and M2Eclipse (Eclipse plugin for integrating Eclipse with Maven) will setup a build path for you.
Two Solutions - 1 Using Eclipse IDE
Install the Maven (M2E Eclipse Plugin) if you use older version of eclipse, If you download the latest eclipse.
Point your settings.xml and create a maven project from your eclipse, it is better keep Group Id as com.yourcompany.app Artifact Id as yourProjectName and Version 0.0.1-SNAPSHOT depends on your Architecture Standards set by your company. Also Packaging can be as WAR file for WebApplication, EAR file for Enterprise Application. You can find the numerous list of examples from Maven Site.
2 From Command Line
Install Maven from Apache Maven site, Would recommend to go for the latest version -apache-maven-3.3.9-bin.zip.
Set the Maven Home in the Environment Variables as shown in the below figure.
Edit Your Path variable as %MAVEN_HOME%\bin, verify your installation by using this command from your command prompt. It should display the Maven Home and Java Version, which confirms your maven successful installation.
Paste your settings.xml (C:\apache-maven-3.3.9\conf) given by your build team or Architecture team for accessing your internal repository. And keep a backup of the original settings.xml (which is default download from Maven site)
Run these commands from your command prompt.
mvn eclipse:clean -e
mvn eclipse:eclipse -e (which will automatically set your project build path as shown in the below figure)
It will resolve your compilation issues and your project is ready as an deploy-able artifact
Forgive me asking following questions. I am totally lost in regards to maven+eclipse. I checked out someone's java project (maven built) from SVN to my local eclipse (kepler). When I click Windows > Preferences, I see Maven.
question 1)
Is this a maven plugin? When developers say maven in eclipse, are they referring to maven plugin? maven and maven plugin are two separate components?
question 2)
when I click on user settings, C:\Users\myName.m2\settings.xml is missing. Exact error message is "User settings file doesn't exist". Does it get created when you install maven plugin at first time?
question 3)
I found three folders may have to do with maven C:\workspace\maven_local_repo_artifactory directory, C:\maven_local_repo and C:\Users\myName.m2\respository but not sure how they get created and what is the relationship among them.
question 4)
Is it ok to remove current maven plugin from eclipse and re-install it then check out the java project from SVN? I think my maven or maven plugin settings are not correct in my local box.
1) Is this a maven plugin? When developers say maven in eclipse, are
they referring to maven plugin? maven and maven plugin are two
separate components?
Yes. This is the maven-plugin. maven-plugin uses the configurations of maven (%M2_HOME%/conf).
If you wanna work with maven, you need to install it on your machine. Then you can run maven commmands. In addition, if you want to invoke maven commands within eclipse (conveniently) - you can install the eclipse-plugin. "maven-plugin" is a plugin for eclipse, that lets you use maven within Eclipse conveniently.
2) when I click on user settings, C:\Users\myName.m2\settings.xml is
missing. Exact error message is "User settings file doesn't exist".
Does it get created when you install maven plugin at first time?
By default, the maven-plugin assumes that your settings.xml (which is the configuration file of maven) is in the path you have mentioned. However, there are cases (like in my case) where the config file is not there, but under %M2_HOME%/conf. you can update it in Eclipse, and the error will disappear.
3) I found three folders may have to do with maven
C:\workspace\maven_local_repo_artifactory directory,
C:\maven_local_repo and C:\Users\myName.m2\respository but not sure
how they get created and what is the relationship among them.
C:\Users\myName.m2\respository is the "local repository". If you learned a bit about how maven works, it holds a local repo on the local machine, and it keeps there all artifacts. It downloads them from the "repository" - if you have one in your company (Nexus, Artifactory, etc) or from Maven Central. However, this path is configurable by Maven's settings. So there might be that someone played with it and changed the path, and these other directories were created. You did not mention what resides inside these paths...
4) Is it ok to remove current maven plugin from eclipse and re-install
it then check out the java project from SVN? I think my maven or maven
plugin settings are not correct in my local box.
Sure it is OK. You may remove the plugin, and the source plus maven itself will not be deleted from your machine.
HTH.
Is it possible to run mvn deploy from Eclipse using M2E? I have the distributionManagement section in my pom.xml and the server configured in my settings.xml, but I can't for the life of me see where I can fire of that specific goal.
If the distributionManagement section of your pom is setup properly and pointing to your Nexus, you just need to run the Maven
deploy
goal.
Assuming that you installed the m2eclipse Maven Eclipse plugin, right click your project or your pom, Run As>Maven build and enter the goal "deploy" on the goals line.
If you did not install a Maven Eclipse plugin, add an External Tools configuration pointing to your Maven install for its "Location" and your project dir for its "working directory", with "deploy" as its argument.
From what I have read, after adding the relevant maven repositories, maven should automatically download the necessary jars to satisfy dependencies in the pom.xml file.
However, no jars ever get downloaded for me after I add dependencies in eclipse. Am I missing some glaringly obvious step?
I'd recommend to start from creating your project with m2eclipse. See more details in this article.
Basically, you need to make sure the following:
your Eclipse project has a valid pom.xml and all dependencies are available (you should see errors on Maven console, in the Problems or Markers view or when opening pom.xml in m2eclipse's POM editor)
Maven support is enabled for this project (you can use Maven / Enable Dependency Management from popup menu on that project)
project configuration is in sync with pom.xml (you can use Maven / Update Project Configuration from the project popup menu)
you can also use Maven / Update Dependencies to refresh your dependencies (e.g. when you got them in your Local Maven repo from the command line)
Dependencies jars aren't in your project but in your local maven repository.
These jars will be automatically used when you compile you project with maven (or m2eclipse).
If you don't have the needed jar yet, maven will download it for you.