Documente Academic
Documente Profesional
Documente Cultură
1.) Although you can choose to put it where you want, it makes a lot of sense for all the
developers on one team to use the same directory structure for our development. I will
use C:\dev throughout this guide. If you have chosen to use something else, adjust your
paths accordingly
2.) Although our production is based on Java 1.4.x and we can set up Eclipse to be compliant
to that same JDK, it makes sense to all download JDK1.5.0_10. You absolutely can
configure Eclipse to only ever allow code that matches Java 1.4. However, in the future,
we may want to jump to five and this way it’s just a configuration setting.
Install the JDK (the full JDK, not just the JRE) into the following directory
3.) After you have installed Java 5, it makes sense to change the root directory to something
simple like I have here. Your choice.
4.) Go to the Windows icon My Computer and right-mouse click. From the context menu,
select properties and then the Advanced tab. At the bottom, select “Environment
Variables” Add a new one called: “JAVA_HOME”, as you see in this example.
Obviously, if you did not simplify the name of your Java home directory, it should match.
5.) You absolutely can use just Eclipse without adding on MyEclipse. The main reason for
adding MyEclipse is for the way it adds several productivity-enhancing features and
removes some annoyances. It makes the plug-ins work together out of the box.
6.) First register for MyEclipse: We all will be using a free 30-day trial until funding goes
through.
http://www.myeclipseide.com/user.php?op=register&module=NS-NewUser
9.) Choose the All-in-One install and Save it to your Windows file system.
10.) I suggest that you install MyEclipse into a new folder under your C:\dev
directory called Eclipse_Europa, which is the version of Eclipse underlying
MyEclipse.
11.) After you have installed MyEclipse/Eclipse, you should find the icon I’ve selected
in this location. Double click on this. When eclipse pops up, it will ask you to select a
workspace, or the place where it will store your Java source and associated files. I highly
recommend you do not accept the default location. Instead, create a directory (often
prefaced with an underscore so it is visible at the top of your directory)
a. You should have a different workspace for each separate application—web or
otherwise—that you work on. It’s really easy to swap and back forth between
workspaces. Also, then you can deploy one web app at a time. In this screen cap,
you see that I have a workspace devoted to C:\_GodwhaleWeb
12.) MyEclipse will come up with a Welcome screen such as this, that you should just
dismiss.
13.) Next, it’s very important to follow what I suggest to avoid becoming frustrated.
You will see the following screen, which is the raw development environment.
Right now we’re looking at the MyEclipse perspective. In Eclipse there are a dozen
different perspectives, which are each organized around a particular type of work. This
one is for writing new code. There is a Debug perspective, a Database Explorer
perspective, etc. You switch between them by clicking on the yellow plus sign.
If you want to add a JSP, you add it to the WebRoot. Right-mouse click and it says “New JSP”.
In this example, though, I already have some code.
How to Add a Jar File
This next bit is very important and is the part that can be frustrating if you don’t do it
right. If you have a Jar file you want to add to the project, your inclination might be to just go to
the place in the directory structure and put it where you need it. BAD IDEA. Instead, you should
but it somewhere outside your workspace and do this. Click on the project and Import the jar
file.
Browse in your file system and pick the directory where your Jar is located. You won’t be able to
see it yet.
In the next screen, you will be able to pick any Jar you want.
Now, we see that indeed the Jar in question has been imported but it is not yet used by our
project, nor is it on the .classpath yet.
It will only show you Jars that you don’t already have. Select the jar and you’re done.
I have added a JSP to WebRoot using the automatic creation and we see one of the perks of
MyEclipse, the ability to design with a virtually WYSIWYG tool:
When I used the MyEclipse auto create to make a servlet, I also clicked on a linking feature that
takes you to the source of any file you click on. This is good and should be used. Also, without
me doing anything except using the wizard to create the new servlet, it automatically configured
the web.xml for me.
CTRL + SHIFT + T = it brings up a Type (as in Java type) browser. You can open the original
source for any Type with this command. Very convenient.
CTRL + SHIFT + R = it brings up a Resource (meaning every file that is not a Type) in your
project.
Within the class, type CTRL + SHIFT + O and it both adds any needed import (asking you to
clarify any ambiguities) or removes any imports that are not being used. Then, it alerts you if you
have any orphan references:
This is really cool and is a great friend to a lazy programmer. Say you have a block of code that
has gotten hairy and you would like to make a method out of it. Highlight the lines you would
like to send to a method:
Type ALT + SHIFT + M and it will ask you for the method name. (If the block has more than
one return, it will refuse to make a method while explaining why.
Eclipse is a bundle of timesaving aids like this. You don’t need to use any of them but they will
save you buckets of time if you do.
Step 3: Install A Local Copy of Jrun40
MyEclipse has a great aid in that it comes pre-configured for things like Application Servers
—including JRun40, fortunately. [I much prefer Jboss but the company where I wrote this
only permitted JRun…]
First, if you are a developer, you can have a permanent developer’s copy of JRun on your
local machine—as long as you only access it by one IP number.
Save it to your local file system and install it—my recommendation—to your C:\dev
folder.
Next, go back to My Computer, right-mouse click and select properties. Then, choose the
advanced tab and Environment variables. Enter a JRUN_HOME that matches where you
loaded it. See this example.
While you’re there, you might want to add the Java Bin directory to the end of your PATH
environment variable. Although Oracle generally puts its crappy old JDK at the front of the
path, it will work if you do this:
Last step. We need to associate our local JRun instance in MyEclipse so it automatically
deploys to it, and so we can start and stop it from within Eclipse.
To deploy the project you were working on to JRun, you click on the deploy button. It
automatically deploys your project as an EAR to your chosen application server. Yet another
sweet benefit of MyEclipse.
After you have started your server, you will want to switch to the Debug perspective
By clicking on the purple margin of your page, you can set a breakpoint. When someone
calls up your webapp’s URL, it will stop during execution at this point and you can inspect
the contents of variables to your heart’s content. You can step through code or anything.
You can look within complex data structures to your heart’s content and—I hope I need not
add—this is immensely more efficient than adding System.out.println() statements
galore. The developer productivity boost more than pays for the $52.00 price of MyEclipse.