• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

All web apps were working fine yesterday until I removed JDK7

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I went through all the example of Head First Servlets and JSP and they worked fine. Once I got to the final example on page 89 I ran into problems. The error on catalina log was:

Unsupported major.minor version 51.0 (unable to load class com.example.web.BeerSelect)

1) So I deleted the JDK 1.7 and JRE and installed JDK1.6 and JRE.
2) I changed the environment variable so future compilations are done with JDK1.6
3) In catalina.bat I changed JRE_HOME address to point to JDK 1.6.
4) I recompiled ALL project java files and servlets with JDK 1.6

Now, nothing works. I get the 404 error. Most confusingly, the catalina log file doesn't mention any errors!
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uninstalling JDK 7 was probably the wrong thing to do. You would get that error message if you compiled code with Java 7, but then tried to run it using Java 6. So it would appear you had both Java 6 and Java 7 installed, and should have uninstalled Java 6, not Java 7.
 
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really shouldn't alter the catalina.bat file. Instead you should set the environment variable before starting Tomcat. Either in the batch file that calls catalina.bat (or startup.bat/shutdown.bat) or in a local or system environment setting from the Windows Control Panel.

Also, it's better to set JAVA_HOME to point to the JDK and not set JRE_HOME.

Also, what version of Tomcat are you trying to run under?
 
Syed Islam
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I forgot to mention that I am using Tomcat 6.

Uninstalling JDK 7 was probably the wrong thing to do. You would get that error message if you compiled code with Java 7, but then tried to run it using Java 6. So it would appear you had both Java 6 and Java 7 installed, and should have uninstalled Java 6, not Java 7.


Don't forget that after uninstalling Java 7 I recompiled everything with Java 6. I thought this is why I am having the first set of problems... because Java 7 doesn't work with Tomcat 6

You really shouldn't alter the catalina.bat file. Instead you should set the environment variable before starting Tomcat. Either in the batch file that calls catalina.bat (or startup.bat/shutdown.bat) or in a local or system environment setting from the Windows Control Panel.

Also, it's better to set JAVA_HOME to point to the JDK and not set JRE_HOME.

Also, what version of Tomcat are you trying to run under?


I modified the catalina.bat file because this is what was instructed in Murach Java Servlets and JSP. I didn't know otherwise.

I also added it as a windows environment variable ---------> C:\Program Files\Java\jdk1.6.0_45\bin

I am using Tomcat 6. I thought it would be easier to configure because I am working from books that use tomcat 6. But I wasted a whooole day with this nonsense so I might just install Tomcat 7 and Java 7 and recompile all the source code.




 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason you shouldn't modify the catalina.bat file is that since it's a complex vendor-supplied script, any changes you make to it are likely to get lost or damaged when the system is maintained. Most of the things you'd want to allow for in catalina.bat can be put in a "setenv.bat" file. Catalina.bat will invoke setenv.bat (or for Unix/Linux, setenv.sh), if it finds one.

WARs can be produced using JDK 7 for Tomcat 6, but you do have to set the javac class level option to generate Java 6 compatible classes. Java 7 classes will definitely give you the problems you saw.

JAVA_HOME (and for that matter, JRE_HOME) shouldn't point to the bin directory. They point to the base directory of the entire JDK (the one that contains the bin directory). By aiming JAVA_HOME at the bin directory, you caused Tomcat not to find the JDK, so it searched its PATH environment in an attempt to locate one.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Syed Islam wrote:Don't forget that after uninstalling Java 7 I recompiled everything with Java 6.


The error indicates that this is not true - there was apparently code that were compiled for Java 7. Of course, it could have been some 3rd party library that requires Java 7, but that seems less likely. The stack trace you got might have the information which class was the offending one.
 
Syed Islam
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:

Syed Islam wrote:Don't forget that after uninstalling Java 7 I recompiled everything with Java 6.


The error indicates that this is not true - there was apparently code that were compiled for Java 7. Of course, it could have been some 3rd party library that requires Java 7, but that seems less likely. The stack trace you got might have the information which class was the offending one.


Hey I'm not sure I fully understand this but just to clarify...
1) I got this error when I had Java 7 -> Unsupported major.minor version 51.0 (unable to load class com.example.web.BeerSelect)
2) After removing Java 7 and keeping Java 6. I used Javac on all source files.
3) Now nothing gets deployed on tomcat. I get 404 error when I try to access servlet url but no longer get the major.minor version 51.0 error. In fact, there are no errors in the catalina log.
 
Syed Islam
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:The reason you shouldn't modify the catalina.bat file is that since it's a complex vendor-supplied script, any changes you make to it are likely to get lost or damaged when the system is maintained. Most of the things you'd want to allow for in catalina.bat can be put in a "setenv.bat" file. Catalina.bat will invoke setenv.bat (or for Unix/Linux, setenv.sh), if it finds one.

WARs can be produced using JDK 7 for Tomcat 6, but you do have to set the javac class level option to generate Java 6 compatible classes. Java 7 classes will definitely give you the problems you saw.

JAVA_HOME (and for that matter, JRE_HOME) shouldn't point to the bin directory. They point to the base directory of the entire JDK (the one that contains the bin directory). By aiming JAVA_HOME at the bin directory, you caused Tomcat not to find the JDK, so it searched its PATH environment in an attempt to locate one.


I'm going to try these tips as soon as I sit in front of my PC again
 
Syed Islam
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I'm confusing everybody with my posts.

I also wrote in catalina.bat
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a problem as well, since "Program Files" has a space in it. The parser breaks off at the space and only sees the "C:\Program" part.

You need to quote the JDK_HOME path:


Alternatively, you could use the 8.3 format, which is usually (but not always) going to look like this:

SET JAVA_HOME="C:\PROGRA~1\Java\jdk1.6.0_45"

Quotes are safer.
 
Syed Islam
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:That's a problem as well, since "Program Files" has a space in it. The parser breaks off at the space and only sees the "C:\Program" part.

You need to quote the JDK_HOME path:


When I leave it without quotes... I get this output in cmd when I startup tomcat:

if I left it with quotes I get:


 
Syed Islam
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another weird error I wasn't getting before. By the way, this is when tomcat starts up correctly.

This web.xml file was not giving me errors before...

Now I am getting this error:
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you managed to double up on quotes and neutralize the quoting. The example I gave used the double-quote character, not 2 consecutive single-quote (apostrophe) characters, by the way.

Use encoding = "UTF-8" instead of ISO-8891-1. The ISO encoding is more appropriate for text content and I'm not sure how popular it even is on Windows, which I think prefers CP-1252 or something like that.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I second using UTF-8 wherever you can. Are you sure ISO-8891-1 even exists? A quick search finds nothing to suggest as much.
 
Syed Islam
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works, that UTF thing done the trick.

I find it unusual the way some things work and some things don't work with webapps. I was following another thread the other day where someone suggested 'ISO-8891-1'. Mind you, this thread was a few years old but it actually worked. And now it doesn't work. Horrible, it makes my stomach turn to think I spent a whole day on this.

It looks like you managed to double up on quotes and neutralize the quoting. The example I gave used the double-quote character, not 2 consecutive single-quote (apostrophe) characters, by the way.

Oh I definitely used a double quote character. Out of the 2 below, I wrote the first option.
But it seemed to work without any kind of quotation mark when I successfully deployed it.

Oh yeah thanks everyone. I'm going to try to deploy all the other projects in Head First Servlets and JSP.
 
Oh the stink of it! Smell my tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic