How can I run testng.xml file in linux with cmd - cmd

How can I run testng.xml file in linux with cmd ?
What is command to run in linux command

java -cp "path to the testng jar" org.testng.TestNG testng.xml
For testng you need only one jar.So put that in the classpath and for the compiler to understand that it was a testng xml file you have to add "org.testng.TestNG" and run like a normal java program.
The testNG jar file can found in this link if you didn't have the jar file
-> You have to remember one thing,The compiled class file must be in the same directory you are running from the test suite xml

cd <Location of TestNGProject> ie. D:\workspace2\TestNG java -cp
D:\workspace2\TestNG\lib\*;D:\workspace2\TestNG\bin org.testng.TestNG testng.xml
java -cp argument is used to provide path to classes and libraries that our program need to run

Related

Run TestNG.xml through command prompt

I am trying to run testng.xml from command prompt and getting error that main class not found.
How to give reference of org.testng.jar while running testng.xml from command prompt
Have you tried reading documentation?
Assuming that you have TestNG in your class path, the simplest way to invoke TestNG is as follows:
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]
If you have your tests and testng.jar in your CLASSPATH the above command should be enough.
Approximate syntax for more complex scenarios:
java -cp "/path/to/test.jar;/path/to/your/tests.jar;/path/to/test/dependencies.jar" org.testng.TestNG testng.xml
where testng.xml is the TestNG config file
More information with examples: Automated test using TestNG chapter

Having issues running java project through command line

I am completely new to using maven. I have created a maven project and exported it to eclipse. Maven automatically created the src/test/java and src/main/java.
I created a java script and successfully ran it in eclipse. But when I try running it through command line, I got an error that says:
cannot find or load main class.
When I checked my project directory, there were two classfile paths: classes and test-classes. The script I was running is the one in 'test-classes' but it is not the main class. But the path to the main class executes successfully but that is not where my script is located.
The command I was using for the main classfile is:
java -cp target/Test-1.0-SNAPSHOT.jar com.mycompany.App.
The command for the test classfile is :
java -cp target/Test-1.0-SNAPSHOT.jar com.mycompany.AppTest.
This second command gives me the error I mentioned.
Please how do I get around this issue?
By convention, everything in src/test/java is supposed to be for testing only. That is, you should place only your test classes in this directory. Maven will run them before building the final JAR, but it will NOT include them in it.
If you absolutely need a JAR with your test classes, have a look at How to create a jar containing test classes.

How do I run a java program in cmd?

I have created a program in Java, but it is not taking the inputs correctly in edit-plus(compiler) so now I want it to run in cmd. My JSK file is at : C:\Program Files\Java\jdk1.7.0_21\bin and my Java file is at: C:\TurboC4\TC\java new programs
Please tell me the steps to run it in cmd.
On the command line use:
java -jar path/to/your/jar_file.jar
if you do not have a jar file, than you have to compile first your Java classes:
javac -g Foo.java
if you have just a single file (containing a static void main()) than you can simply run it with:
java path/to/your/compiled_class_file [<command line args>, ...]
Note: Run the command above without .class extension. i.e.
java Foo
if you want to generate a jar file from your compiled .class files run:
jar cf jar-file input-file(s)
However, I would recommend you to use a IDE that compiles, packs and runs your code for you automatically with one click. i.e. IntelliJ or Eclipse
If your class is not into a package and is compiled as java.class in C:\TurboC4\TC\:
cd C:\TurboC4\TC\
C:\Program Files\Java\jdk1.7.0_21\bin java
If you just want to run your single java class as a command line program, then the answer is in This question.
Example:
java my.class.HelloWorld
If you have compiled an entire java project into a JAR file, check this Stackoverflow question for the answer.
Example:
java -cp c:\location_of_jar\myjar.jar com.mypackage.myClass

How run mahout in action example ReutersToSparseVectors?

I want run "ReutersToSparseVectors.java". I can compile and created JAR file without problem.
I compiled this file by below command:
javac -classpath hadoop-core-0.20.205.0.jar:lucene-core-3.6.0.jar:mahout-core-0.7.jar:mahout-math-0.7.jar ReutersToSparseVectors.java
created JAR file with below command:
jar cvf ReutersToSparseVectors.jar ReutersToSparseVectors.class
When I write java -jar ReutersToSparseVectors.jar to run, give me below error:
Failed to load Main-Class manifest attribute from
ReutersToSparseVectors.jar
Do you can help me to solve this problem?
IF this example can run with hadoop, please me that how i can run this with hadoop.
instead of using -jar option, then it's better to to run:
java -cp mahout-core.jar:... mia.clustering.ch09.ReutersToSparseVectors
or you can use mvn exec:java command, as described in README for examples...
mvn exec:java -Dexec.mainClass="mia.clustering.ch09.ReutersToSparseVectors"
Or you can run this file directly from your IDE (assuming, that you correctly imported Maven project).
P.S. your command isn't working, because to run with -jar switch, the .jar file should have special entry in manifest that describes that class should be started by default...
P.P.S. It's better to use book's examples with Mahout 0.7, as they were tested for it. You can use it with version 0.7 if you need, by then you need to take source code from mahout-0.7 branch of repository with examples (link is above)

How to Execute Clojure File?

How can I run a clojure file/script, which uses clojure-contrib, from the command line? My (winodws) machine has clojure-1.2.1.jar and clojure-contrib-1.2.0.jar on the classpath. Note: I can start the REPL with: java clojure.mainand I can execute *.clj files that DO NOT use clojure-contrib with: java clojure.main file-name.clj
You need to add the clojure-contrib jar to the classpath. Since you are using windows, you add multiple classpaths by separating the entries with semicolons.
java -cp clojure-1.2.1.jar;clojure-contrib-1.2.0.jar clojure.main file-name.clj
The above code should enable you to run your file-name.clj script which depends on clojure-contrib.
This line will run a clojure script "hello-world.clj". It first adds the clojure jar to the class path first and then will execute the file.
java -cp clojure.jar clojure.main hello-world.clj
for those used to text editor + lots of shell work
lein run isn't bad
and lein projects can help you organize deps and other proj-specific

Resources