Starting selenium server from java in the background - java

I want to make easy-to-use selenium tests - just run one file and it starts the server, connects to it, run the tests, then close the server and exit (on windows).
I don't want the user to see the selenium console so I want to hide it if possible (run it in background and maybe log output). How can I start selenium server directly from Java?

Well, it wasn't that hard (at least on windows). I used to start selenium server like this:
java -jar selenium-server-xxx.jar <options>
To start it without console I just use javaw:
javaw -jar selenium-server-xxx.jar <options>

Create a windows .bat file and run the .bat file to start the selenium server. You can also include your test classes and dependencies.
eg:
java -cp ".;.\supportlibraries\junit4.11.jar;.\supportlibraries\poi-3.8-20120326.jar;D:\downloads\Selenium 2.0\selenium-server-standalone-2.45.0.jar" org.junit.runner.JUnitCore [classname]

Related

How Can I Use a Java Application Instead of Desktop?

I want to make a Java Application that will start automatically when I start the computer and will run instead of the desktop, so the desktop-terminal etc will be unreachable for users. The users must use nothing but the application and when they close the application, the computer also must be turned off automatically. How can I do such a thing for a simple Java Application (jar)?
Shortly, for ubuntu you have to:
Remove desktop environment, just look around for some guides, it depends by which desktop you have (GNOME, XFCE, KDE, etc). https://askubuntu.com/a/147870
Add a script in /etc/rc.d and link it in rcS.d https://unix.stackexchange.com/a/83752.The script have to run your application, wait for end and shutdown,
an example could be:
#!/bin/bash
nohup java -jar MyApp.jar &
wait
/sbin/shutdown -r now
Try this in a virtual machine that you can reach in SSH or in some other ways, after you removed desktop environment, you cannot open a terminal.

run Java commands through a Shell script

I'm trying to code a shell script to start/stop torrents using vuze's console UI through SSH:
https://wiki.vuze.com/w/Console_UI
I've downloaded vuze and everything works fine until I type this command:
java -jar Azureus2.jar --ui=console
After that, no command in my script works unless I quit that console.
Any solutions please? And if it's not feasible using shell scripts, any suggestions please?
Thanks.
Basically, the moment you run that command, your java program runs 'in the foreground', which means the rest of your script stops executing until your program exits.
If you want to keep on running the rest of your script while your java program executes you have to run your program in the background. One way to do that is as #Alp suggests:
java -jar Azureus2.jar --ui=console &

How to run Java application on startup of Ubuntu Linux

I have a requirement where I need to develop application that reads TCP/IP Socket. I successfully made the program as Java program with No GUI means as soon as program runs it starts listening to the Socket and gets the response with the help of Netbeans IDE. Now as per my requirement i have to start execution of this program as soon as Linux system Booted.
Actually I am very novice in Java and Linux Platform, so have few doubts..
Is my Socket Program with no GUI is fine to be run as per my requirement.
How can I write script to run jar on Linux Boot up, I got to know. init.d is meant for this.
Ideally you should create a service wrapper for your java application and then make this service run on startup example here.
Use
sudo update-rc.d mytestserv defaults to run your service wrapper on startup on Ubuntu
So two things you'll need to do:
First create a small shell script to start your java program from a terminal. As you have packaged as a jar have a look at this, specifically the JAR Files as Applications section.
This may be sufficient: (although you'll want to use the full path to Java)
#!/bin/bash
java -jar path_to_jar_file
You should be able to run your script and successfully start your program.
Once you've got it starting from a script you can use standard linux tools to start the script. Either putting it in /etc/rc.local, or as you're using Ubuntu, use update-rc.d to start it on boot. See here for a very simple example of using update-rc.d
Hope this helps,
Will

Unable to keep Selenium Server Running after Putty Close

First, install the Selenium Server:
Download a distribution archive of Selenium Server.
Unzip the distribution archive and copy selenium-server-standalone-2.9.0.jar (check the version suffix) to /usr/local/bin, for instance.
Start the Selenium Server server by running java -jar /usr/local/bin/selenium-server-standalone-2.9.0.jar.
I can let it run but when i close my putty, the server shuts down. Is it suppose to be that way? As in, does the code initialize the server when they need? or how do I find a way to keep it running?.
This is normal, when you close putty all your commands will be killed.
To keep your commands running, you need either to :
Create a script that will launch this command
run your command using : nohup java -jar /usr/local/bin/selenium-server-standalone-2.9.0.jar &

running -jar file from php code

I want to run -jar file from my php script, my -jar file run perfectly through commandline but i want to integrate it to my website but it is not working properly and also not provide me any error. my code is below
if (isset($_POST['Export'])) {
exec('java -Xmx1024M -jar C:\UploadTest-1_2.jar http://localhost:8080/packaging/Package C:\book\testbook.pdf –pass park345');
echo 'export button clicked';
}
output is:
export button clicked but -jar not doing needful.
Is Java on the path?
Try the command with "java -version", if you don't get output, Java is not on the PATH defined within the PHP environment.
Is the environment locked down?
When running PHP code, one generally doesn't allow any kind of execution to take place, as people could attempt to hijack the PHP environment to place code on the server which wasn't there. This means that you will have to take into account any type of chroot'ing, acl controls, permissions, selinux, and web server configurations which make it harder to run items without a clear knowledge (that means prior configuration) that the application should be allowed to run.

Categories