Navigation Bar

Sunday, October 25, 2009

Java web application: Migrating to a later version

 Old Java Version : 6u16

New Java Version : 21.0.9

Old Tomcat Server Version : Tomcat 6.0.0

New Tomcat Server Version : Tomcat 11.0.13

E:\install\tomcat\tomcat11013\webapps\httpreqresp>java -version
java version "21.0.9" 2025-10-21 LTS
Java(TM) SE Runtime Environment (build 21.0.9+7-LTS-338)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.9+7-LTS-338, mixed mode, sharing)

Uninstall the existing Java setup
In Control Panel - > Programs -> Programs and Features : Find the Java program like Java (TM)... and right click on it to uninstall. Go to the physical installation directory and delete any residual files of earlier installation.

Once this is completed, install the newer version of Java as per the link below.  
Java and Tomcat Installation Steps

With Java 21.0.9 and Tomcat 11.0.13 web server setup done and verified, we build and test our initial Servlet application.
Using Servlets to retrieve HTTP data from browser 

Copy the httpreqresp folder from <CATALINA_HOME>/webapps folder deployed on the Tomcat 6 web server version to <CATALINA_HOME>/webapps on the Tomcat 11013 version.

Make changes to the environment variables for PATH, JAVA_HOME, CLASSPATH to point to the new paths

set CLASSPATH=E:\install\tomcat\tomcat11013\lib\servlet-api.jar;
set ANT_HOME=E:\install\ant\apache-ant-1.7.1-bin\apache-ant-1.7.1
set JAVA_HOME=E:\install\java
set PATH=E:\install\21cXE\dbhomeXE\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\PuTTY\;E:\install\java\bin;C:\Program Files (x86)\MySQL\MySQL Server 6.0\bin;C:\Users\winni\AppData\Local\Microsoft\WindowsApps;E:\install\ant\apache-ant-1.7.1-bin\apache-ant-1.7.1\bin
Make changes to the ANT build.xml to point to the new src and destination on the new CATALINA_HOME/webapps path
<pre class="language-java"><code><project name="httpreqresp" default="compile-single" basedir=".">

<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/WEB-INF/classes"/>


   <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="init">
        <mkdir dir="${build.dir}"/>
    </target>

<echo message="111111..."/>	
<target name="compile-single">
    <echo message="Compiling LoginForm.java..."/>
    <javac srcdir="${src.dir}" destdir="${build.dir}">
	<include name="httpreqresp/ParameterServlet.java"/>
	</javac>
</target>

</project></code></pre>
Run the set_path.txt script on the cmd prompt
E:\install\tomcat\tomcat11013\webapps\httpreqresp>set_path

E:\install\tomcat\tomcat11013\webapps\httpreqresp>set CLASSPATH=E:\install\tomcat\tomcat11013\lib\servlet-api.jar;

E:\install\tomcat\tomcat11013\webapps\httpreqresp>set ANT_HOME=E:\install\ant\apache-ant-1.7.1-bin\apache-ant-1.7.1

E:\install\tomcat\tomcat11013\webapps\httpreqresp>set JAVA_HOME=E:\install\java

E:\install\tomcat\tomcat11013\webapps\httpreqresp>set PATH=E:\install\21cXE\dbhomeXE\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\PuTTY\;E:\install\java\bin;C:\Program Files (x86)\MySQL\MySQL Server 6.0\bin;C:\Users\winni\AppData\Local\Microsoft\WindowsApps;E:\install\ant\apache-ant-1.7.1-bin\apache-ant-1.7.1\bin
Run the ant command for compiling the ParameterServlet.java java class. You will get the below error
E:\install\tomcat\tomcat11013\webapps\httpreqresp>ant
Buildfile: build.xml
     [echo] 111111...

compile-single:
     [echo] Compiling ParameterServlet.java...

BUILD SUCCESSFUL
Total time: 0 seconds
E:\install\tomcat\tomcat11013\webapps\httpreqresp>ant
Buildfile: build.xml
     [echo] 111111...

compile-single:
     [echo] Compiling ParameterServlet.java...
    [javac] Compiling 1 source file to E:\install\tomcat\tomcat11013\webapps\httpreqresp\WEB-INF\classes
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:7: error: cannot find symbol
    [javac] public class ParameterServlet extends HttpServlet {
    [javac]                                       ^
    [javac]   symbol: class HttpServlet
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:8: error: cannot find symbol
    [javac]     public void doGet(HttpServletRequest request, HttpServletResponse response)
    [javac]                       ^
    [javac]   symbol:   class HttpServletRequest
    [javac]   location: class ParameterServlet
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:8: error: cannot find symbol
    [javac]     public void doGet(HttpServletRequest request, HttpServletResponse response)
    [javac]                                                   ^
    [javac]   symbol:   class HttpServletResponse
    [javac]   location: class ParameterServlet
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:9: error: cannot find symbol
    [javac]               throws ServletException, IOException {
    [javac]                      ^
    [javac]   symbol:   class ServletException
    [javac]   location: class ParameterServlet
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:12: error: cannot find symbol
    [javac]     public void doPost (HttpServletRequest request, HttpServletResponse response)
    [javac]                         ^
    [javac]   symbol:   class HttpServletRequest
    [javac]   location: class ParameterServlet
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:12: error: cannot find symbol
    [javac]     public void doPost (HttpServletRequest request, HttpServletResponse response)
    [javac]                                                     ^
    [javac]   symbol:   class HttpServletResponse
    [javac]   location: class ParameterServlet
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:13: error: cannot find symbol
    [javac]             throws ServletException, IOException {
    [javac]                    ^
    [javac]   symbol:   class ServletException
    [javac]   location: class ParameterServlet
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:2: error: package javax.servlet does not exist
    [javac] import javax.servlet.*;
    [javac] ^
    [javac] E:\install\tomcat\tomcat11013\webapps\httpreqresp\src\httpreqresp\ParameterServlet.java:3: error: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.*;
    [javac] ^
    [javac] 9 errors

BUILD FAILED
This is because for newer versions of JAVA and Tomcat as in Java 21.0.9 and Tomcat 11.0.13 the HttpServlet package has changed from
import javax.servlet.http.HttpServlet;
to
jakarta.servlet.http.HttpServlet;
Once these changes are made in ParameterServlet.java, restart tomcat, delete the existing ParameterServlet.class file and do a fresh ant build
E:\install\tomcat\tomcat11013\webapps\httpreqresp>ant
Buildfile: build.xml
     [echo] 111111...

compile-single:
     [echo] Compiling LoginForm.java...

BUILD SUCCESSFUL
Total time: 0 seconds
The ParameterServlet.class class file is created in CATALINA_HOME/httpreqresp/WEB-INF/classes/httpreqresp path.

We now invoke the ParameterServlet from the browser as follows
http://localhost:8080/httpreqresp/Form.html


And the response is displayed as below



God's Word for the day
Riches are good if they are free from sin; 
  Poverty is evil only in the opinion of the ungodly.
The heart changes the countenance either for good or for evil
  The sign of a happy heart is a cheerful face,
but to devise proverbs requires painful thinking.
Sirach 13:24-26

Concerning Fasting 
And whenever you fast, do not look dismal like the hypocrites
  For they disfigure their faces so as to show others that they are fasting.
Truly I tell you, they have received their reward.
  But whn you fast put oil on your head and wash your face
So that your fasting may be seen not by others;
  But by your Father who is in secret.
And your Father who sees in secret will reward you.
Mathew 6:16-18

No comments:

Post a Comment