Maven works in Command Prompt, but not in Power Shell - java

I am very new to Maven and initial stages where i am exploring how to create a java EE project that i can host in a server. Maintain it through Maven.
First question is asked is how do i create the same structure of a java project that is created by Eclipse when i create a new Maven project in command line in Power Shell?
My findings -
Please see the image snippet
I understand that once we have a project crated. If you want to add modify how your project should build, we can modify that, or we can add new dependencies or many other things from the POM.xml.
But initially atleast it should create the structure of the maven project with a minimal pom.xml right ?
I used the command mvn archetype:generate .... In the Command Prompt the project was created correctly. But I need Maven work in the Power Shell, and this produces an error:
The goal you specified requires a project to execute but there is no POM
in this directory ...
Thanks in Advance

See tutorial. It is pretty good:
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
To create a project structure:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
For PowerShell, use quotes for -D, as follows:
mvn -B archetype:generate "-DarchetypeGroupId=org.apache.maven.archetypes" "-DgroupId=com.mycompany.app -DartifactId=my-app"

Related

How to create maven projects on VS code?

I've already succeed creating java project on vs code. I am installing Java extension pack which is auto install another plugin (like language support by red hat and etc), I am using jdk 8 (jdk1.8.0_241). I am using command palette to create new java project. But my new project doesn't contain pom.xml
Anyway I don't install dedicated maven, only Maven for java extension
I need maven for iReport/jaspers dependencies
You are probably creating a new "Java Project", which is Eclipse-based structure, not Maven.
In the command pallet (Cmd+P on macOS), type Maven and you shall see "Maven: Create Maven Project".
Next step, the extension will ask you which Maven Archetype to use. Select "maven-archetype-quickstart".
You will be asked for input on the terminal after this.
Once the project is generated, type $ code to open a new VSC window.
Done.
You can execute this by cmd:
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.mycompany.app -DartifactId=my-app
This will generate a maven-archetype-quickstar project.

How to create maven project to support Intelllij project structure?

I am using IntelliJ community version and I am trying to create jersey project,but my intelliJ is not allowing this feature.
mvn archetype:generate -DgroupId=com.mkyong.rest -DartifactId=RESTfulExample
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
But as here, I created maven project from command prompt and I saw ,I needed to add extra support for the IDE.Since this command as given down in figure is for Eclipse,What is the command should I run for IntelliJ to change it so that IntelliJ will support it?

Want to build project with commandline mvn but have to use Maven update in eclipse first

I'm working with multiple projects in Eclipse. because I want to automate the building I want to script the building process.
Unfortunately I cannot do the same actions on the commandline as in Eclipse.
So a common problem is that when a new function from a referenced project is used, I cannot build the project on the commandline with mvn. I use the command:
mvn clean install -U
But this command will give a build failure until I do a Eclipse Maven Update from the eclipse GUI. After that I can build the project again.
I also tried all the other commands I came across Stackoverflow:
mvn eclipse:eclipse
mvn dependency:resolve
So I just want to that Maven Update command in eclipse from the commandline so I can build from the commandline. If anyone could tell me what I'm doing wrong that would be awesome.
Thx in advance
Update for more clarification:
The project structure is:
Rest-service, Framework-service, Framework-model
Framework-model is referenced in the pom file by Framework-service and Framework-service is referenced by Rest-service. The other projects are not relevant to the problem.
When a function is added to Framework-model and used in Rest-service it gives an compilation error in eclipse and when I build with mvn clean install -U, although Maven install in eclipse is succesful but I think it is still using the old compiled code. After a Maven Update command in eclipse the compilation error is gone. And mvn clean install -U from the commandline also works.
How could I do a Maven Update command in the commandline? If mvn clean install -U should also do a Maven Update command, what settings should I check?
Another update: So this weekend I tried different things and running mvn compile before the mvn clean install -U command gives a different output. And finds the new function. But as I read maven, I thought install should also do the previous steps. How is this possible?
Eclipse's Maven plugin uses the maven version configured in Preferences/Maven/User settings. If you have a different version of maven in your Eclipse's settings than the one on your PATH variable, you could have different outputs. Maybe try and check that.

What is the difference between maven-archetype-mojo and maven-archetype-plugin?

Snippet from the output of running the command mvn archetype:generate > a.txt:
332: remote -> org.apache.maven.archetypes:maven-archetype-mojo (An archetype which contains a sample a sample Maven plugin.)
333: remote -> org.apache.maven.archetypes:maven-archetype-plugin (An archetype which contains a sample Maven plugin.)
Running the following commands generated near-identical pom files and Java source classes:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app-plugin -DarchetypeArtifactId=maven-archetype-plugin -DinteractiveMode=false
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app-mojo -DarchetypeArtifactId=maven-archetype-mojo -DinteractiveMode=false
So what is the difference between maven-archetype-mojo and maven-archetype-plugin? Will either of these generate a sample plugin project? Why do we have both?
There is no difference. Maven Mojo is a minimal Maven Plugin.
What is a Mojo? A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos.
I think we does not need both, just some mess in Maven world :)

specify pom.xml in mvn command and mix goals of other project

I have multiple questions.
Can I specify the pom.xml in mvn command?
Can I mix the goals of another project while executing mvn command on current project ?
Eg: mvn clean-otherproject comple-otherproject instal-otherproject compile-thisproject
I can do this with multiple mvn commands, but Can I do this in single maven command.
Just mvn --help would have answered the first question:
mvn -f otherPomFile.xml
No. You can simple execute the phases for the current project you are in. You can give multiple phases like
mvn clean install site site:deploy
For the first question, see khmarbaise's answer
If you want to build more than one maven project in one step, you must use modules.
In a multi-module project, if you call mvn install from the top project, all sub modules are built, unless you use the advanced reactor options (e.g. mvn install -pl util -am only builds the module 'util' and it's dependencies)

Categories

Resources