I have clean integration-test -DclassId=appas a maven goal in a Jenkins Maven Job.
How can I retrieve this in Java using System.getenv();? When I do this I am only seeing null.
For command line options you have to use System.getProperty() instead of System.getenv():
String id = System.getProperty("classId");
Find more details here.
Related
Currently Im working in a Maven project where I need to run tests in different environments.
The idea is be possible to pass the environment as argument as examples below:
mvn test -Pdev
mvn test -Puat
How can I capture this argument -P from command line?
Thanks!
Hello there are tests written on Java + cucumber
The structure is as follows:
https://i.imgur.com/moLVY6L.png
The main question is how to run this tests not from the IDE, say from the console or even wrap it all in jar file
The problems encountered are that you need the main class to create a jar,
It seems as there is a certain java cucumber.api.cli.Main - but how to use it I do not understand. Either way, there's probably a way to run this just from the command line. Please tell us how to do it?
You can download Maven with following terminal script :
$brew install maven
After brew installation, you need to go to the project directory which includes pom.xml file in terminal :
$cd /path/of/your/project
And finally you can run following command to run your tests :
$mvn clean test
You can try the below on command prompt.
java -cp "E:\Workspace\CucumberProj\Jars*;E:\Workspace\CucumberProj\bin" cucumber.api.cli.Main --glue stepDefination E:\Workspace\CucumberProj\Feature\Login_Test.feature
Description
I'm writing a simple console application that starts in a Docker container, reads user input and processes it. For automating Docker I use docker-maven-plugin.
The code for reading user input is the following:
new Scanner(System.in).nextLine()
Tried also the following:
new BufferedReader(new InputStreamReader(System.in)).readLine()
Running an application without Docker works in both cases.
I run the docker with command:
mvn clean docker:build docker:run
However in Docker when it comes to user input the code simply returns null and doesn't block for user input. In case of Scanner I get java.util.NoSuchElementException: No line found which is basically the same.
I've found a similar issue on StackOverflow where passing the command line parameters -i -tseem to help.
Is there any way I could add these command line parameters to Maven run configuration? Or any ideas why this issue happens?
Info
Maven version : 3.3.9
Docker version : 1.13.1
It is not possible with docker-maven-plugin. See this.
I also agree with rhuss (last comment in the link) as well. You are using maven which is a build tool and then starting containers which will probably help you in some way to build-test something. Also, if you refer to this section in docker documentation, it says
Specifying -t is forbidden when the client standard output is redirected or piped
which probably a build plugin will do.
Trying to do some automated test. I have used below commands to execute the junit file (RunnerTest.java) in command line, getting an error as "could not find class"
Command line commands:
C:\Users\username\workspace\MavenCucumberPrototype\src\test\java\com\cucumber\MavenCucumberPrototype>javac -cp "C:/cjars/*" MavenCucumberPrototype/*.java
C:\Users\username\workspace\MavenCucumberPrototype>java -classpath C:/cjars/junit-4.12.jar org.junit.runner.JUnitCore src.test.java.com.cucumber.MavenCucumberPro
totype.RunnerTest
Maven Project structure
MavenCucumberPrototype
-/src/main/java
-com.cucumber.MavenCucumberPrototype
-/src/test/java
-com.cucumber.MavenCucumberPrototype
-postconn.java
-RunnerTest.java
-Steps.java
-/src/test/resource
-myfeature.feature
When I run Maven projects from a command line, I usually do
mvn clean install
or whatever lifecycle phase I want to execute. In your case, it might be sufficient to do
mvn test
The only imprtant thing to notice is that you must execute the command in the same directory as the pom.xml resides.
The error you recieve is nost likely due to a classpath that doesn't contain what you expected.
I'm configuring a Maven project and want to be able to alias, like
mvn server - to execute mvn clean package tomcat:run
The Grunt task runner does it very well, but I haven't found a way to do the same in Maven. Is it possible?
You can define a <defaultGoal>...</defaultGoal> in your pom if you like. So you can define something like this:
<project>
<build>
<defaultGoal>clean package tomcat:run</defaultGoal>
.
</build>
</project>
will be activated if you simply call mvn...not really an alias, cause usually you don't need one...
Out of the box I don't know of any solution that doesn't imply using a plugin. A simple solution may be adding aliases to your .bashrc file in your home directory (for Linux) or .bash_profile (on OS X) for your desired instructions.
E.g: Adding a line alias my-alias="mvn clean install" will allow you to execute the command my-aliasin the terminal, obtaining the same result as running the mvn clean install instruction itself. Add another line alias my-alias-port="mvn clean install -Dcrx.port=9200"for a second instruction, and so on.
Optionally, you can execute alias to see a list of all your aliases and their respective instructions.
The best solution I have found to this is to use a combination of:
New Maven 3.3 command line config support: project/.mvn/maven.config
GNU Make (which then calls maven)
Bash scripts
Blaze
Roughly in that order of preference.
GNU Make is especially nice because it offers bash completion.
An example Makefile for your specific example would be:
.PHONEY: server
server:
[tab]mvn clean package tomcat:run
Replace [tab] with a real tab! See make documentation.
Then you can run:
make server
For windows environments you will need to install cygwin or something equivalent. For Mac you don't have to but you should probably install homebrew.
Finally the Maven Bash completion albeit doesn't do aliases but will greatly facilitate typing maven commands (press tab). Many package managers have this as a package (ie homebrew has it as maven-completion).
You can also add the following function to your .bashrc file:
function mvn() {
if [ "$1" = "i" ]; then
command mvn install
else
command mvn $#
fi
}
And so you can invoke the mvn install with the mvn i alias.
Everything else that is not mvn i will call the original mvn command instead.
Alias-maven-plugin is what you are looking for.
Following the site:
Whenever you type a command in a shell, for instance
mvn clean install
you could spare time in simply using an alias like this
i
It has also more advantages - you could configure plugin by XML file.