How to execute Testng project without main method from command line - command-line

I have a TestNG project where I use testng.xml file to execute.
How to take a jar of my project and execute it on another machine.
I know how to execute it on the same machine by giving path of bin & lib folders i.e
cd C:\Workspace\projectname java -cp
C:\Workspace\projectname\lib*;C:\Workspace\projectname\bin
org.testng.TestNG testng.xml.
But if i want to do on another machine how to do this?

You can create a bash file which points to your testng.xml file.
Use this:
Bash file is running fine in windows for testng but it is not working in linux/mac
Steps:-
1. Create a notepad file
2. Copy -> java -cp ./src/lib/*:./bin org.testng.TestNG testng.xml(use ; instead of : if you are using windows) (./src/lib/* -> All your jars files must present in this location, ./bin -> all your class files must be present here)
3. save the file.
4. Rename the file as something.bat
5. Double click on file if you are using windows or use **bash filename** if using linux or mac
Note: - Java, require browsers must be present in other computer and it's a prerequisite which is nothing to do with your automation script run. they must be pre-installed

Related

Shell script exporting Hadoop library classpath does not working

I am trying to develop Python client which interacts with Hadoop file system 3.3 using pyarrow package. My OS is CentOS 8 and IDE is Eclipse pydev. The sample code is simple.
from pyarrow import fs
hdfs = fs.HadoopFileSystem('localhost', 9000)
But the prerequisite command has to be executed for the successful python codes running. The command is
# export CLASSPATH=`$HADOOP_HOME/bin/hdfs classpath --glob`
Whenever I run Eclipse IDE, I have to execute the above export CLASSPATH command before Eclipse. To prevent this inconvenience and to automate the IDE configuration, I make the shell script file like below,
#! /bin/bash
export CLASSPATH=$(/usr/local/hadoop/bin/hdfs classpath --glob)
echo $CLASSPATH
When I execute this script, output messages from shell script are correct. But when I execute the Eclipse on the next line, the above pyarrow Python codes do not work successfully. I have no idea of this failure.
When I execute the export CLASSPATH command on the shell itself, the Python codes on Eclipse work correctly. But when I execute shell script, the Eclipse Python codes throws errors.
Update
I enter the [Run Configurations] menu and choose [Environment] tab. I click [Add] and input the below values onto [New Environment Variable] Dialog.
Name : CLASSPATH
Value : $(/usr/local/hadoop/bin/hdfs classpath --glob)
But my configuration is not correct, the same errors are still brought again.
I attach the image of my IDE configuration.
As mentioned in comments, in eclipe's "Run Configurations" menu, you need to add en environment variable entry for called CLASSPATH.
The value must be whatever the shell returns when you run this command:
/usr/local/hadoop/bin/hdfs classpath --glob
Don't try to put $(/usr/local/hadoop/bin/hdfs classpath --glob), it will be interpreted as a string an won't work.

Running an eclipse created jar file

I have created a jar file in eclipse and now I want to execute the jar file in command prompt.
How can I do that?
When your creating jar file using eclipse
While reaching JAR manifest specification
enter main class
Run this command from command prompt:
java -jar <JarName>.jar
Note: you will need to jar a file called META-INF/MANIFEST.MF in order to run the jar after compilation.
If you are creating the jar using Eclipse do this:
Go to file > Export > Java > Jar file (hit next)
Select your project and all the files you would like to jar
Type below the destination of the jar (e.g. c:\MyJar.jar) (hit next x2)
On the bottom Main class either hit browse and choose the class which contains main or type: package_name.class_name (wihch contains the main entry point)
Hit Finish
Go to the jar location in command prompt and run as i mentioned above

Creating jar executable w/ external jar (JXL) in ECLIPSE java

I can't find a working solution for my jar executable. The program runs perfect in my Eclipse IDE, but when I attempt to follow Eclipse instructions, the executable does not work with external JAR.
The JXL jar is in my build path. Anyone know how to get this working through Eclipse? I do not have access to command line.
1.) Right-click on project, select pop-up menu entry "Export...".
2.) Select "Java -> Runnable JAR file".
3.) Choose a working launch configuration for running your program via java -jar MyExecutable.jar from the command line later. Select an output folder and file name. Select "Package required libraries into generated JAR".

"jar cvf ui.jar -C bin ." doesn't seem to work for me

While setting up the HSQLDB plugin for eclipse, I've run into issues creating a ui.jar file (via the console command) in my hsqldb.ui directory. When running the command
jar cvf ui.jar -C bin .
I constantly get a message saying "jar" is not recognized as an internal command. The JRE and JDK files are set up properly, at least I assume (as I've been running eclipse for 2 months now). So, I'm at a loss for what to do.
Any bump in the right direction will be appreciated.
The jar executable should be located in the bin directory under your java sdk installation.
You will need to add that bin directory to your system environment PATH variable if you want your shell or console window to find it.

How to run a batch script (.bat file) from eclipse

My Java application is started by running a set of commands that are present in a batch file (.bat file). And I imported this into Eclipse workbench. How do I execute the batch file from Eclipse. Similar to the one in command line, I directly give "path:\myBatchfile.bat". Is there any way I can do directly from Eclipse.
You can call your .bat file using the External Tools feature (in the Run menu).
Example:
Or, you could create an Ant build file, which can call external applications.
This will give you the advantage to call the .bat not only from Eclipse, but other IDE's, or from command line (on any machine).
http://ant.apache.org/manual/Tasks/exec.html
You can also run a batch file (or any other executable file) by opening it with the System Editor. Use Open With -> System Editor.
Associate with text Editor by right-click - Open With
(As of 2017 there is no plugin with special editor )
To run install plugin like https://marketplace.eclipse.org/content/easyshell
You can easy run .sh with Git Bash as well
or https://github.com/culmat/eExplorer