Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Spring in Action Third Edition source code

I extracted sia3-code ZIP file and imported the extracted sia3-code folder as Existing Maven Projects in my Eclipse Helios IDE. It imported just fine but I don't see any of the src folder in the build path and I can't run the test classes.

This is how it looks: enter image description here

Could someone help me with how to get the source code that comes along with the book running as maven project?

Thanks.

like image 868
skip Avatar asked Sep 25 '12 20:09

skip


2 Answers

1] download the sourcecode into a dir, which i'll refer to as code_dir_tree

2] edit the pom.xml in the code_dir_tree root as follows:

replace:

<modules>
        <module>translators</module>
</modules>

with:

<modules>
        <module>knights</module>
    <module>rest-client</module>
    <module>springidol</module>
    <module>springidol-annotation</module>
    <module>springidol-aop</module>
    <module>springidol-aspectj</module>
    <module>springidol-atinject</module>
    <module>springidol-autodiscovery</module>
    <module>springidol-javaconfig</module>
    <module>springidol-qualifiers</module>
</modules>

3] from a command shell in the code_dir_tree root directory, run: mvn eclipse:clean

4] within eclipse, ensure you have a refreshed, preferably empty workspace available

5] copy the entire code_dir_tree manually into the workspace - not the individual projects, the code_dir_tree itself.

6] in eclipse, perform import | existing maven projects, select the code_dir_tree root (already within the workspace), ensure all the projects including the pom.xml are selected, hit finish

7] run maven updates, clean install builds - all -maven- projects aside from rest-client, which has an unresolved dependency, should now be ready to go

The remaining projects, spitter and SpringPizza, are gradle projects - STS, which has gradle integraton, needs to be installed to get these imported

8] in eclipse, perform import | gradle project, select the spitter directory, hit ok, select 'build model', when complete ensure all are selected, hit finish

9] repeat the same process as in 8] for SpringPizza

That's it - you should be ready to roll!

like image 126
theRiley Avatar answered Nov 15 '22 09:11

theRiley


In the package explorer, right-click on the java directory and select Build Path->Use as source folder. Do this for both java directories (the one in src/main and the one in src/tst).

Then right click on the project and select Configure->Convert to Maven project.

UPDATE:

I think you need to install the M2Eclipse Plugin. Here are some directions. Then you should be able to right click on your project and select Maven->Enable Dependency Management.

Since you are utilizing Spring, I would highly recommend you checkout SpringSource Tool Suite. It's Eclipse bundled with a lot of useful plugins (such as m2eclipse). Here's a brief snippet from their website:

The Spring Tool Suite™ (STS) provides the best Eclipse-powered development environment for building Spring-powered enterprise applications. STS supplies tools for all of the latest enterprise Java and Spring, and comes on top of the latest Eclipse releases.

Read about STS and download it at its site: http://www.springsource.org/sts

SECOND UPDATE:

I think I see what you did wrong. It looks like you specified the root of your project as the directory that contains the folder 'sia3-code'. That caused all the projects to be collapsed under one big project, which, I'm pretty sure, is not the way you want to do it.

Remove the project from your Eclipse. Then in the Package Explorer, right-click and select Import. Select "Existing Projects into Workspace". Select the root directory to be /your/path/to/sia3-code/ (do not select the root directory to be /your/path/to/). Then select Finish. You'll see that you have 10+ projects imported into your IDE.

The above steps were verified in STS, so you might need to adapt them a bit if you are using Eclipse Helios.

like image 37
alfredaday Avatar answered Nov 15 '22 09:11

alfredaday