• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

do not understand compiling a servlet

 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I use the book SCWCD from David Bridgewater. I did ex0102.

URL http://localhost:8080/ex0102/weather.html

Everthing works fine. I just deployed the example.

After I tried to change the servlet:


I saved it on my desktop. I compiled it. I got a the class file, it is saved on my desktop. Then I replaced the old class filed with the new class file. No the application does not work anymore.

I get the message: HTTP Status 503

What is wrong?



[BSouther: Added UBB CODE tags]
[ January 20, 2008: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you restart the application?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Urs Waefler:

No the application does not work anymore.
I get the message: HTTP Status 503
What is wrong?


This doesn't give us much to work with.
Have you looked at the server's logs to see what, exactly is going wrong?
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one general question.

Is it possible to compile a .java file, then copy and paste the .class file?

I mean, I compiled it on my desktop. Then I copied and pasted the .class file.
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I found this in the log file:

SCHWERWIEGEND: Error deploying web application directory ex0102
java.lang.UnsupportedClassVersionError: Bad version number in .class file

What is the meanig of this?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Urs Waefler:
There is one general question.

Is it possible to compile a .java file, then copy and paste the .class file?

I mean, I compiled it on my desktop. Then I copied and pasted the .class file.


Yes, a class file is just a file.
Note, depending on your container and how it is configured, you may need to restart the application or container before the new version of your class will be loaded.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Urs Waefler:
And I found this in the log file:

SCHWERWIEGEND: Error deploying web application directory ex0102
java.lang.UnsupportedClassVersionError: Bad version number in .class file

What is the meanig of this?


This is the error you will see when you try to load a class file into a JVM that is older than the version of javac used to compile it.
For example, if you compile your class with the javac program that came with jdk1.6 but are running your container with the JVM that came with jdk1.5 you will see this error.

To fix, you can either re-compile your class with the same version that you are using to run your container, upgrade the version of Java that you are using to run your container, or use the "-source" switch when compiling to let the JVM know that this class (even though compiled with a newer compiler) doesn't contain any features that are not compatible with the version under which you are trying to run it.
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, that was the mistake. I used version 6 to compile it, but in Apache Tomcat there was version 5. I changed the version in Apache Tomcat to 6, now it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic