Inicio > desarrollo > Building Your Development Environment of Java, Tomcat, Eclipse & MySQL

Building Your Development Environment of Java, Tomcat, Eclipse & MySQL

Fuente: http://www.sipages.com/jet.shtml

Developing JSP’s and Servlets

Looking for a desktop environment to develop and test commercial-quality Java code, JSP’s and Servlets? Prefer not to spend a small fortune for the software?

Here’s a great alternative to high-priced, commercial software and you just can’t beat the price! It’s all either free and open source (or just free) and available for downloading on the internet (for commercial work or for provider support, some of the components may have a price tag). After it’s set up you’ll be able to make changes to your JSP’s and servlets and see the effects immediately in a browser. You’ll also have many of the debugging features of the Eclipse environment available and the console will be live along with the Tomcat logs for bug tracing.

You can develop WAR files (Java Web Archive files) which can be dropped into the webapps folder of a Tomcat server.  Tomcat will magically “explode” the WAR file into the appropriate folders.  This makes transferring your website to a server a snap. If you select the option to include the Java files you can also pass your WAR file to other developers who can unzip the WAR into a project inside Eclipse for further development.

This tutorial covers the basics of a JSP and Servlet development environment. It is recommended you learn these basics before moving on to Struts, Tiles, Validation and other advanced frameworks.

The following pages include the steps to load Java, a Tomcat JSP container which works as a server, the Eclipse IDE, and a MySQL database server. The versions are generally up-to-date as of May, 2012. Other versions may be available but remember to read through the various websites to confirm all the components will work together. After the downloads are unzipped, installed and set up you will have eaten 500+ mb’s on your hard drive. Even more as you begin to set up the workspaces and databases for development — plan on a gigabyte of hard-drive space.

The programs were installed on a workstation running Windows 7 in 64-bit mode.  The setup is essentially the same for XP, Vista and  Windows 7 in 32-bit. If you download the 32-bit versions of the following programs remember to install the programs in C:\Program Files(x86)\ rather than C:\Program Files\. Some of the screen captures were made in Windows Classic mode — they look old-fashion but are a little easier to read.

Component Version Link Download Size (Zipped) Installed Size
Java 7 JDK 7.4 http://www.oracle.com/technetwork/java/javase/downloads/index.html 95 mb 204 mb
Tomcat 7.0.23 http://tomcat.apache.org/download-70.cgi 8.3 mb 13.4 mb
Eclipse (Indigo) 3.7.1 www.eclipse.org/downloads/index.php 212 mb 283 mb
MySQL 5.1.53 dev.mysql.com/downloads/mysql/5.5.html 32 mb 78 mb
MySQL Connector 5.1.18 dev.mysql.com/downloads/connector/j/5.1.html 4 mb 9 mb
MySQL Workbench (not required but highly recommended) 5.0 “http://dev.mysql.com/downloads/gui-tools/5.0.html” 26 mb 97 mb
Setting up projects Start coding!
Project testing from the workspace Hot-swapping your code.
Creating a WAR file Exporting your project.
Book Recommendations Using the Amazon links on the left help support this page.

Contact:

Please send any comments or suggestions to webmaster@sipages.com. It would be a huge help if you report errors in the instructions or just point out hard-to-understand sections. Several hundred Java/Tomcat beginners are using these instructions every day — so any corrections would help us all.

The Murach book, “Java Servlets & JSP (2nd Edition),” is highly recommended for developers learning the basics of JSP’s and servlets. It will help you develop a strong foundation before venturing into Struts, Tiles, Validation, etc. The Hall, Brown, and Chaikin book, “Core Servlets and JavaServer Pages, Vol. 2 (2nd Edition),” is excellent and includes the Struts, Tiles and Validation frameworks. Both are readable by beginners. There are Amazon links to both books on the left column of this page.  Using these Amazon links help pay for this site — thank you very much.

