thank's Jon Skeet I have done all that you mentioned to do on your site
http://www.yoda.arachsys.com/java/extensions.html ... but I get the message:
Could not find the main class. Program will exit!
I realise that running the javaw command uncompresses the file and i can do
the same thing using winRAR. Now what I also managed to gather is that the
directory that these classes have to be uncompressed is the
C:\jdk1.3.1\jre\lib\ext directory... Am I right? And the files are supposed
to have a *.class extension once uncompressed! Well I have all of my classes
installed in that folder as mentioned earlier but I still can get my Java
program to find the class in that directory. Are each of these individual
classes supposed to be in a folder of their own? i.e.
C:\jdk1.3.1\jre\lib\ext \TerminalIO\KeyboardReader.class or is it supposed
to be C:\jdk1.3.1\jre\lib\ext\KeyboardReader.class
Any help is greatly appreciated. here's my source code:
import TerminalIO.*;
public class Convert {
KeyboardReader reada = new KeyboardReader();
ScreenWriter writa = new ScreenWriter();
double fahrenheit;
double celsius;
public void run() {
writa.print ("Enter degrees Fahrenheit: ");
fahrenheit = reada.ReadDouble();
celsius = (fahrenheit - 32.0) * 5.0/9.0;
writa.print ("The equivalent in celsius is ");
writa.println (celsius);
reada.pause();
}
public static void main (String [] args) {
Convert tpo = new Convert();
tpo.run();
}
} //close class Convert
This is the code that was shown to us at university (the code supposedly
converts Degrees Fahrenheit values into Degrees celsius values). I am trying
to get the KeyboardReader.class and ScreenWriter.class to work.
The error message I get is as follows:
C:\jdk1.3.1\bin>javac Convert.java
Convert.java:11: cannot resolve symbol
symbol : method ReadDouble ()
location: class TerminalIO.KeyboardReader
fahrenheit = reada.ReadDouble();
^
1 error
Have I got it right or am I way off?? Any help is much appreciated.
Now please flame me as per usual Newsgroup policy and if you could please
give me some help on my little problem.
TIA
e-regular
I have looked at a lot of messages posted in Forums regarding this error but
I still can't sort out what I am doing wrong. Keeping in mind that I also
have described the correct CLASSPATH in my Windows System Variables... I am
totally lost and confused.
"e-regular" <***el_papich...@hotmail.com***> wrote in message
news:a67v6p$2si$1...@bunyip.cc.uq.edu.au...
No, running javaw *doesn't* uncompress the file - at least not to disk.
> Now what I also managed to gather is that the
> directory that these classes have to be uncompressed is the
> C:\jdk1.3.1\jre\lib\ext directory... Am I right?
The jar file shouldn't be uncompressed at all. Leave it as a jar file.
You don't need to have it in the jre/lib/ext directory either - you
should just be able to run
javaw -jar myfile.jar
How have you created the jar file though? Have you got the manifest
appropriately set up with a Main-Class parameter?
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
As I've said many times, you'll almost certainly be better off without a
CLASSPATH environment variable at all. Given that it's not working, you
may well *not* have described it correctly, if you're going to use it at
all.
See http://www.pobox.com/~skeet/java/classpath.html
Jon> How have you created the jar file though? Have you got the
Jon> manifest appropriately set up with a Main-Class parameter?
BTW... I'm trying to create such an "executable" jar file but i've
still not found any example of manifest file in the java doc files,
nor in books as corejava, Java IaN.
To test, i want to jar a sample class, MyBirthday.class, in a jar
file, say signature.jar to be able to run it with :
$ java -jar signature.jar
What i've understood so far is i have to create a manifest file to
specify my main class :
$ cat mymanifest
Manifest-Version: 1.0
Created-By: 1.3.1_01 (Sun Microsystems Inc.)
Main-Class: MyBirthday
Then create the jar file with the -m option :
$ jar -cvmf signature.jar mymanifest MyBirthday.class
But, when i try that, i get the following error:
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:354)
at java.util.jar.Manifest.read(Manifest.java:161)
at java.util.jar.Manifest.<init>(Manifest.java:56)
at sun.tools.jar.Main.run(Main.java:125)
at sun.tools.jar.Main.main(Main.java:904)
As this error gives no clue about what header is wrong, i don't know
what i've missed...
--
Éric Jacoboni, né il y a 1318963495 secondes
Jaco> Then create the jar file with the -m option :
Jaco> $ jar -cvmf signature.jar mymanifest MyBirthday.class
Ok, i've found the problem: the manifest filename should appear
_before_ the jar filename.
Doing:
$ jar -cvmf mymanifest signature.jar MyBirthday.class
Runs ok, but that's not what is written in the jar help screen :
$ jar
[...]
Example 2: use an existing manifest file 'mymanifest' and archive all the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .
Seems confusing, isn't it ?
--
Éric Jacoboni, né il y a 1318964970 secondes
Look up "Jar" in the Java glossary at
http://www.mindprod.com/jgloss.html
> To test, i want to jar a sample class, MyBirthday.class, in a jar
> file, say signature.jar to be able to run it with :
>
> $ java -jar signature.jar
>
> What i've understood so far is i have to create a manifest file to
> specify my main class :
>
> $ cat mymanifest
> Manifest-Version: 1.0
> Created-By: 1.3.1_01 (Sun Microsystems Inc.)
> Main-Class: MyBirthday
You only need the last line of this - the rest are added automatically.
> Then create the jar file with the -m option :
>
> $ jar -cvmf signature.jar mymanifest MyBirthday.class
You've got those the wrong way round - use should have:
jar cvmf mymanifest signature.jar MyBirthday.class
The parameters come in the same order as the flags in the first option.
Not really. You can either use
jar cvfm classes.jar manifest
or
jar cvmf manifest classes.jar
So long as the parameters come in the same order as the flags, all will
be well.
>> Seems confusing, isn't it ?
Jon> Not really. You can either use
Jon> jar cvfm classes.jar manifest
Jon> or
Jon> jar cvmf manifest classes.jar
Jon> So long as the parameters come in the same order as the flags,
Jon> all will be well.
Ooops... i was too tar-centric ;-)
--
Éric Jacoboni, né il y a 1318969858 secondes
Thank's for the insight! I actually downloaded the *.jar files from the net
at this site:
http://turing.cs.wwu.edu/martin/breezygui/legal_stuff.htm ...Ok so I will
leave the *.jar files as they are...And I'll post a follow up to let you
know how it all went.
Tah-tah for now!
1) My classpath in The Windows System variables:
Variable name: CLASSPATH
Value: c:\jdk1.3.1\lib
2) The files located in my C:\jdk1.3.1\lib directory are as follows:
BreezySwing.jar
dt.jar
htmlconverter.jar
src.jar
TerminalIO.jar
tools.jar
3) I have copied the javaw.exe file into that directory and I have run the
command (from the CMD Prompt):
javaw -jar TerminalIO.jar
javaw -jar *.jar (just to make sure that I get it right)
4) I have run the compiler "javac Convert1.java" which has created my class
file
5) When I go to run the class file ie "java Convert1" I get the message:
Exception in thread "main" java.lang.NoClassDefFoundError: Convert1
I get this message everytime. No matter which class I import in my source
code I still get the message.
My files do compile but I can not execute the java byte-code using the java
virtual machine because it
can not find the classes. Well that is my assumption. here are 2 pieces of
code which I am able to compile but unable to execute:
// Fig. 2.6: Welcome4.java
// Printing multiple lines in a dialog box
// Java extension packages
import javax.swing.JOptionPane; // import class JOptionPane
public class Welcome4 {
// main method begins execution of Java application
public static void main ( String args[] )
{
JOptionPane.showMessageDialog(
null, "Hello\nworld" );
System.exit( 0 ); // terminate application
} // end method main
} // end class Welcome4
and the other is:
import TerminalIO.*;
public class Convert1 {
KeyboardReader reader = new KeyboardReader();
ScreenWriter writer = new ScreenWriter();
double fahrenheit;
double celsius;
public void run() {
writer.print ("Enter degrees Fahrenheit: ");
fahrenheit = reader.readDouble();
celsius = (fahrenheit - 32.0) * 5.0/9.0;
writer.print ("The equivalent in celsius is ");
writer.println (celsius);
reader.pause();
}
public static void main (String [] args) {
Convert1 tpo = new Convert1();
tpo.run();
}
} //close class Convert1
What else can I do apart to shoot myself with a bullet? I have searched high
and low. Steps 1 through to 5 are information which I have gathered so far
from various websites, newsgroups, forums and University. Does the java
engine know where to look for the class files because we're telling it in
the Windows Environment System variables?? If this is the case why won't
mine work?
Now please flame me as per standard newsgroup procedure. Oh yeah and any
help is much appreciated.
e-regular...
There are two ways of running a Java application:
1. Direct from class:
- uses CLASSPATH if defined
- requires classes to be accessible through the classpath
- takes a class name as the interpreter parameter
2. Executable JAR image:
- ignores the CLASSPATH entirely
- requires a correct relative or absolute JAR image path
- takes the JAR image name as a parameter, with "-jar" option
- main class must be specified by the manifest in the JAR file
e-regular wrote ...
> I have made all of the following verifications:
>
> 1) My classpath in The Windows System variables:
>
> Variable name: CLASSPATH
> Value: c:\jdk1.3.1\lib
This is a bad idea. You should probably eliminate it.
> 2) The files located in my C:\jdk1.3.1\lib directory are as follows:
> BreezySwing.jar
> dt.jar
> htmlconverter.jar
> src.jar
> TerminalIO.jar
> tools.jar
Note that for a JAR file to be in your CLASSPATH (and this is only
relevant for case #1, remember) you need to specify the file itself.
Thus, if you're depending on Java to be able to find these JAR files,
it's irrelevant for your CLASSPATH variable to contain "c:\jdk1.3.1\lib"
as you say it does. It would need to be:
Value: c:\jdk1.3.1\lib\BreezySwing.jar;c:\jdk1.3.1\lib\dt.jar;... et
cetera
As I said, though, I don't think you really want to do it that way. It
looks like you're trying to use executable JARs, in which case you should
skip the CLASSPATH stuff entirely.
> 3) I have copied the javaw.exe file into that directory and I have run the
> command (from the CMD Prompt):
This is a bad idea, too. Java depends on the integrity of its
installation. You can't just copy executables around and expect them to
keep working. Run the javaw.exe program from its correct location, in
c:\jdk1.3.1\bin
> javaw -jar TerminalIO.jar
This is the correct command, *if* your current working directory is
c:\jdk1.3.1\lib (where you have put the JAR file). Otherwise, you need
to specify a full path:
javaw -jar c:\jdk1.3.1\lib\TerminalIO.jar
or even:
c:\jdk1.3.1\bin\javaw -jar c:\jdk1.3.1\lib\TerminalIO.jar
The latter if you don't have c:\jdk1.3.1\bin in your PATH environment
variable.
I'd recommend, though, that you get your own files (eg, TerminalIO.jar)
out of the Java SDK install directory as soon as you can, and run them
from elsewhere. Consider the Java SDK install dir to be owned by Java.
Leave everything as it is, and create your own directories for your Java
projects and code that you develop.
> javaw -jar *.jar (just to make sure that I get it right)
That's just plain nonsensical.
> 4) I have run the compiler "javac Convert1.java" which has created my class
> file
This late? The class you want to run should be part of the executable
JAR image. Is Convert1.class in the TerminalIO.jar file that you're
trying to run (and listed in the manifest?)
> 5) When I go to run the class file ie "java Convert1" I get the message:
> Exception in thread "main" java.lang.NoClassDefFoundError: Convert1
Now you've stopped using executable JAR files entirely, and reverted to
case 1 from the beginning of my response. For this to work, you need to
have a properly configured CLASSPATH (or, preferably, lack thereof, in
which case it is implicitly set to the current working directory).
Does that make any sense?
Chris Smith
Wrong. Get rid of it altogether. It's not doing any good like that.
> 2) The files located in my C:\jdk1.3.1\lib directory are as follows:
> BreezySwing.jar
> dt.jar
> htmlconverter.jar
> src.jar
> TerminalIO.jar
> tools.jar
Nope. Get rid of all of the ones you put in there (which is probably
just BreezySwing.jar, src.jar and TerminalIO.jar). Your jar files don't
belong there.
> 3) I have copied the javaw.exe file into that directory and I have run the
> command (from the CMD Prompt):
> javaw -jar TerminalIO.jar
That has a chance of working.
> javaw -jar *.jar (just to make sure that I get it right)
That's almost certainly not going to work. (If you did it from a Unix
shell you might get lucky, but it's not the right way to do it.)
javaw -jar
takes a single jar file as the next parameter - that jar file is the one
which says which class is the main one and which other jar files and
classpath entries are needed.
> 4) I have run the compiler "javac Convert1.java" which has created my class
> file
>
> 5) When I go to run the class file ie "java Convert1" I get the message:
> Exception in thread "main" java.lang.NoClassDefFoundError: Convert1
That would be because you've got your classpath mucked up. Please read
http://www.pobox.com/~skeet/java/classpath.html
> I get this message everytime. No matter which class I import in my source
> code I still get the message.
Yup, I'm not surprised. You've told the JVM (using the classpath
environment variable) to just look in jdk1.3.1\lib for class files - and
not even within the jar files in there.
> Now please flame me as per standard newsgroup procedure. Oh yeah and any
> help is much appreciated.
Has anyone flamed you yet? I haven't seen it.
I would have to be the happiest Java newbie on the face of this earth right
now!! Thank'ts all for the input. It has really helped me to get this out.
All I finally did was delete the CLASSPATH from my Windows Sytsem Variables
and presto, it's all working like it is Supposed to!! I have no idea why in
some instances people are saying that I should properly configure the
CLASSPATH variable and in other instances some say that you may not really
require this variable?
Anyway I deleted it and it's working, so once again thank's all for your
time and effort with my questions.
e-regular.
PS. but I probably will be back in months to come!
>java.lang.NoClassDefFoundError:
see http://mindprod.com/errormessages.html
This is a beast of a an error message. I have written tons about it.
The java glossary is at
http://www.mindprod.com/gloss.html
or http://209.139.205.39
--
eagerly seeking telecommuting programming work.
canadian mind products, roedy green
>BTW... I'm trying to create such an "executable" jar file but i've
>still not found any example of manifest file in the java doc files,
>nor in books as corejava, Java IaN.
see "jar" in the Java glossary.