Setting class path in code

Posted on 2007-10-09
Last Modified: 2008-01-09
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", "");
            selenium.type("email", "");
            selenium.type("pass", "xyz");
            selenium.type("q_apps", "Super wall");
            verifyTrue(selenium.isTextPresent("Super Wall"));
  "link=Super Wall");
            verifyTrue(selenium.isTextPresent("Add Application"));
       public static void main(String[] args) {
              System.out.println("Hello World!"); // Display the string.
              try {Facebook fb=new Facebook();
              catch (Exception e){}


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

And these are the locations of the jar file

Question by:angelblade27
    LVL 92

    Expert Comment

    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

    Author Comment

    is there a way to do it without having to do it during command line. like hard code it somewhere?
    LVL 92

    Accepted Solution

    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
    LVL 4

    Expert Comment

    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 :

    u can use ant in eclipse also as

    I think this will help u a lot .


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now