• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

Getting Stated with Java

I am getting-stated with Java because I want to use Selenium 2 in Java.
I have an experience with Elipse IDE for PHP and for JavaScript.
I oped a new Java Project.
and the src folder I added anew Java File and copied the GettingStated Selenium file to is (as my first Java application).
Now I want to run it.
I added the file as the main class to the "Run Configuration"  and Run it (Apply).
I received and error:  Could not find the main class: src/GettingStated.js.  Program will exit.
 The Run-Configuration
  • 3
  • 3
2 Solutions
Your java program should be in the file with the extension .java.
Does Eclipse create it with extension .js ? Then you probably have wrong perspective or something.
You can check in the file system - all Java source files should have extension .java

The syntax of the main method is very strict - it should be

public static void main(Strimg [] args){
//body of the method here

Does your main method conform to that?
Jim CakalicSenior Developer/ArchitectCommented:
First, is GettingStarted a java file or a javascript file? If it is a java file then it should have the extension .java. Second, you don't "run" a .java file. The .java file is the source text. It needs to be compiled (which may happen automatically for you when you change the extension to .java). The compiler generates another file of the same name with a .class extension. It is the .class file that you execute (but without using the .class extension).

Perhaps one of these tutorials will help you get started with Java in Eclipse:

Jim Cakalic
VapiSoftAuthor Commented:
The second link is very helpful.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

VapiSoftAuthor Commented:
I am sorry, but after I followed the examples, I still cannot compile/run the Selenuim 'Getting Started' that I downloaded.
It comes with two jar files:
and a lib folder with many jar files.
I imported the jar files (from another folder to my folder)
But when I tried to add it to my space, I get a lot of X (almost every line) - see the attached picture
package org.openqa.selenium.example;

	import org.openqa.selenium.By;
	import org.openqa.selenium.WebDriver;
	import org.openqa.selenium.WebElement;
	import org.openqa.selenium.firefox.FirefoxDriver;

	public class MyFirstClass {
	    public static void main(String[] args) {
	        // Create a new instance of the Firefox driver
	        // Notice that the remainder of the code relies on the interface, 
	        // not the implementation.
	        WebDriver driver = new FirefoxDriver();

	        // And now use this to visit Google

	        // Find the text input element by its name
	        WebElement element = driver.findElement(By.name("q"));

	        // Enter something to search for

	        // Now submit the form. WebDriver will find the form for us from the element

	        // Check the title of the page
	        System.out.println("Page title is: " + driver.getTitle());
	        //Close the browser

Open in new window

Jim CakalicSenior Developer/ArchitectCommented:
You need to add all the jars to your classpath. Classpath is kind of like the Windows PATH variable to Java -- it defines the locations and jar files where other classes needed by your class can be found.

I'm working from memory at the moment but I think you need to right click on the project, select Properties, find Build Path in the project properties tree (maybe under Java?) and then there should be a tab where you can add the jars to your classpath.
Jim CakalicSenior Developer/ArchitectCommented:
VapiSoftAuthor Commented:
Thanks jim,

I added all the jars to the java build path (see picture), but I still have the same errors.
 java build path dialog
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now