Re: Help with packages getting started




Lew wrote:
code. The tutorials on java.sun.com go into this.
Ok, your going to have to explain things.

BlitzA wrote:
Possibly a step-by-step guide of how to get this working If you have time ? -

I assumed you were asking about my advice:
Use the -classpath (or -cp) option to your compilation and execution of Java code.
The tutorials on java.sun.com go into this.

But from your question
So theres a tutorial that specifically shows you how to make elements work with JDK 6.0 in a small step-by-step guide?

I see that I was mistaken. My advice was to fix the classpath - how to do that step by step is covered by Sun's tutorials.

If so please can you give the link?

http://java.sun.com look around for the links to the tutorials.

As I said, I'm talking about tutorials with respect to setting the classpath for Java, which is where your problem lies.

In a nutshell, you have to tell Java where the class is that you're trying to run, and as I pointed out earlier, that should most definitely not be in the Java installation directory tree, most especially particularly not in its bin/ subdirectory.

Knute Johnson wrote:
I don't know where the tutorial is either but you can look here for some more information on CLASSPATH;

www.knutejohnson.com/classpath.html

CLASSPATH is one of the trickiest pieces of programming with Java.

There are some important tips to remember;

1) You don't want to set the CLASSPATH environment variable except in
a few rare circumstances

Important point, to be sure.

2) The CLASSPATH has to include all the bits you want to compile or run

Lower-case classpath does, too. More precisely, it has to include all the parent directories and JARs of the bits you want.

3) If you use the -jar option on the command line to run a program
the -classpath or -cp command line options are ignored.

Also the CLASSPATH envar is ignored then.

2 is probably where your problem lies. I don't see a . in the CLASSPATH so how is the runtime going to find your class?

Lower-case. If there is no CLASSPATH envar and you don't specify a -classpath option, Java assumes "." as the classpath.

Sun's tools docs contain the page
<http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html>
that gives excruciating detail.

So for the OP, this means picking a project directory, say, C:/projects, and building your stuff in a subdirectory there.

For project "example" with the source in a tree rooted at subdirectory src/, and classes going into a tree rooted at build/classes/:

cd /projects/example/src
javac -d ../build/classes com/lewscanon/example/App.java
cd ../build/classes
java com.lewscanon.example.App

If you don't cd to the build/classes subdir, you can use -classpath to run the program:

cd /anywhere/you/like
java -classpath /projects/example/build/classes com.lewscanon.example.App

If I needed a JAR to pull in a library, like /projects/libs/foo.jar, then it'd look like this:

java -classpath /projects/example/build/classes:/projects/libs/foo.jar \
com.lewscanon.example.App

The colon (:) would be a semicolon (;) in Windows environments.

Once all that is straight that original error should melt away.

--
Lew
.



Relevant Pages

  • RE: NoClassDefFoundError after upgrade to FC3
    ... it's a lot harder to figure out what is missing. ... Check the script that starts the IDE and see if it is setting a classpath. ... Sometimes the CP is set using a command line option of the java command ... NoClassDefFoundError after upgrade to FC3 ...
    (Fedora)
  • Re: Question for Java Gurus
    ... > people running into classpath issues while doing command line work. ... in which case it's clear that their environment is impeding their ... success at learning Java. ... programming, that's a negligible space of education. ...
    (comp.lang.java.programmer)
  • Re: Question for Java Gurus
    ... > people running into classpath issues while doing command line work. ... in which case it's clear that their environment is impeding their ... success at learning Java. ... programming, that's a negligible space of education. ...
    (comp.lang.java.help)
  • Re: Question for Java Gurus
    ... > people running into classpath issues while doing command line work. ... in which case it's clear that their environment is impeding their ... success at learning Java. ... programming, that's a negligible space of education. ...
    (comp.lang.java.softwaretools)
  • Re: Java server wont run after reboot
    ... > package definitions in your source code. ... Execute from that directory, no classpath definition needed. ... > java HelloWorld ... > If you compile to a different location, ...
    (RedHat)