Setting Up Eclipse for Time Expression


So far I have provided you with a basic understanding of Eclipse, enough to move forward with setting Time Expression. Now we can build an Eclipse Project using our existing Ant build.xml file. This is done via the File, New, Project menu option. Figure 8.9, shows the New Project Wizard screen. Select Java Project from an Existing Ant Buildfile from the options and click Next.

Figure 8.9. The New Project, Select a Wizard screen.


Figure 8.10 shows the next screen where we actually specify our existing Ant build.xml file. This is the big moment for us because after this step we can begin working with all our existing source code within Eclipse; no more command line! So, we can click the Finish button.

Figure 8.10. The New Java Project, Create a Java Project from an Ant Buildfile Wizard.


Figure 8.11 shows the first screen we should see immediately after the new project has been created, named timex. However, as you might notice, we have a few (more like, 100) problems as shown in the Problems view. This is related to the way I chose to set up the source and output directories for Time Expression.

Figure 8.11. Newly created timex project.


I could have demonstrated a smooth working example here that used Eclipse's default directory structure; however, I intentionally wanted to demonstrate this because there are good chances you (or the organization you work for) already have a standard way of establishing your directory structures. Anyway, we can easily fix this problem as explained next.

Let's expand the timex project's file/directory hierarchy tree in the Package Explorer view (on the left side of the screen). Locate the src directory in the tree and right-click it to show the context menu. Select Build Path, Remove from Build Path, as shown in Figure 8.12.

Figure 8.12. Remove src/ from build path.


After we do this, the src directory reappears on the list, but with a different icon. Note that we did not actually delete the directory, just removed it from the build path. Now, we will expand the src directory, locate the java subdirectory underneath it; right-click it and select the Build Path, Use as Source Folder option from the context menu, as shown in Figure 8.13.

Figure 8.13. Use as Source Folder.


We are almost there. We took care of the source directory; now we need to adjust the output folder for our compiled (.class) files, so we can use our Ant build.xml file to compile classes and also Eclipse's built-in Builder feature (see the sidebar "Save Compiles Within the Blink of an Eye!").

Save Compiles Within the Blink of an Eye!

If you have been programming for some time now, you are probably used to the trial-and-error techniquethat is, you write some code, compile it, fix compile errors, recompile, fix more compiler errors, recompile, run, find runtime errors. Okay, you get the picture.

Eclipse comes with a built-in builder for compiling your .java files to .class files every time you save your file. This is perhaps one of the most important, yet least advertised, features of Eclipse (it is a personal favorite of mine). The compilation is so fast that you won't even know the compilation took place. Pretty cool, huh?

If I press Ctrl+S to save my .java file, I instantly have a .class file generated for me within the blink of an eye (so to speak). Of course, the compilation takes place only if the source code is without errors (warnings are okay).


To change the default output folder, we right-click the src/java directory in the Package Explorer view and select the Build Path, Configure Output Folder context menu option, as shown in Figure 8.14.

Figure 8.14. Configure output folder.


We should now see a screen similar to what's shown in Figure 8.15. Notice that we have changed the default output folder to build/timex/WEB-INF/classes. This is relative to the workspace we specified earlier (shown in Figure 8.7).

Figure 8.15. Specify output folder location.


Now we are actually ready to use Eclipse for our development! However, let's take care of a couple more cleanup steps. These are optional, but we don't want to leave any unnecessary remnants lingering out there.

When we changed the source folder to src/java, Eclipse compiled the .java files to its default output folder (timex/bin/, that is). We can manually delete this subfolder, but let's adjust a configuration item so that Eclipse doesn't create this directory again. To do so, right-click any entry (file, directory, or project name, for example) in the Package Explorer view and select Build Path, Configure Build Path. Figure 8.16 shows the Project Properties screen for our application, Time Expression. Notice that we have changed the default output folder (toward the bottom of the screen) to timex/build/timex/WEB-INF/classes. This is the same output folder as the one we chose for our src/java directory. Again, this is an optional step because we are working only with a single source directory, so the default and source directory output folder are the same. After this, we can right-click the bin/ directory in the Package Explorer view and safely delete it.

Figure 8.16. Project Properties window.


Also, you might have noticed an entry in the Package Explorer view with a directory name that looks something like C:/anil/rapidjava/timex/build/timex/WEB-INF/classes; this might indicate (unknown) at the end of the ToolTip when you hover your mouse over this entry. We can safely remove this; right-click this entry and choose Build Path, Remove from Build Path.

Now Eclipse is fully set up to develop Time Expression!

By the way, I tried this setup on my Mac OS X and Linux and it worked as advertised. Figure 8.17 shows the Eclipse workbench on a Mac OS X, with the Time Expression project open. Figure 8.18 shows Eclipse on Linux (using bootable Knoppix Linux CD). Impressed yet? We have only begun; there is much more to come.

Figure 8.17. Eclipse with timex project on Mac OS X.


Figure 8.18. Eclipse with timex project on Linux (using Knoppix bootable CD).




Agile Java Development with Spring, Hibernate and Eclipse
Agile Java Development with Spring, Hibernate and Eclipse
ISBN: 0672328968
EAN: 2147483647
Year: 2006
Pages: 219

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net