Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Classpath woes

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
GB
Hi all :((

I have a classpath problem after changing computers, and the workaround must be ok on future changes too (pc & mac, without admin rights).

/desktop/a/b/*.class
/desktop/c/*.class
/desktop/d/*.class
/desktop/e/f/main.class

Tried javac from root: javac /e/f/main.class (cannot find /c/*.class)

PC accepted the following, but it isn't working on current Mac.

/desktop/a/b/*.class
/desktop/c/*.class
/desktop/d/*.class
/desktop/main.class

I'm in trouble if this isn't fixed pronto!

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
I forgot to say that each computer they stick me with has different classpath settings. This is something that just has to be accepted and worked with.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
javac is for compiling, not for executing.

Appart from that, which is your actual classpath?

Cheers,
Dian
 
I do not know how to answer your question. Is the answer written somewhere in the system?

The following is now working on the Mac

/desktop/a/b/*.class
/desktop/c/*.class
/desktop/d/*.class
/desktop/main.class

Meaning, I type this in the console:
cd desktop
javac main.java (finds all required packages)
java main (whoohoo!!)

However, this is not ideal because a collection of 'mains' will be used for a technical demonstration and having them all on the desktop would be messy. That's why I wanted the individual apps in /desktop/e/f/main.class where /f/ is unique.

So what I think I'd like is to compile in desktop/e/f/ using packages found in desktop/ and this works, but it won't execute (which I think is what you're referring to)

Do I need to define the classpath when executing, and how would I do that? Thank you!! :)

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Oh, I was looking for this thread :$

I have tried with -cp and just posted in another thread (sorry). It compiles (javac) and does not run (java).

The quoted lines show the relationship between my files.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
I thought jar files were for packaging a working application, not for fixing one that won't run?

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
I just tried with -classpath a:a/b:a/d etc.

javac -classpath worked, and java -classpath failed (wrong name) [sadeyes]

I'm sure javac worked because there were no errors and the class files were updated.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Still no change. Compiling appears to work and executing does not (using identical args). MoreFeo, I tried that too - it gives the same result.

Recap:

javac is creating files
java is giving me "NoClassDefFoundError" (wrong name)


--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
From sun..

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
 
Oooo... well this works for the javac/java

// javac DIR/littledir/app.java -classpath DIR -d DIR/littledir
// java -classpath DIR:DIR/littledir app

However, using this, app expects to find all its data files in root/ instead of root/DIR/littledir *i hate compooters*

So back with the Java language, can I query the current working directory in my code?

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Not always, I think he's looking for something like

Code:
File f = new File(".");
System.out.println(f.getAbsolutePath());



Cheers,
Dian
 
Don't know if you still have the problem, but how are you executing java?

It should be "javac -classpath . a/b/c/*.class" and then "java -cp . a.b.c.Main" or "java -classpath . a.b.c.Main" (no more slashes, replace them with dots)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top