This page was last updated December, 2010. The screen captures are from a Windows 7 computer and may differ slightly from other operating systems. Some captures may also indicate earlier application versions, i.e., C:\Program Files\Java\jdk1.6.0_01 whereas the current version might be C:\Program Files\Java\jdk1.6.0_23.

JAVA

Java SDK

Download: http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-download-513651.html

Java File StructureChances are very good the Java that came with your computer is out of date and may well be only the Java Runtime Environment (JRE). Download and install a newer version of the Java JDK (Java Development Kit). You must install the JDK — which includes the javac compiler for compiling Java code — not just the JRE. In fact, the JDK includes a JRE in its directory structure and installs it in the main Java directory (see the screen capture at right).

On the Oracle website linked above, select the Java (JDK) SE 7u1. The “SE” stands for “Standard Edition”; the “JDK” stands for “Java Development Kit”.

After the download completes, accept the defaults and install it. The installer exe will know where it needs to be on your hard drive — just accept the location when the window pops up. The examples and screen captures assume the 64 bit version. The screen captures reflect whats current on 12/1/2011. Newer versions will have different update numbers (i.e., 7u2 instead of 7u1).

TOMCAT

Tomcat

Download: http://tomcat.apache.org/download-70.cgi

As of this update (12/01/2011) the Tomcat link above will display the 7.0.23 version release. You can find previous versions of Tomcat at the same location. In the Binary Distributions section chose the Tomcat version that works on your computer. The final Tomcat folder location will depend on which version you downloaded. The 64-bit version would go into the “C:\Program Files”.  The 32-bit version will go into the “C:\Program Files (x86)” folder. Please adjust the locations in the following paragraph accordingly.

After downloading, right click on the zip file and choose Extract All. Browse to “C:\Program Files”; the extraction process will create the “apache-tomcat-7.0.23” folder. If you extract the files to the default folder (which will be the folder where the zip file is located) create the following folder C:\Program Files\apache-tomcat-7.0.23 and move or copy the extracted files to it. The version numbers (“7.0.23”) should reflect the version you downloaded. Due to the wonders of Windows 7 security it may be easier to extract to the default folder and copy the files.

There are a couple of steps to associate Tomcat with Eclipse and your project. These will be discussed in the upcoming Eclipse section.

Unlike earlier environments, you no longer have to change the system environment variables to run Tomcat inside Eclipse. If this is your first try at setting up a development environment, you should probably take advantage of this change and forego setting up Tomcat so it will also run outside of Eclipse.  However, if you previously created a Java/Tomcat/Eclipse/MySQL environment on your current computer you should update or delete the following entries in the system environment variables.

Changes to the environment variables are made at the following location: Control Panel / System / Advanced System Settings / Environment Variables.  You can create, update, and delete system variables in the lower part of the window that pops up.

To run Tomcat outside of Eclipse you will need the CATALINA_HOME variable set in the System Variables section in the bottom half of the Environmental Variables window. The JAVA_HOME variable will also need to be set — that’s in the Java section of this tutorial. You don’t need the Classpath and Path variables set.

Classpath: C:\Program Files\apache-tomcat-7.0.23\lib\servlet-api.jar C:\Program Files\apache-tomcat-7.0.23\lib\jsp-api.jar;

Path: C:\Program Files\apache-tomcat-7.0.23\bin

CATALINA_HOME: C:\Program Files\apache-tomcat-7.0.23

Restart the workstation for the environment variable changes to take effect.

ECLIPSE

Eclipse

Download: www.eclipse.org/downloads/index.php

Installed Java JREsStraightforward download. Install in C:\Program Files\. The extractor will create the Eclipse subdirectory. Eclipse takes quite a while to load up (especially the first time) so be patient. It will create a workspace and ask you to confirm it.

Download the “Eclipse IDE for Java EE Developers” version (212 megabytes). Other versions may not have the built-in server view which is very helpful.

You must configure Eclipse to recognize the Java JDK you installed previously rather than the Java JRE Eclipse installs as the default. First, in Eclipse, select Window –> Preferences –> Java –> Installed JREs. Select Add on the Preferences page (see screen capture on the right).

