Updating Java Servlet without restarting Tomcat in Tomcat 8.0 ownwards

Problem: Recently i started learning Java Servlets and faced an issue regarding updating of Servlet after recompiling the servlet class. Initially, I what i did was shutting down Tomcat and restarting again after making any changings to servlet and recompiling it. But then i did some digging and found the solution for this issue. Following are the steps for handling this problem.

The Guide is for Tomcat 8 ownwards.

Open Tomcat directory and navigate to conf Folder. In Conf folder, you will find a file tomcat-users.xml . Open that xml file and you will something like following in that file:


<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
</tomcat-users>

There you can see the default users. The next step is to add a new User here. Edit that file and add following code for a new user before closing ‘tomcat-users’ tag.


<role rolename="manager-gui"/>
<user username="admin" password="shumail" roles="manager-gui,manager-jmx,manager-script,manager-status"/>
<!-- Just add above 2 lines for creating a new user -->

After addition of this code, the tomcat-users.xml file will look something like this:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->

<!-- Following is the code for new user -->
<role rolename="manager-gui"/>
<user username="admin" password="shumail" roles="manager-gui,manager-jmx,manager-script,manager-status"/>

</tomcat-users>

Save the xml file. At this point, we have successfully created a new user with username admin and password shumail and assigned 4 roles to this user – manager-gui, manager-jmx, manager-script, manager-status.

We are almost done. Now whenever you do any changes in servlet code and recompile it, all you need to do is open following URL in browser that uses Tomcat Manager Application to redeploy the servlet:

http://localhost:8080/manager/text/reload?path=/

This will prompt for username and password. Enter username and password of the user we created earlier here i.e admin/shumail. You should see this type of message if it will be successful.

OK - Reloaded application at context path /

Refresh your application URL and you will see the updated version.
Share your thoughts in comments below – Don’t forget to share this article – Sharing is Caring..

Batch changing URL of post images in wordpress

For blogger who self-hosts the WordPress blog publishing system on a web hosting server with own registered domain name, sometimes, you may decide to reorganize the blog link URL to make it tidier or to reflect new focus or theme of the blog. You may decide to change URL of your site as well. But changing URL can cause some issues. You may face broken images in all your previous posts since you just changed URL of site but didn’t update the URLs for images already added to posts.

e.g Before changes, your wordpress URL was: www.old-site.com & your images URL were like: www.old-site.com/2013/06/image.png
And After Change, your site URL is: www.new-site.com but your all posts are showing images from www.old-site.com

It’s not possible to correct URL of all images by editing each post since it can take too much time based on volume of site. A better approach is to Change URLs of all the images collectively by SQL Querying the database. Let’s see how easy it this below:

NOTE: We will be using SQL statements based on MySQL replace() function to modify the database. To run SQL queries, you need to login to MySQL database that houses WordPress tables via phpMyAdmin or login to the DB server and run MySQL client as root. If you don’t have access to it, then you can also do this from your wordpress admin dashboard by installing a plugin: Find & Replace ( http://wordpress.org/plugins/search-and-replace/ )

Go to MySQL Query mode & use the following SQL commands to fix broken links to blog in all WordPress posts and pages:

-- MySQL Query

UPDATE wp_posts SET post_content  =
replace(post_content, 'http://www.old-site.com', 'http:/ www.new-site.com');

-- see documentation of replace function for more understanding

The above SQL Query will replace all the links for www.old-site.com with www.new-site.com in post_content (DB Table that stores all posts content) & hopefully this will fix broken images links as well since now those images URLs will be changed to new domain.

Caution: Before making changes to database & run queries, make sure to backup your database because these changes will be permanent and can’t be undone. Dont forget to export your database from phpmyadmin as .sql 

Please share this with others who are facing such issues – Sharing is Caring..

Installing and Configuring MySQL 32 bit ODBC driver on a 64 bit Operating System.

Complexity: Recently i was working on a C# Project that was 32-bit application. My Machine is 64-bit so i was facing problem while using MySQL ODBC 64-Bit Driver with my application there’s type mismatch and project was giving runtime error. I tried to use 32 bit driver on my PC and managed to get application working and get rid of “architecture mismatch error” that’s common while using it, after following the below solution.

What happens is that you have a 64 bit operating system, which usually comes with a more modern equipment, and specially a 64 bit server OS, which is most likely to be the case, and you need to install an ODBC driver that would work with a 32 bit application.

If you install a 64 bit ODBC driver, it will be listed and configurable in “ODBC Data Source Administrator” (StartControl PanelAll Control Panel ItemsAdministrative ToolsData Source (ODBC)), but it will not be able to work with 32 bit application.

On the other hand, if you try to install the 32 bit driver, the system will not recognise it, and it will not appear in your default Data Sources (ODBC) inside the control panel, so you will not be able to configure it and connect to MySQL.


THERE IS A SOLUTION TO THIS PROBLEM – In many places you will read that this is IMPOSSIBLE – WHICH IS NOT TRUE. What you need to do is the following:

    • Download and install the 32 bit MySQL driver, regardless of the fact that you are using a 64 bit OS.It will install the files in the following place (path):C:Program Files (x86)MySQLConnector ODBC 5.1
    • Make sure that you are installing ODBC Driver Version 5.1, because for 5.2 it doesn’t work properly. Use this link: http://dev.mysql.com/downloads/connector/odbc/5.1.html
    • Instead of following the usual path via the Control Panel (Control PanelAll Control Panel ItemsAdministrative ToolsData Sources (ODBC) ) , where the 32 bit driver will not be recognised, YOU NEED TO FIND AND USE THE FOLLOWING PATH:
      C:WindowsSysWOW64odbcad32.exe
      .

mysql-odbc-instructions-1

Open odbcad32.exe and you will find 32-bit driver there. Use that to create DSN or whatever your objective is.

mysql-odbc-instructions-2

Here you will be able to see your 32 bit ODBC driver and configure it to connect with the MySQL database, in the same way as you would do on a 32 bit system. That was all about installing and configuring MySQL ODBC 32-bit driver on 64-bit PC. Stay tuned for my next post on using MySQL ODBC driver with C# Application.

Please encourage me by Sharing this blogpost.