• No se han encontrado resultados

TÍTOL VIII. REGULACIÓ DEL SÒL NO URBANITZABLE

D) ÀREA DE PROTECCIÓ INTEGRAL. E) ÀREA DE SERVEIS AGRÍCOLES

Let’s get started with setting up the environment that we use throughout this book. We explain how you can run (and play with) the provided examples. Note that you don’t need to use Eclipse to run our examples. We provide Ant scripts so that you can also run them from the command line or from other integrated development envi- ronments (IDEs) such as NetBeans or IntelliJ.

3.2.1 Setting up ESBs, tools, and required libraries

Before we get started, make sure you have the correct versions of Ant and Java installed. Mule and ServiceMix can run with older versions of Java, but some of our examples use Java 5 features, so make sure you’ve got an up-to-date Java version installed. Besides an up-to-date Java version, we use Ant for automating download, compile, build, and startup tasks, so we also require an up-to-date Ant version.

INSTALLINGTHELATEST JAVAVERSION

To check your version of Java, run java -version from the command line. This com- mand should return something similar to this:

java version "1.6.0_06"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0_06-b02) Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

Notice that this is the output of a Java 6 runtime environment, but Java 5 is also fine. If the Java version shown is below 1.5, then please install a newer version from http://java.sun.com/javase/downloads/index.jsp.

INSTALLINGTHELATEST ANTVERSION

Besides an up-to-date Java version, we also use Ant to run the examples. If you don’t have Ant installed, please download and install the latest version from

Listing 3.16 Defining an ActiveMQ connection in a servicemix-jms configuration

http://ant.apache.org. If you do have Ant installed, run the ant -version com- mand to check the version of your installation. Verify that the version returned is at least 1.7. If you’ve installed an older version, go to http://ant.apache.org and download the latest version.

SETTINGUPTHEENVIRONMENTWITH ANT

Now that you know that the correct versions of Java and Ant are installed on your sys- tem, let’s get the libraries, servers, and tools used in this book. Some of the tools used in this book, such as the Apache Directory Server in chapter 8, need a separate instal- lation. We’ve created an archive that you can download from this book’s website, http://www.esbinaction.com/rademakers (if you haven’t done so already in chapter 1). Unpack this archive into a directory of your choice, and you’ll see that the following directory structure has been created:

-boxResources -esb -libraries -prepareResources -tools -workspace build.xml

In the esb subdirectory we’ll install ServiceMix and Mule. If you’ve worked through the examples in chapter 1, you’ve already installed Mule and ServiceMix in this direc- tory. In the libraries subdirectory, we’ll store all the required libraries used in our examples. In the tools directory, we’ll install various servers such as an EJB container, and an XML and relational database. The workspace directory contains the examples and resources shown in this book. If you look through the directories, you’ll notice that most of them are still empty. This is because providing all the libraries would make the downloadable archive very large. So to get started, we’ll use the Ant build file in the root directory, build.xml, to download all the libraries, servers, and tools and then store them in the right directory structure.

Ant, Ivy, and Maven

For this book we chose to use Ant for all the builds and examples, and we also use Ant to set up the initial environment. The reason we use Ant instead of Ivy or Maven is that with Ant we can easily get the installation archives and unpack them to spe- cific directories. This would also be possible with Maven or with Ivy, but would involve a lot of work in getting all the dependencies correct and getting the depen- dencies in the proper target directory.

The main reason to use Ant is that we’re not forced into a specific directory struc- ture or project setup (Maven does force that on you). However, when you’re doing your own ServiceMix project, Maven might be a good option. The people behind ServiceMix have provided a nice set of Maven artifacts that you can use to set up and deploy service units and service assemblies to ServiceMix.

To get all the correct libraries (we list the versions in appendix G), you should run the ant script from the root directory where you unpacked the downloaded archive, which happens to be the directory where the Ant file is located. You do this by run- ning the following command:

ant prepare-environment

When you run this example, you can get a cup of coffee, since this will start download- ing all the required libraries, tools, and servers from various online repositories and websites. When you scroll back in your console, you’ll see output in your console that looks similar to this:

init:

[mkdir] Created dir: tools [mkdir] Created dir: libraries get-mule:

[echo] Downloading Mule.... (38MB)

[get] Getting: http://snapshots.dist.codehaus.org/mule/org/mule/

➥distributions/mule-full/2.0.2/mule-full-2.0.2.zip [get] To: work/downloads/mule-full-2.0.2.zip

When the Ant build file has finished executing, you’ll have a completely configured environment that you can use to run the book’s examples and play around with the Mule and ServiceMix ESBs.

Navigate to the workspace folder and you’ll see two subdirectories. One directory contains a Mule workspace and the other a ServiceMix workspace. In these work- spaces you’ll find all the examples from this book. So just navigate to the correct chap- ter in these workspaces and you’ll find an Ant file there that you can use to run the examples from that specific chapter. In all the upcoming chapters we explain which Ant file and which target you need for a specific example.

So far we’ve only set up a command line–based environment. Since developing and experimenting with the code is much easier from an IDE, let’s see how you can use Eclipse together with these examples.

3.2.2 Running examples from Eclipse

You don’t have to do much to run our examples from Eclipse. In this section we show how to import the examples in Eclipse. To do this, start Eclipse and create a new work- space that points to the workspace/workspace-mule directory (where you unpacked the downloaded archive). When Eclipse has started, select File > Import from the Eclipse menu. This opens the screen shown in figure 3.5.

From this screen select Existing Projects into Workspace and click Next. This opens the Import Projects screen, shown in figure 3.6.

On the Import Projects screen, use the Browse button to navigate to the work- space/workspace-mule directory. After you’ve selected that directory, you can select the Mule project and import it into your own workspace. Make sure, though, that you

don’t select the Copy projects into workspace option, since the project is already at the correct location.

And that’s it! You now have a configured Eclipse workspace from which you can run and experiment with our Mule examples. You might wonder why you don’t have to configure the classpath or do any other setup work. During the “prepare- environment” step, we also created the Eclipse-specific .classpath file to make it all a bit easier.

Now the Mule setup is finished, and we can do the same thing for ServiceMix. For this you can repeat the previously mentioned steps, but this time point the workspace to the workspace/workspace-servicemix directory instead of the workspace/workspace- mule directory. Then you can import the ServiceMix project in the same manner as we showed in figures 3.5 and 3.6.

The development environment is in place, and you can run the examples from both the command line and from Eclipse. Next let’s look at an example where every- thing we’ve done so far comes together. We start with a Mule-based example, and after that we show you a ServiceMix-based example.