Setting class path in code

I wrote a java code using eclipse and set the some jar files in the eclipse class path ( first time using java and eclipse) when i run the code via eclipse it works fine however when i go to command ( winxppro) and type java Facebook i get a error. How do i include the libraries in the code iteself?

Here is the code
package Trial;
import com.thoughtworks.selenium.*;

public class Facebook extends SeleneseTestCase {
      public void testSeleniumrc() throws Exception {
            
            selenium = new DefaultSelenium("localhost",4444, "*chrome", "http://www.facebook.com");
             selenium.start();
            selenium.open("/");
            selenium.type("email", "xyz@yahoo.com");
            selenium.type("pass", "xyz");
            selenium.click("doquicklogin");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Applications");
            selenium.waitForPageToLoad("30000");
            selenium.click("//div/div[1]/a/img");
            selenium.waitForPageToLoad("30000");
            selenium.type("q_apps", "Super wall");
            selenium.waitForPageToLoad("30000");
            verifyTrue(selenium.isTextPresent("Super Wall"));
            selenium.click("link=Super Wall");
            selenium.waitForPageToLoad("30000");
            verifyTrue(selenium.isTextPresent("Add Application"));
            selenium.click("link=Logout");
            selenium.waitForPageToLoad("30000");
            selenium.stop();
      }
       public static void main(String[] args) {
              System.out.println("Hello World!"); // Display the string.
              try {Facebook fb=new Facebook();
              fb.testSeleniumrc();
              }
              catch (Exception e){}
          }

}

here is the output:
c:\Trial>java Facebook.java
Exception in thread "main" java.lang.NoClassDefFoundError: Facebook/java

And these are the locations of the jar file
C:\selenium-remote-control-0.9.0\server\selenium-server.jar
C:\selenium-remote-control-0.9.0\server\selenium-server-tests.jar
C:\selenium-remote-control-0.9.0\java\selenium-java-client-driver.jar
C:\selenium-remote-control-0.9.0\java\selenium-java-client-driver-tests.jar

angelblade27Asked:
Who is Participating?
 
objectsCommented:
u can specify the classpath via the CLASSPATH environment variable
and/or u can copy the jars to <jre>/lib/ext and they get found automagically
0
 
objectsCommented:
java -classpath C:\selenium-remote-control-0.9.0\server\selenium-server.jar;C:\selenium-remote-control-0.9.0\server\selenium-server-tests.jar;C:\selenium-remote-control-0.9.0\java\selenium-java-client-driver.jar;C:\selenium-remote-control-0.9.0\java\selenium-java-client-driver-tests.jar;c:\ Trial.Facebook
0
 
angelblade27Author Commented:
is there a way to do it without having to do it during command line. like hard code it somewhere?
0
 
TheMajesticCommented:
u can write a batch file which contains all the path's in it.

batch file is nothing but just open the notepad type this

java -classpath C:\selenium-remote-control-0.9.0\server\selenium-server.jar;C:\selenium-remote-control-0.9.0\server\selenium-server-tests.jar;C:\selenium-remote-control-0.9.0\java\selenium-java-client-driver.jar;C:\selenium-remote-control-0.9.0\java\selenium-java-client-driver-tests.jar;c:\ Trial.Facebook

and save it with .bat extension .

then u can run it when ever u needed .


if u want u can use ant also .

for reference :

ant.apache.org

u can use ant in eclipse also as

www.gvcsitemaker.com/jass4eclipse/ant_builder

I think this will help u a lot .


0
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.

All Courses

From novice to tech pro — start learning today.