Put a comment in goals of "Run configurations" wizard in Eclipse. - java

I am writing a Java project using Eclipse, Maven.
In the "Run configurations" wizard of Eclipse I am running the following goals
-e clean install
-e clean compile
-e clean -Dtest=MyJUnitTest test
Since I am running these configurations quite frequently, instead of three configurations, I am thinking it will be more convenient to be able to write one.
-e clean compile // -Dtest=MyJUnitTest test
With //, I was hoping to tell Maven not to execute anything written after //. However, this does not seem to work and Maven complains about //. Is there any other delimiter used for commenting out in Maven? Is there are a facility of commenting out parts of maven command at command prompt at all?

Try something like this:
call mvn clean install -Dmaven.test.skip=true % This is a comment %

Related

Maven works in Command Prompt, but not in Power Shell

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"

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 options are available to mimic "sbt run" in Maven?

In a project where I use the scala language, with sbt can launch directly from the terminal the command:
sbt run
Now I switched to use java with maven. If I try to run in the terminal:
mvn run
the command does not work. The error is:
[ERROR] Unknown lifecycle phase "run" ...
There is an alternative way to do it?
Thanks a lot.
Use the maven exec plugin.
mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
You can configure the plugin in your pom.xml to set what the default main class and default arguments should be.

Write custom maven command set using eclipse plugin

from command line I can write
mvn install -Pauto-deploy
Is it possible to store this command in my eclipse maven plugin. I want to execute this command by click.
I see only standart things in maven menu:
build
clean
install
test
I want see at this list my_autodeploy_command
I am sure it is possible but I don't know how.
Can you show how?
where can I write mvn install -Pauto-deploy ?
Somewhere here?
UPDDATE
for taringamberini
The dialog is the correct one. Install, the lifecycle phase to run up to, is put into the goals field, your profile (auto-deploy) is put into the Profiles field (without -P):
You could also copy the full line (without leading "mvn") into the Goals field
Is it possible to store this command in my eclipse maven plugin.
Yes, it is:
In the Package Explorer view right click your Maven project
choose Run as and Run configurations...
right click on Maven Build (node added by your eclipse maven plugin) and choose New
Compile the filed Name for example with clean_test_install
Compile the field Base directory browsing your maven project directory
Compile the field Goals for example with clean build test install
click Apply and close the Run Configuration window
Now, in the tool bar, if you click on the drop down menu at the right of the Run As ... button you can see the clean_test_install entry.
UPDATE
You can do it in maven plugin in eclipse as below.
Go to debug configuration eclipse --> New configuration in Maven Build
Specify Goals as clean -install and select base directory as project which you want to build. You can also skip test if we want in configuration
I had an ugly/complicated maven command which launched my project. And On Windows, I wanted to launch it in eclipse - to see the console, and not under a command prompt - where you can't see the console clear. The Maven command was something like:
mvn -am -pl web package -DskipTests -P link-repo,tomcat-run,local-jive -Dfile.encoding=UTF8
So blackbuild answer:
"You could also copy the full line (without leading "mvn") into the Goals field"
saved my life!
I just copied the maven command in Goals field and it worked!

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