How to run maven project using batch file? - java

This is what i have done till now:
I have API automation Script in maven using testng, Following is the structure of project
2.Now i first tried to run testng.xml using command-line with following command.
java -cp ".;C:\Users\A622965\.m2\repository\org\testng\testng\6.8\testng-6.8.jar" org.testng.TestNG testng.xml
3.But throws following error:
Error: Could not find or load main class org.testng.TestNG
Not able to figure out the issue after watching lot of tutorials.
I am looking to batch process the script using Task Schedular in Windows

Remember that Maven is a build tool, so every single operation which requires the classpath must be done through Maven, wether if you want to execute it from the command line or from some GUI.
So, in your case you will find useful the Maven command line tool:
mvn <phases>
In your case:
mvn test
But remember to include first in the pom.xml the testng library dependency, and also to properly configure the surefire plugin.

You need to build path for testng
Right click-->Build -->Libraries Tab-->Add External jar-->Then restart--it will work...

Related

Run a script after JSweet transpilation

I'm trying to build a TypeScript project with JSweet. After the transpilation, I want to run a script in any language to move some files around; specifically files that are already in TypeScript that don't need transpilation. I wrote a Groovy script that does just that but I can't make it run after the generate-sources instructions for JSweet.
Here's my pom.xml file: https://pastebin.com/932r9cWw
I am far from a Maven expert. I think the script shows that I'm trying to run the script scripts/addJsScripts.groovy after the transpilation, but I'm clearly doing something very wrong. The goals available to Maven Invoker plugin don't match the goals of the JSweet transpiler at all.
Is there a way to do what I'm trying to do?
There are plenty of ways to achieve this, but this is more a Maven issue than a JSweet one.
I suggest you use the exec-maven-plugin, as explained here: I want to execute shell commands from Maven's pom.xml

JUnit4-Serenity: Create an executable jar with all required dependencies and run the tests standalone

Please help solving the below:
Create an executable jar file of a Maven Java Project which only consists of JUnit4-Serenity tests and run it on command line.
Serenity-JUnit4 Maven Java Project - used only to run tests.
It only consists of test classes and each test class has an annotation #RunWith(SerenityRunner.class).
Currently I am executing all the test using the mvn command as below with couple of input parameters "appName" and "testENV":
mvn clean verify -DappName=test -DtestENV=integration
Reference project - https://github.com/serenity-bdd/serenity-junit-starter - running using Maven.
I am doing this to dockerize it by adding the created jar to a base image which consists of some required root CA.

Run IntelliJ configuration from command line

I've configured various execution and test configurations in my Java IntelliJ project. Is it possible to execute IntelliJ on a given project and configuration from the command line?
Summary
You will need to define a command line build project to run your tests from the command line, as IntelliJ (or any graphical IDE) does not provide tools to do so.
Details for building running tests using Gradle
In the following directions I picked Gradle as command line build language, though some use Ant, or Maven as possible alternatives. The gradle syntax is based on Groovy, which is a JDK-based scripting language.
A sample configuration for a basic java project is here: http://www.vogella.com/tutorials/Gradle/article.html
Once your Gradle project is setup, you can run 'gw test' from command line.
I highly suggest to install gradle wrapper called 'gdub' from here: https://github.com/dougborg/gdub -- this will save typing ./gradlew all the time.
Hope this helps!

mvn clean install to execute Cucumber test for executing a jar file

I am working on running Cucumber tests through Maven "mvn clean install" command. One of my Cuke tests including executes a jar file through command line with the following command - "java -jar -Dprop1:value... ./jarLocation. This test is working correctly and passing locally in my IDE, but when I perform a "maven clean install", it fails to start the process and throws a Null Pointer exception on the line where I start the Process.. Would anybody have an idea as to how to get this Cuke test to execute jar file, working with Maven? Any suggestions would be very much helpful.
May be its an issue of mapping, please check the below URL hope it would be helpful for you.
m2e lifecycle-mapping not found

How to execute a Maven build Java application

I am playing to Maven and tried to built a simple HellowWorld application.
This application uses Spring to libraries.
When I tried to run it, I run it through:
\target\classes
with command:
java -cp HelloWorldApp
It has a long list of classpath dependencies.
I think maven must have some more clever ways to do this instead of listing a whole list of dependency libs.
Can someone help?
Update:
Thanks. I now have another question. I run the project using:
mvn exec:java -Dexec.mainClass="com.vaannila.HelloWorldApp"
However, my project uses a Spring config called beans.xml which is in the
\src\main\resources
When I run it, it says:
Caused by: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.jav
a:336)
How can I specify where to look the Spring config?
Many thanks
Run your application by issuing mvn exec:java at the command line, maven will take care of the rest including download of the maven exec plugin.
EDIT As for your updated question: It appears that maven did not copy your resources to the target folder, you can use the maven-resources-plugin to do that. This link should help you get this done.
If you use IDE, such as eclipse +m2eclipse - it will calculate all dependencies from maven dependencies.
If you are running from command line use Exec maven plugin

Categories