aspose file tools*
The moose likes Servlets and the fly likes do not understand compiling a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "do not understand compiling a servlet" Watch "do not understand compiling a servlet" New topic
Author

do not understand compiling a servlet

Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
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 ]

SCJP 1.4
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

Did you restart the application?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
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

Joined: Mar 13, 2007
Posts: 77
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Mar 13, 2007
Posts: 77
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.
 
wood burning stoves
 
subject: do not understand compiling a servlet