Unusable

So far, it appears to me that Java is unusable. This whole classpath silliness makes Java unfathonable.

I have compiled a program called jTidy to a jar file. It compiled with a one error and some warnings concerning depracated functions. I fixed the error and it compiled to "E:\My Documents\Java Central\jTidy\build\Tidy.jar".

So I try to execute it using the command java -cp "E:\My Documents\Java Central\jTidy\build" Tidy.JAR and get the ever present "Exception in thread "main" java.lang.NoClassDefFoundError: Tidy/jar"

Try executing java "E:\My Documents\Java Central\jTidy\build\Tidy.JAR" and I get the same thing.

Can someone PLEASE point me to some clear information which makes this whole classpath thing understandable? I am unable to run anything, even after reading page after page on this issue.

I am using the Java Studio Enterprise v8, and have the latest JRE installed. I'm on WinXP Pro. I can't run anything from within JSE, either. You'd think the JSE would know where to find the program.

I can't get anything to run locally - how am I supposed to deliver a product to a regular user and have it function reliably? I was planning on switching to Java, but it appears to me to be one more good idea poorly implemented. Maybe someone can set me straight.

Thanks.

Signed,

Frustrated and ready to burn my jbooks.

[1394 byte] By [Neeeeeola] at [2007-10-2 20:20:30]
# 1

compiling produces .class files, not .jar files, so have yo compiled or complied and then jarred?

To run something.class, go to the directory with the class file and type

java something (no extension).

Remember CASE is significant.

to run something.jar, again go to the directory with the jar file and type

java -jar somejar.jar (assuming the jar manifest points to the 'main' function in a contained class.

Seems to me like you need to go back to fundamentals, lite the tutorial 'My First Cup of Java'

I've been programming in java for 7 years and rarely if ever had to set a classpath explicitly.

armalcolma at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 2

> So far, it appears to me that Java is unusable. This

> whole classpath silliness makes Java unfathonable.

You can be thankful for every forum member that reads past this intro. Getting frustrated is not the way to solve problems, and showing this frustration is generally not the best way to get help. I'll ignore the rest of negativity in your post.

Stay calm. Follow the documentation exactly. And it will work.

> I have compiled a program called jTidy to a jar file.

> It compiled with a one error and some warnings

> concerning depracated functions. I fixed the error

> and it compiled to "E:\My Documents\Java

> Central\jTidy\build\Tidy.jar".

It actually compiled to a number of .class files. These are put into a jar. Either way, as I understand, you have a jar file but problems executing it.

> So I try to execute it using the command java -cp

> "E:\My Documents\Java Central\jTidy\build" Tidy.JAR

> and get the ever present "Exception in thread "main"

> java.lang.NoClassDefFoundError: Tidy/jar"

>

> Try executing java "E:\My Documents\Java

> Central\jTidy\build\Tidy.JAR" and I get the same

> thing.

Okay. You did *not* follow the documentation, so obviously it does not work.

> Can someone PLEASE point me to some clear information

> which makes this whole classpath thing

> understandable? I am unable to run anything, even

> after reading page after page on this issue.

http://java.sun.com/j2se/1.5.0/docs/tooldocs/index.html#general

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html

I quote from the documentation for java.exe:

java [ options ] -jar file.jar [ argument ... ]

This would lead me to believe that you should try this instead of what you typed above:

java -jar "E:\My Documents\Java Central\jTidy\build\Tidy.JAR"

Lokoa at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 3

> Try executing java "E:\My Documents\Java

> Central\jTidy\build\Tidy.JAR" and I get the same

> thing.

That looks right except that you are capitalizing 'JAR'. Why are you? Sometimes you are and sometimes you are not. Also, I dislike executable jars and would suggest using the main class name explicitly. Lastly, if you are not able to get your first app running, forget about jars for now. Just use a directory structure containing .class files.

dubwaia at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 4

I feel your frustration. Here is an example that might help you with the different steps. You seem to be mixing a couple things together.

here is sample code.

public class HelloWorld {

public HelloWorld () {

//comment: this is the constructor. It is called to create in instance

// of the HelloWorld object

System.out.println ("Hello World") ;

}

public static void main (String[] args) {

//comment: this is instantiating a HelloWorld object from the HelloWorld class

new HelloWorld () ;

}

}

To compile the code from the cmd line:

%> javac HelloWorld.java

This produces a HelloWorld.class file. I could run this file immediately with

%> java HelloWorld

If that does not work, then the java installation is bad. Meaning that the classpath env variable was not set or somehow does not include "." for the current directory. You can check this by by running as follows

%> java -cp . HelloWorld

Now let's run it as a jar. The jar is cool because you zip everything up into a single file to deliver it to your client. To create an executable jar, you have to tell the jar where the "main" class is. The main class is called at start up, so java needs to know where it is. This is done in a file called a manifest. So create a file named "manifest.mf" (the name doesn't matter). In this file put the single line

Main-Class: HelloWorld

Notice that there is NO .class suffix.

Now create the jar with this manifest. Here is the command

%> jar cvfm HelloWorld.jar manifest.mf HelloWorld.class

then to run it

%> java -jar HelloWorld.jar

kris.richardsa at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 5

> So far, it appears to me that Java is unusable.

You're right. It is completely unusable. The whole thing was started as a joke and it just got a little out of hand. The thousands of companies and individuals who have spent millions of hours and billions of dollars building enterprise solutions, desktop apps, libraries, etc. over the past 11 years have just been wanking.

Sun is going to admit to the joke and announce the immediate shutdown and recall of everything Java related at the end of this week's JavaOne conference. Congratulations on figuring it out before that. You win a Duke watch.

jverda at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 6

<canned>

[url=http://wiki.java.net/bin/view/Javapedia/ClassPath]Javapedia: Classpath[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html]How Classes are Found[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html]Setting the class path (Windows)[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html]Setting the class path (Solaris/Linux)[/url]

[url=http://www-106.ibm.com/developerworks/edu/j-dw-javaclass-i.html]Understanding the Java ClassLoader[/url]

java -cp .;<any other directories or jars> YourClassName

You get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

javac -classpath .;<any additional jar files or directories> YourClassName.java

You get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

</canned>

jverda at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 7

Thanks all who responded with helpful information. I am studying the links that were provided, and the very clear instruction on the difference between a jar and class files did more to help than any of the documentation I have run across. I got the Tidy.jar file to run (it didn't produce the results I needed, but it gave me better info on what went wrong than either of the Windows EXEs that I had tried did.) So again, thanks.

For those of you who didn't like my tone and replied as such, I would have thought it was obvious that I simply didn't get it. Java is a widely used language - that's precisely why I want to start writing in it. 'nuf said.

Thanks again.

Neeeeeola at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 8
What about those of us who provided both helpful and sarcastic replies?:-)
jverda at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 9

> java -cp "E:\My Documents\Java Central\jTidy\build" Tidy.JAR

> and

> java "E:\My Documents\Java Central\jTidy\build\Tidy.JAR"

I'm not sure if you have solved your problem yet so I'll throw my 2 cents in the can...

If you want to use the -cp option for java, you have to provide the complete path to your Jar file, including the Jar file name itself. Then you must also provide the package name and class file you want to execute. so it might look something like this:

java -cp "C:\Some long @ss path to my resource jar folder\

JavaJays.jar" javareference.collections.LinkedListDemo

The class is LinkedListDemo located in the javareference.collections Package.

On the other hand... if you want your jar file to be executable so the application will start when you double click the file or use the java -jar syntax, you must have a manifest.mf file inside the jar file that has an entry that specifies the main-class.

This is just like Kris.Richards spoke of in reply 4. However, if you have packeges in your source, then you will have to specify the fully qualified class name for the Main-Class: manifest entry. example: package.subpackage.ClassName

Hope it helps

JJ

Java_Jaya at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...
# 10

> What about those of us who provided both helpful and

> sarcastic replies?

You get a duke watch.

> I would have thought it was obvious that I simply didn't get it.

So? I don't get Perl, I don't post on a perl newsgroup "Perl sucks" when I want help, as common sence tells me thats a daft idea. I post just the problem I am having.

mlka at 2007-7-13 23:02:51 > top of Java-index,Java Essentials,New To Java...