Run mvn command on module from existing source - maven

I imported several maven modules on IntelliJ IDEA by using the option File/New/Module From Existing Source. This is working fine but I'm not able to run mvn command lines on one specific module by its module name.
I was able to do it by specifying the path to the pom.xml file by using -f option:
mvn -f "path/to/pom.xml" clean
But I would like to avoid having specifying the path every time I want to run a mvn command. Is their any way to run the command by specifiying the name of the module ?
Thank you.

If you use "Run Anything" then it's possible to select module at the top right corner

You can perform maven install, maven clean etc for a complete module or sub modules of a project using top right option in IntelliJ.
Maven-->select module/submodule folder-->Plugins-->select the option:- deploy, compile, install, clean etc.

Related

Maven project execute without ide

I do a selenium test using Maven. I have more than 20 test classes. How do I export and run them without ide ?
I am also using the POM structure.
Simply open terminal/cmd, navigate to you project directory and use maven command:
mvn clean test
clean ā€” delete target directory
test ā€” run tests
If you want to specify which exactly class you want to run (no all like above) you can run a -Dtest parameter like suggested:
mvn clean -Dtest=testClass install
First navigate to folder where your project's pom.xml is located.
cd DirectoryWherePOMisLocated
then execute below command,
mvn clean -Dtest=classNameWhichYouWantToExecute install
If you want to execute multiple classes just separate them with , in -Dtest argument.
Hope this helps!!

Export a Eclipse RCP product from command Line

I tried different way to export it but i couldn't succeed in it.
I need a way to export my product file which is located in my workspace.
If you need to implement do that using command lines, you must compile the product using maven with tycho. You will need to implement every module as a artifact in Maven.
After the configuration you only need to run:
mvn clean install
Please read this link:
https://www.eclipse.org/tycho/
Here is the tutorial to configure your project:
https://www.vogella.com/tutorials/EclipseTycho/article.html

Set up Jenkins to run a specific maven command

Iā€™m new to Jenkins and currently working on a maven project.
I am able to run a simple Jenkins job using maven commands.
mvn clean install
However, the extended requirement requires me to us an additional parameter in the maven command
mvn clean install -DfileName=file1
Is it possible to have a drop down with file names (e.g. file1, file2 ..) and have the user selected one append to the maven command.
mvn clean install -DfileName = {selected filename from dropdown}.
Could some one please assist with this along with what plugin and how can I setup.
Parameterize your jenkins job see https://wiki.jenkins.io/plugins/servlet/mobile?contentId=34930782#content/view/34930782.
Use choice parameter to add your file name choices
Active Choices Plugin - https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin
The user selected choice can be used in your maven command using "{params.param_name}".

How to add a new module to Spark source and make it work in spark-shell?

I'm using IDEA15 and I want to add a new module to the spark source.
I clicked File->new->module and chose a maven module. Then I set the "Add as module to..." option and the "Parent" to "Spark Project Parent POM". After typing in the module name I clicked "Finish".
Then I added some code to my new module and build it using the follwing command
"build/mvn -Pyarn -Phadoop-2.4 -Dhadoop.version=2.4.0 -DskipTests clean package"
The project was built successfully but in the spark-shell I can't import my newly added classes.
I wonder what's wrong with what I've done and how can I add a new module and then import it in the spark-shell?
Thanks a lot!
PS: I'm sure there's no problem with my code. I added my code in the mllib module and it worked.
Maybe some dependency is missing but I don't know how to fix it.
The Maven build created a jar file from your build (should be in the target/ directory inside your project folder).
When you start the Spark shell, you can define the jar files to include in your shell. You can include your jar there like this:
spark-shell --jars /path/to/your/project.jar
Also you could give it a try, to install your project inside your local Maven repository, it is possible that the Spark shell can pick it up (so you don't have to specify --jars each time you run the it).
For this, run your Maven build command with clean install instead of clean package at the end.

How to Build a maven project using script file?

I have created a maven project in STS.I completed the development and testing code for my project.If now I want to run or build this project, then I have to do the following
Right click on the project-->Run as-->Run on Server (or)
Right click on the project-->Run as-->Maven Build
If I want to run the test code then
Right click on the class file-->Run as-->Run JUnit
But I want to create a text file I mean script file to run all these commands when I run this script file from the cmd prompt. I have found out on a web site that I should create a PowerShell file, So I don't cognize how to compose a script file like this, is there any example file for it ?
Please, anybody can help me
You can just run mvn clean install on your project root folder (i.e. where your pom.xml file is) in cmd prompt. This command will trigger your project default build lifecycle covering a number of build phases including:
validate
compile
test
package
integration-test
integration
verify
install
During these build phases, Maven will validate and compile your project, run tests (if any) against your codes, package the resultant binaries into say, a JAR file, run integration tests (if any) against your JAR, verify it, and then install the verified package to your local .m2 repository.
If you really want a script, then just add mvn clean install to your batch file.

Resources