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

java classpath problem

Hi

I installed jdk1.6 and I run java in console windows

I have a test.java file under C:\test\test.java

When I enter into C:\test>java test, it can run

However, when I was in other directory
e.g. C:\abc\example>java -classpath C:\test\test.class test

It said noclassdeffounderror.

How should I write it properly?
0
techques
Asked:
techques
  • 4
  • 4
  • 3
  • +1
1 Solution
 
ksivananthCommented:
try

C:\abc\example>java -classpath C:\test\ test
0
 
jazzIIIloveCommented:
Hi there;

Step 1:
cd\

Step2:
cd C:\Program Files\Java\jdk1.6.0_07\bin

Step3:
C:\Program Files\Java\jdk1.6.0_07\bin>javac "c:\test\test.java"

Step 4:
cd\

Step 5:
cd test

Step 6:
java.exe -classpath . test

Best regards...
0
 
techquesAuthor Commented:
The problem is I need to run it in a jsp page

Runtime R = Runtime.getRuntime();      
R.exec("java C:\\test\\test" + id);

How can I apply it to my case?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jazzIIIloveCommented:
Hi there;

Runtime r = Runtime.getRuntime();      
r.exec("cd\");
r.exec("cd 'C:\Program Files\Java\jdk1.6.0_07\bin'");
r.exec("javac 'c:\test\test.java'");
r.exec("cd\");
r.exec("cd test");
r.exec("java.exe -classpath . test" +id); //whatever id it is..

Best regards...
0
 
ksivananthCommented:
>>The problem is I need to run it in a jsp page

check this http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
0
 
techquesAuthor Commented:
r.exec("cd\");

compile error:
it said string literal is not properly closed by a double-quote

if r.exec("cd\\");

java.io.IOException: Cannot run program "cd\": CreateProcess error=2, The system cannot find the file specified
java.lang.ProcessBuilder.start(Unknown Source)
java.lang.Runtime.exec(Unknown Source)
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
      java.lang.ProcessImpl.create(Native Method)
      java.lang.ProcessImpl.<init>(Unknown Source)
      java.lang.ProcessImpl.start(Unknown Source)
      java.lang.ProcessBuilder.start(Unknown Source)
      java.lang.Runtime.exec(Unknown Source)


0
 
jazzIIIloveCommented:
what happens when you use the following:
    Runtime r = Runtime.getRuntime();      
    Process p = null;
    p = r.exec("C:\\Windows\\system32\\cmd.exe");
     
    p = r.exec("cd /");
    System.out.println("hi");
    p = r.exec("cd C:\\Program Files\\Java\\jdk1.6.0_07\\bin");
    p = r.exec("javac c:\\test\\test.java");
    p = r.exec("cd /");
    p = r.exec("cd test");
    p = r.exec("java.exe -classpath . test");

Best regards...
0
 
techquesAuthor Commented:
same error for p = r.exec("cd /");

java.io.IOException: Cannot run program "cd": CreateProcess error=2, The system cannot find the file specified
      java.lang.ProcessBuilder.start(Unknown Source)
      java.lang.Runtime.exec(Unknown Source)
      java.lang.Runtime.exec(Unknown Source)
      java.lang.Runtime.exec(Unknown Source)
0
 
jazzIIIloveCommented:
could you comment the cd / lines and retry?
0
 
objectsCommented:
use:

test.main(null);

I'd suggest putting the class in a package though

0
 
techquesAuthor Commented:
Runtime r = Runtime.getRuntime();      
Process p = null;
p = r.exec("C:\\Windows\\system32\\cmd.exe");

It is hanged. I run it in servlet.
0
 
ksivananthCommented:
>>It is hanged. I run it in servlet.

go through this link http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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