Need to keep the jar in my maven local repository - java

I want to keep custom jar in local repository.Maven is already installed in eclipse.But coming to the command prompt it is showing as "The program 'mvn' is currently not installed. You can install it by typing:
sudo apt install maven"
If i install the maven and keep that jar in local repository,will it reflect eclipse pom?

You need to install maven on your system as suggested.
Now in eclipse go to Window -> Prefrences -> Maven -> installations and add that maven there.
Then install your custom jar to maven as suggested here.

eclipse brings its own maven implementation.
If you want to run maven from command line you need to install it explicitly.

Related

Install Maven artifact from remote repository like npm install

I'm searching for a Maven CLI command to install a Maven artifact (e.g. jar library) from a remote Maven repository. I don't want to manually download the artifact first, so that I can install it. I'm looking for a command like npm install rxjs, which automatically downloads rxjs and installs it as a dependeny to my project.
Is there an equivalent command available for Maven?
Unfortunately, there are no such commands.
One option is through a shell scripts or stream editors (e.g. sed).

how to run maven project from github in eclipse

I use eclipse and I want to compile and run this code from gitub https://github.com/openphacts/Validator ,it needs maven project to build it but unfortunately I don't know how to proceed with it. Can someone help me how to get this project into eclipse to run it and test it in my machine please? It's emergency
Once you've checked out the project from github, you need to utilize maven to install the dependencies and build the project. In the root folder of the project (where the pom.xml is located), enter the following in your command line:
mvn install
More details can be found here: https://maven.apache.org/run-maven/
Additionally, you must first download the maven command line tool: https://maven.apache.org/download.cgi
And install it: https://maven.apache.org/install.html

Maven dependecny is not available in eclipse java build path

I checked out an existing eclipse project from SVN. Then I converted it to Maven project.
The project is compile with Maven target clean install perfectly no problem. But the eclipse doesn't identify any dependency jar file. Basically it does not know the Maven repo path. It knows only JDK path. So all my java classes are with full of red lines.
Everything in this site and google I checked all fine. But why eclipse can not find the mvn repo?
eclipse version = JUNO Version: 4.2.2. ( I think this has inbuilt maven plugin)
Maven plugin detail = M2E - Maven Integration for Eclipse version - 1.4.0, Provider - Eclipse.org -m2e
UPDATE ======================
If I checkout the source code separately and import it as a maven project that way its working. But I want to know why if I checkout the code through Subclipse and convert it to maven project is not working?
Run
# use maven to control your eclipse .project and .classpath files, that is
mvn eclipse:clean
mvn eclipse:eclipse
and then restart your eclipse (or switch your workspace and then back).
Make sure you have the m2e plugin, - from here, you should read the Release Notes and add this to your update sites - "http://download.eclipse.org/releases/juno" and "http://download.eclipse.org/technology/m2e/releases".
In Eclipse, you can actually create an external tool Run> External Tools> External Tools Configurations. After this you can select your project that you want to setup and run this external tool.
or if you have maven plugin installed in eclipse, select your project right click Run As > Maven Build... (see below image). In Goals put "eclipse:eclipse" and click Run

Java Eclipse Build Path Errors Maven

I am just starting out with Maven. Is there any way to get maven dependencies to be added to the Eclipse project's build path? As of right now, my project is full of red x's due to Eclipse not being able to include some external class from one of these dependencies.
First you need to setup you M2_REPO variable. This is a class path variable that tells eclipse where your designated maven repository is located.
You can setup M2_REPO by running the following command in your workspace.
mvn -Declipse.workspace="replace with your Eclipse Workspace" eclipse:configure-workspace
Next make sure that your project has a maven fact applied by running the following command
mvn eclipse:eclipse
in the workspace of your project. run
mvn clean package
just for good measure to make sure all your dependencies are resolved and available before restarting eclipse.
Once you restart eclipse again and bring your project up your issues should be resolved.
You should look up more information about these 2 commands and how to use them effectively.
Save yourself a ton of hassle and get the M2Eclipse plugin. The plugin will handle all of the project setup for you and you don't have to worry about doing the mvn eclipse:eclipse commands.
http://www.sonatype.org/m2eclipse/
have you executed
mvn eclipse:configure-workspace -Declipse.workspace=/path/to/workspace
?
You need to execute it so maven set the M2_REPO path to eclipse. Or you can set it manually.
Remenber to restart eclipse after you do so :P

Is it ok to Install maven if I already have installed maven eclipse plugin?

I have maven eclipse plugin and I want to use a jar file in my project that is not supported in maven so I found out I have to do something like this :
mvn install:install-file -Dfile=c:\kaptcha-2.3.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar
So I have to install maven to issue that command but won't that cause redundancy with maven plugin ?
You can install multiple different versions of maven, and configure m2eclipse to use a specific instance, see the setting under Window > Preferences > Maven > Installations.
Managing multiple different versions on the command line is controlled by the PATH environment variable, you would normally define an environment variable M2_HOME which specifies the home directory of the version that you are currently using, and then add $M2_HOME/bin or %M2_HOME%\bin to your path environment variable.
It is no problem if you have both maven and eclipse maven plugin installed. I only use eclipse maven plugin for its pom.xml file editor. I do all other operations about maven through the command line.
Besides, the plugin (m2eclipse) I used, sometimes give strange dependency errors although everything is fine. Because when I run a "mvn install" for the project, it is built successfully. So, I think using maven itself is more reliable.

Categories