[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1058
  • Last Modified:

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

0
angelblade27
Asked:
angelblade27
  • 2
1 Solution
 
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
 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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