I want to create a Maven Project through command prompt. I have installed Eclipse+Maven.How to find out the location of mvn folder?
The Maven that is included in Eclipse cannot be used on the command line.
You need to install a separate command line Maven for that.
I think it's best if you provide more details of exactly what you want or need to do. When you say you want to create a maven project through the command prompt, do you mean with a maven archetype? I have a feeling you don't know what that is.
If you want to create a new Maven project, you can do it in Eclipse, with "File"->"New"->"Other..."->(filter for Maven)->"MavenProject".
Related
I have a Java Spring MVC web app in Eclipse/STS.
I can build the WAR file by right-clicking on the project and choose "Run As > Maven Install". The WAR file is created under \target\MYPROJECT.WAR
Now I want to run this from the command line because I'm writing a script that will build the WAR, and make a deliverable ZIP file (with the WAR, readmes, docs, and config files).
I'm on a Mac, when I run 'mvn install' from the root of my project, it says "command not found: mvn". I prefer not to setup a separate maven installation, I'd rather use the same one that Eclipse is using.
Where is the Maven installation that Eclipse/STS is using?
Answering the question after getting helpful comment from #greg-449
The answer is, you cannot (or are not supposed to) use Eclipse/STS's built-in Maven from the command line.
So instead I installed a separate Maven instance.
I am trying to use Maven to export my project into a JAR file, however I am also trying to export the dependencies as well and I am using the shade plugin, however I am wondering how exactly would I then run it?
I read I need to run "mvn shade:shade", however I don't exactly know where I run this? in the terminal I get 'mvn' is not recognized as an internal or external command, operable program or batch file.
So I don't really know where I am supposed to run this
Note: This solution assumes that your project is configured/imported as a Maven project.
Right-click the project in Eclipse. Select Run as > Maven build... > Goals, type package and then click Run.
Following best practices, you should not run shade:shade from the CLI (which you are actually doing with this approach), but rather bind the shade plugin to the package phase.
This link will explain how to do that, if you haven't already done it.
I was looking for information about mvn eclipse:eclipse and I realize that there are some obsolete goals here, one of them is eclipse:eclipse.
Is there any alternative to doing the same from the command line?
This plugin is deprecated, there's no need to use it anymore. In fact, it will do more harm than good.
In short: eclipse:eclipse generates all eclipse files based on the pom.xml. This means that if you change the pom, you always need the run the goal again. With m2eclipse it is aware of changes in the pom and will update your project on the fly in most cases. I know that if you update the source/target, you need to run a Maven Update from the context menu explicitly.
In my maven project I usually use the POM file named pom.xml. I have a second POM file though (call it pom_alt.xml), which I occasionally use to perform a very different build of the same project. To do so I specify the -f option in the command line
mvn clean package -fpom_alt.xml
as suggested by man mvn:
-f,--file
Force the use of an alternate POM file.
Now, when I am coding in eclipse I usually need maven to use pom.xml, but sometimes I should code or debug while the other file pom_alt.xml is used instead. Is there a way to tell the eclipse maven integration to use that file? Currently I am temporarily copy-pasting from pom_alt.xml to pom.xml since I seldom happen to need that, but you can see that's not optimal.
I am with Eclipse IDE for Java EE Developers, Mars Release 4.5.0.
UPDATE
I could build from the command line or use Run As Maven build as in
Carlos Andres' solution, but ideally I would like to define a persistent setting, like a property or preference. This because I find nice if the POM file can be fixed while I am doing things like running as Java Application and test cases, or executing on a server. Processes that require a project clean or server restart are often triggering a maven build with the default POM.
Check that M2E - Maven Integration for Eclipse is installed on Eclipse. Once that is installed go to the project and press right click
Next, put the command that you want to execute
This option allow you to save the commands, and the next time all your commands will be saved.
To execute the command recorded go to
Note: I'm asking about the command line mvn tool, although I imagine similar answers would apply to the m2eclipse plugin?
It's a bit confusing what the command line mvn targets that mention Eclipse actually do and DON'T do.
Confirming what I believe I understand:
The mvn eclipse:eclipse command is just generating Eclipse dot-project files? You would them import them into Eclipse?
The -Declipse.workspace=(eclipse-workspace-path) eclipse:add-maven-repo is just updating workspace files to point a repository, but does not tell the workspace anything about your maven projects, even if you do both steps in the same command?
When I first saw the references to Eclipse in the Maven doc I thought perhaps you could generate set of Eclipse projects and add them to a template workspace from the command line, but I guess that was just wisshfull thinking.
The m2eclipse and command line mvn tool take two very different approaches to Eclipse/Maven integration. It sounds like your question is about mvn tool.
The mvn eclipse:eclipse command reads your pom file and creates Eclipse projects with correct metadata so that Eclipse will understand project types, relationships, classpath, etc. It does not actually import those projects into a workspace as creating a workspace or importing projects into a workspace requires running Eclipse. You have to re-run this command when anything in your pom changes. Once you run this command, it is simple to import the created projects into your workspace. Just start Eclipse and use File -> Import -> Existing Projects wizard. Once you've imported projects you will not have to repeat this process after re-generating metadata unless the number of projects have changes. Just start Eclipse back up, select all projects and invoke refresh from the context menu.