In the Edit JRE window (shown below) enter “JDK” (or anything that makes sense) in the textbox marked JRE name (remember, the JDK includes a JRE in its structure). Use the browse button across from JRE home directory to navigate to the Java JDK directory from above (the default is C:\Program Files\Java\jdk1.7.0_01).

Back to the previous window and select the checkbox for the Java JDK you just added. As the window instructions note — Eclipse will now use the JDK by default.

Once  Eclipse is installed go to Help –> Welcome.  There are several valuable help files including tutorials to acquaint you with Eclipse.

Eclipse Edit JRE 

Eclipse and Vista / Windows 7 Security

This is similar to the comments in the Tomcat section above. Vista with User Account Control (UAC) running causes a problem.  Vista and Windows 7 normally run everybody — including administrators — in a non-administrative role. This provides additional security and makes it more difficult for intruders to run programs requiring administrative privileges. You can right click on the Eclipse desktop shortcut if you made one and chose “Run As Administrator”.

For a more permanent solution, right-click on the shortcut and chose “Properties –> General –> Advanced” and check the box to run the program as administrator.

MYSQL

MySQL

Download: dev.mysql.com/downloads/mysql/5.1.html

Online Reference Manual: dev.mysql.com/doc/mysql/en/index.html

MySQL will be installed as a service which will start up with Windows. It is recommended you accept most of the defaults although I did check in the “Include Bin Directory in Windows Path” checkbox (which allows Windows to find executables from the command line if you choose to run it that way occasionally) and you should add a password when given the opportunity — which you will soon forget so write it down! You may need to configure your firewall to accept the port(usually port 3306).

Grab your favorite MySQL manual and create a database and some tables from the command line. If you’re not in love with command line programming give the MySQL Administrator below a try.

Java – MySQL Connector

Download: dev.mysql.com/downloads/connector/j/5.1.html

The Java-MySQL Connector allows standard Java JDBC commands to access the database. As of December, 2011, the current connector is 5.1.18.

Download and unzip the file linked above. Copy the mysql-connector-java-5.1.14-bin.jar to the following folder in the Java home directory: C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext.

MySQL Workbench

Download: dev.mysql.com/downloads/gui-tools/5.0.html

To properly administer a MySQL database you can download or buy the 800+ page manual or you download and use the MySQL Workbench. With the Workbench’s GUI interface you can create databases, tables and columns much faster than entering arcane SQL commands in a DOS command box.  The WorkBench replaces 3 previous tools: query browser, administrator, and migration toolkit.  You can use the Workbench to export databases to other team members on a project.

Find the Workbench tutorial by clicking the Help button or selecting F1.

PROJECTS

Java Projects

It’s time to start writing code. A great book to use in setting up a first project is Murach’s Java Servlets and JSP. It contains a couple of relatively easy projects (complete with code) including a mailing list program that makes a perfect beginner’s project.

Tomcat has also provided several sample jsp files in the webapps directory. Navigate to C:\Program Files\apache-tomcat-7.0.5\webapps\examples\jsp\ to get some ideas. In the C:\Program Files\apache-tomcat-7.0.5\webapps\ROOT directory take a look at index.jsp.  It’s the page that came up when you originally set up the Tomcat directory above (which you reach with http://localhost:8080/ in the address of your browser).

Fortunately, almost any question you may have about programming has been asked before — usually several times — in the newsgroups. Just reading the current entries will quickly increase your understanding of Java programming.  It will also help you realize you’re probably not the dumbest Java programmer in the world — although, obviously, one of us is that person!  For answers and suggestions about writing Java code, check the following Google newsgroups:

Categorías:desarrollo Etiquetas: , , ,
  1. 15 octubre 2012 a las 3:20 am

    Thanks for sharing such a good thinking, post is nice, thats why i have read it entirely

  2. 17 octubre 2012 a las 10:46 am

    Wow, this paragraph is nice, my sister is analyzing these kinds of things,
    therefore I am going to let know her.

  1. No trackbacks yet.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: