The Artima Developer Community
Sponsored Link

Java Answers Forum
classpath

2 replies on 1 page. Most recent reply: May 3, 2004 4:54 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
rassuls

Posts: 10
Nickname: rassuls
Registered: Mar, 2003

classpath Posted: Apr 30, 2004 11:52 AM
Reply to this message Reply
Advertisement
I have the following class:

package com.testpack;
public class Test1
{
public static void main(String[] args)
{
System.out.println ("Run Test1.main()");
}
}

It is in d:\dir\com\testpack directory, and classpath is:
set classpath=.;d:\dir;
It compiles within d:\dir\com\testpack directory, but when I try to run it I get errors:

Exception in thread "main" java.lang.NoClassDefFoundError: Test1 (wrong name: com/testpack/Test1)
at java.lang.ClassLoader.defineClass0(Native Method)...

Your help is appreciated. Thanks


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: classpath Posted: Apr 30, 2004 12:27 PM
Reply to this message Reply
You're probably trying to run it with "java Test1" instead of "java com.testpack.Test1"

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: classpath Posted: May 3, 2004 4:54 AM
Reply to this message Reply
The problem i your start directory.


You did right.
the class com.testpack.Test1 must be called by

java -cp .\ com.testpack.Test1


BUT:
You can't call it from "d:\dir\com\testpack"

Instead, call it from "d:\dir\".

d:\dir>java -cp .\ com.testpack.Test1
will work


If you want to call it from any directory:
java -cp d:\dir\ com.testpack.Test1
should also work

"set classpath= ..." does not allways work. If I'm not wrong, java 1.4+ does ignore it completely.
Instead you should use the classpath setting from java.exe as shown above.

Flat View: This topic has 2 replies on 1 page
Topic: vowel array compare with name entered Previous Topic   Next Topic Topic: GUI application

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use