Executing Eclipse Selenium Webdriver Java Code in Command Line? - java

I'm using Windows Server 2003,and I'm building a webpage and I want a particular testcase(a Java code) to execute when I click a button in that webpage(the webpage is in same server). SO first I have to find a way to run this eclipse java codes in command line.
On doing some research I found I need to install Maven or Ant. But I know this is not really required. I'm not sure which way to go. I prefer not using Maven or Ant. Can someone please tell me the steps to execute These tests in Command line. ALso the environment variables to add Because I'm unable to find QTjava.zip file in jre7 /lib/ext/ folder.

Have a look at the javac and java command line options. Heres what I did to run selenium tests without requiring eclipse or maven/ant.
this compiles your class, with the jar file (i put it in the same directory, but ideally you will put the full path in the qoutemarks:
javac -classpath "selenium-server-standalone-2.33.0.jar" Example.java
Then you can run the generated class via:
java -classpath ".;selenium-server-standalone-2.33.0.jar" Example
Hope that helps.

Related

Is there a way to run selenium Java scripts without installing Eclipse?

I built several selenium Java scripts and each class represents a test and I also built nice UI that allows the users to select which test they want to run. All the classes are under the same project/package
I am trying to deploy this UI to end users so that they can run it to select the tests without having to install Eclipse. This will make it so easy for me to deploy it to end users.
Is this double?
You can specify the instruction to run it from command line as follows
java -jar filename.jar
ex:
java -jar program1.jar
the program1 consist of the followings are:
program1.class file
Resource library file such as SeleniumRC Server.jar and Selenium Java client.jar file
This method is applicable for SeleniumRC execution. We can directly create the program1.jar file from eclipse using File->Export.
I haven't tried it. Hope this helps

Running a Java program created in IntelliJ on Windows Command Line

I have seen many people ask this question but none of the answers have solved my problem.
I have written a Java project in Intellij which runs fine in Intellij. I need it to run on the command line however.
Intellij automatically builds the .class files in the following directories which is outlined as follows:
C:\git\myProject\out\production\myProject\main
C:\git\myProject\out\production\myProject\openNlpTools
C:\git\myProject\out\production\myProject\sentimentAnalysisTools
I have three sub directories here. The file with the main method is in the \main folder.
To run the program I thought I used the following:
java main.FileMonitor
When I run this however I get the following error:
Error: Could not find or load main class main.FileMonitor
Does anyone have any tips as to why this isn't running?
Intellij runs the program fine, is there anyway I can see the command IntelliJ uses to run the program?
Thanks!
If you can't file a class it usually means you didn't include it in your class path. Some ways to run in the command line
Copy from IntelliJ
Run the program in InetlliJ.
Copy the first line as this will contain full command line
Edit the command line to remove bits you don't need.
Using Maven/Gradle
Set the Main-Class in the assembly plugin
build the program with assembly:single
this will create a Jar you can run on the command line.

Java - how to run console program in windows

Hi I wrote wordquiz program on Java. Using Eclipse in Unix.
In my linux machine it works fine.
Here is a source code https://github.com/HighlanderGe/Words
So, only basic package is used.
In windows compilation of such code as jar doesn't run. Neither in Mac.
As I guess problem is that in linux it is made to run from console, and console is comething very native for linux, but in Windows and I think in Mac too, cmd should be called, and from there it somehow to run.. but I bet cmd has no idea what is java. So some java console is needed for it?
The problem is not with the Mac or Windows, the problem is that you did not setup your workspace in Eclipse the same way on your different computers.
You can build your program on the command line in all environments in the same way. You just have to know the right steps.
First of all, there's an error in your code on line 25 in WordDatabase. Instead of:
dictionary = new ArrayList<>();
it should be:
dictionary = new ArrayList<String>();
After that, you can build your code like this:
javac -d . *.java
And run it like this:
java wordquizz/Wordquizz
This should work in any system that has Java, you just need to figure out how to setup your workspace in Eclipse the same way on your different computers.
UPDATE
I forked and converted your project to a Maven project:
https://github.com/janosgyerik/StackOverflow-Words
After you clone this to your PC, you can import into Eclipse using the File | Import... menu, and then Existing Maven projects option. It should work on all operating systems.
Maven is a recommended tool for building Java projects and it's a good thing to learn. After you install maven, you can build the project with:
mvn compile
You can package the project into a jar file with:
mvn package
You can run your code with either of these commands:
# needs 'mvn compile' first to generate classes
java -cp target/classes/ wordquizz.Wordquizz
# needs 'mvn package' first to generate the jar
java -cp target/wordquizz-1.0-SNAPSHOT.jar wordquizz.Wordquizz
If you like these improvements, merge from my repo soon. I won't keep it forever, I will delete it at some point.
UPDATE 2
To make a jar executable, you need to add inside a manifest file like this:
Main-Class: wordquizz.Wordquizz
You create the jar file with a command like this:
jar cvfm package.jar manifest.txt wordquizz/*.class
I updated my GitHub repository, so that now if you run mvn package, it will automatically add the right manifest, and the generated jar file will be executable.
If you installed java under windows you have to adjust the Path-variable, so the cmd knows where the java executable is. A good tutorial on how to set this up you can find here:
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
After that you can simple go to the directory your source code is in and use the same commands as under linux to compile and run your application.

How to build/run a java project on linux system using bash?

So I have a java project in intellij right now. I'm trying to get it to run through ssh on a linux system.
I've uploaded the class files, however The project will not run unless I take out all the package declarations and rebuild the project.
Whats the correct way to build/run a java project using bash?
The only way to run a java program is to call the java command-line.
To build it is javac but if you hae uploaded the class files, it means that it is already compiled
make sure you have a entry main method in one of your java file, then use java xxxx -cp yourjarpaths to start your program. You can also use ant or maven to start your project, in bash, you can run "ant xxx" or "maven xxxx" to start the jvm
While you can use the command line to build and run the java programs using javac and java commands, you should consider using Maven or Ant or any other build manager for your project. This will be especially useful when you start having external dependencies in your projects.

Creating build of a Java project

I have a stand alone project in my eclipse.There are few external jar as well.The programme is executing well and giving required result. Now i need it to run from command prompt.and i just want to run the class file generated by eclipse. how i will be able to run it.When i am tring to run it from commend prompt it is giving class not found exception.I also tried to make an executable jar,but that is also not running.do i need to create executable jar or i can simply run it from command prompt..tell me the way out..
thanks
koushik
A step by step guide at
I recommend you to go through jar, class path and other basic building blocks of java for eg check this about jar
try using this command java -cp . package.name.className

Categories

Resources