How to Run TestNG using Linux Shell file - java

I am using following working command for Windows batch file.
set projectLocation=E:\APPIUM\CXMFunctionalTest\LinuxAPITest
cd %projectLocation%
set classpath=%projectLocation%\bin;%projectLocation%\lib\*
java org.testng.TestNG %projectLocation%\testng.xml
pause
How i can convert this into Linux Shell Script? So i can run it in Linux machine.

cd /home/[[youruser]]/APPIUM;
java org.testng.TestNG /home/[[youruser]]/APPIUM/testng.xml;
This should be sufficient, considering that [[youruser]] is your users home folder, and the APPIUM folder is placed directly inside it. Then you can put this in a file called runappium.sh, and run it with the command sh appium.sh or mark it executable and run it directly.

Related

My java program runs in netbeans, but will not run in command or through the jar file. What am I doing wrong?

So, I am trying to run a program from jar files. It uses javaswing and has a gui.
The program runs fine in netbeans and in eclipse.
When I try to run it from the exported jar file it says this:
Unable To Install Java
There are errors in the following switches:
"C:\Users\CNC Department\Desktop\ValveConversion.jar";.
Check that the commands are valid and try again.[java installation not complete
Now, I also tried doing it from the command prompt. Here is what came up:
[cmd prompt attempt][1] [1]: https://i.stack.imgur.com/7reZ3.png
So, I reinstalled the java JDK, java SDK, netbeans and eclipse. The issue is still occurring in both command prompt and from running the jar file directly.
What am I doing incorrectly here? What do you recommend that I do to get this to run from a .jar file?
You need to set the java path
Open a cmd with elevated privileges and run this command to set the JAVA_HOME environment variable using setx command:
setx JAVA_HOME -m "C:\Program Files\Java\jdk-11.0.2"
Then restart the cmd and run java -version to check if it's all ok.
For reference setx command documentation
Or simply use the following snippet if you prefer to use java without setting the PATH variable:
"C:\Program Files\Java\jdk-11.0.2\bin\java" -jar "C:\Users\CNC Department\Desktop\ValveConversion.jar"

Error starting selenium grid hub via powershell - VSTS/TFS

I'm struggling to start selenium grid on an azure VM via a powershell script in my build due to the following error....
System.Management.Automation.RuntimeException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Error: Unable to access jarfile selenium-server-standalone-3.4.0.jar
The script simply contains java -jar selenium-server-standalone-3.4.0.jar -role hub and it runs fine locally. Java is installed on the VM.
Does anyone know what the issue is?
Thanks,
According to the script you provide, I suspect that you put the powershell script file in the same folder with "selenium-server-standalone-3.4.0.jar" so you didn't need to specify the path to jar file in the script. However, you need to use absolute path for "selenium-server-standalone-3.4.0.jar" file when you run the script from remote since the working folder is changed. Add the absolute path to the file or add "Set-Location" command in the script file to set the folder to the path where the jar file placed and then try again.
By the way, if you just call the "java -jar selenium-server-standalone-3.4.0.jar -role hub" command from the powershell script, you will keep waiting on the Remote PowerShell script step since the powershell script cannot be finished as the selenium server keeps running. I'd recommend you to start another process to run the selenium server like following:
Set-Location JarFileFolderPath
Start-Job -ScriptBlock {cmd /c start java -jar selenium-server-standalone-3.4.0.jar -role hub}
And make sure that stop the job after all your test is finished.

How to launch a jar file on windows startup from the registry?

I am trying to launch a jar file on Windows Server 2008 R2 startup.
I tried to add a key\value to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
I tried as a value several alternatives:
java -jar c:\jcm\jcm.jar
"java -jar c:\jcm\jcm.jar"
c:\program files(x86)\java\jre1.8.31\bin\java.exe -jar c:\jcm\jcm.jar
"c:\program files(x86)\java\jre1.8.31\bin\java.exe -jar c:\jcm\jcm.jar"
"c:\program files(x86)\java\jre1.8.31\bin\java.exe" -jar c:\jcm\jcm.jar
But none of them launched the program.
Can you advise please?
EDIT: Fixed exe to jar of course
You probably have a problem in the command line. I think it should be something like that last row that you have used but with jar and not exe.
"c:\program files(x86)\java\jre1.8.31\bin\java.exe" -jar c:\jcm\jcm.jar
You just need to test it in command line first and if it works it will work in the registry. You can also make a .bat file to start the java program and copy that to windows Startup Folder instead of using the registry.
The startup folder you can find here:
http://windows.microsoft.com/en-us/windows/run-program-automatically-windows-starts#1TC=windows-7
If it is Windows 10 then you may try this way-
Create a batch file e.g. (my-batch.bat with below statements.)
#echo off
title my-app batch script!
echo my-app welcomes you!
:: If your JAR contains GUI then use-
start javaw -Xmx200m -jar D:\Softwares\JAR\my-app-v1.0.jar
:: Otherwise use-
start java -jar D:\Softwares\JAR\my-app-v1.0.jar
Copy this my-batch.bat file at
C:\Users\pc\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Restart your PC to execute your JAR on startup.
Now, You may check your running JAR using Command Prompt with below commands-
1. jps -l
Output will look like-
8120 sun.tools.jps.Jps
13276 D:\Softwares\JAR\my-app-v1.0.jar
2. tasklist /V

Run java class from single command using makefile

I have a homework assignment in Java that is tested using the commands:
make
./<program_name> <arguments>
my make file compiles my java program successfully, but how can the program be run without using the command:
java <program_name>
I have investigated how to convert a .jar into an .exe but I am convinced that is not the answer I am looking for.
I believe the test is run on a Linux machine. Is there something I can include in the make file to cause the command
./<program_name>
to run a compiled java class?
Without converting the java program in a native executable file, that will be different for linux, for windows and any other platform (so you will loose Java portability), the only thing you can do is to create a launch script.
On *nix system you can create a bash script and on windows a batch script. Then in this script you have to call java <program_name>.
With the script you are now able to launch your application with a single command.
For example on unix you can create myapp.sh:
#!/bin/bash
java -classpath bin com.test.YourApp $*
and make this script runnable with command
chmod a+x myapp.sh
in this example when you write myapp.sh command you launch your Java class com.test.YourApp using the folder bin as classpath.

how to run shell script in java using Cygwin

From a long time i am struggling for with this program. I am having a shell script which accepts parameters as version number and path for the files. then that script creates Zip file with the name of version number congaing all file files to the folder.
I have installed Cygwin on following path D:/cygwin. I am coping required files to same location where cygwin is installed D:\cygwin\bin
Command
D:/cygwin/bin/bash -c '/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files
Or Can any one please suggest how to run shell script in java using Cygwin.
Rewriting the Problem:-
When i am trying to run following Command in command prompt it gives error
sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
Error:-C:\Documents and Settings\sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
/usr/bin/app.sh: line 51: lib/lib.sh: No such file or directory
But if i run the same command at
D:cygwin\bin\Test>sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
It works fine. Can any one suggest me how to avoid this kind of errors.
Runtime run = Runtime.getRuntime();
Process p = run.exec("D:/cygwin/bin/bash -c \'/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files");
p.waitFor();

Categories