Home Page   We Generate Your Software.
Products Services Company Technology Demo Contact Site Map Search

Full list of in-depth articles - Feedback and questions - Request demo -


1 September 2004 - Eclipse and SoProMach

  1  Extending Eclipse with a Somusar generator
  2  Requirements
  3  Preparing an integration workspace in Eclipse
  4  Extending Eclipse with SoProMach/java_dao_struts
  5  Running SoProMach/java_dao_struts from within Eclipse

1 - Extending Eclipse with a Somusar generator

So far, a major part of Somusar's activity on generators development has been aimed at delivering a number of self-contained, batch generators providing a broad range of proof-of-concepts (POCs). These POC generators demonstrate the flexibility and applicability of Somusar/Software Production Machine[tm] for a number of different code-generation tasks.

This article describes how to integrate one of these generators (the Java/JSP DAO Struts generator) with one of the most famous integrated development environments (IDEs) for Java: Eclipse 3.0.

Such an integration shows how to use Eclipse's comfortable user interface to directly drive SoProMach's powerful code generation facilities, significantly improving Eclipse users' productivity without limiting their development experience.

The Somusar generator used for this article produces code conforming to Keld H. Hansen's tutorial "Using DAOs in Apache Struts" published by JavaBoutique. Depending on different project requirements and constraints, different Somusar generators can be integrated to produce source code, configuration files, and documentation compliant to those requirements and constraints.

2 - Requirements

The article assumes that you have a working installation of both Eclipse 3.0 and SoProMach/java_dao_struts on Windows 2000 or Windows XP. Steps similar to those described in this article are required to integrate Eclipse and SoProMach on Linux or Mac OS X.

Instructions on how to request, install, and run the SoProMach/java_dao_struts generator are provided in the generator description and in the general POC instructions.

You will also need the source code from Keld H. Hansen's tutorial "Using DAOs in Apache Struts", which is freely available on JavaBoutique.

3 - Preparing an integration workspace in Eclipse

To test the SoProMach/java_dao_struts generator we suggest to set up a new workspace in Eclipse. By default, when starting Eclipse you may select a workspace. We chose the new workspace shown in the picture below.

Figure 1 - Creating a new Eclipse workspace

Figure 1 - Creating a new Eclipse workspace

After creating the new workspace, you create a new project with the "Java Project" wizard, as shown below.

Figure 2 - Creating a new Eclipse Java project

Figure 2 - Creating a new Eclipse Java project

You can then assign a name to the new Java project. We chose "dao_struts", as in the next picture.

Figure 3 - Creating the DAO Struts project

Figure 3 - Creating the DAO Struts project

To be able to compile the Java files that the generator will produce, you need to add several external JAR files. These JARs are required to rebuild the project described by Keld H. Hansen's in his tutorial "Using DAOs in Apache Struts", independently of SoProMach/java_dao_struts. Please refer to Keld's article for a list of the required components and JAR files. To add the JARs to the Eclipse project use button "Add External JARs..." shown in the next picture.

Figure 4 - Adding required JAR files

Figure 4 - Adding required JAR files

After creating the new project, you can now create a new package "dk.hansen" by selecting the project with your mouse, and right-clicking to activate menu "New -> Package" and fill in the dialog illustrated below.

Figure 5 - Creating the new dk.hansen package

Figure 5 - Creating the new dk.hansen package

You can now add the one and only hand-written file required for your project, "DAOException.java". You can get this file from the download package of Keld's article. Import it into package "dk.hansen" of your Eclipse project using the file system import wizard as shown below. Make sure that "Create selected folders only" is selected.

Figure 6 - Importing file DAOException.java

Figure 6 - Importing file DAOException.java

If everything so far worked properly, you should now be able to double-click on DAOException.java and view it in the editing area of Eclipse. More importantly, Eclipse's automatic build should report no errors ("0 errors, 0 warnings, 0 infos") as shown in the checkpoint picture below.

Figure 7 - Checkpoint 1

Figure 7 - Checkpoint 1

You can now close the project (see below) and proceed to the next stage.

Figure 8 - Closing the project

Figure 8 - Closing the project

4 - Extending Eclipse with SoProMach/java_dao_struts

Up to now you have created a simple Java project with one class. Extending Eclipse with the generator is not more complex than that. The generator is configured as an external tool. You can open the external tools configuration dialog by navigating this menu path: Run -> External Tools -> External Tools...

Click on "Program", then on "New_configuration". Set the input fields of tab "Main" (Location, Working Directory, Arguments) as shown in the picture below, except that "C:\ide_user\dao_struts_gen" is the installation folder where we uncompressed the SoProMach/java_dao_struts trial package tarball (".tgz") file. Instead of "C:\ide_user\dao_struts_gen" you should type the path where you installed your copy of SoProMach/java_dao_struts. Do not click on "Apply" yet: you need to set tab "Refresh" and "Common" first.

Figure 9 - Eclipse's external tools: tab "Main"

Figure 9 - Eclipse's external tools: tab "Main"

Select tab "Refresh". Activate "Refresh resources upon completion". You should get the same settings as shown below.

Figure 10 - Eclipse's external tools: tab "Refresh"

Figure 10 - Eclipse's external tools: tab "Refresh"

Select tab "Common". Deactivate "Launch in background". Activate "External tools" under "Display in favorites menu".

Figure 11 - Eclipse's external tools: tab "Common"

Figure 11 - Eclipse's external tools: tab "Common"

Now click on "Apply", then on "Close". Do not click on "Run" yet: you have to import the entity files into your project first.

5 - Running SoProMach/java_dao_struts from within Eclipse

The input models to SoProMach/java_dao_struts are Sisendel entity files, listed in the generator description. Entity files are plain text files, that can be imported into Eclipse without any particular configuration.

Select package "dk.hansen" in the project view of Eclipse, and right-click to activate the file-system import wizard of Eclipse. You can thus import the four ".ef" files provided in the "project" folder of your SoProMach/java_dao_struts trial package, as shown in the next picture. Click on each selection box beside the four .ef files, and do not click on the selection box beside the "project" folder, otherwise you will import additional unnecessary subfolders.

Figure 12 - Importing the four ".ef" files

Figure 12 - Importing the four ".ef" files

You are now ready to run the generator. Make sure that your Eclipse window looks like the checkpoint picture below, with 0 errors, 0 warnings and 0 infos, and the four .ef files in package "dk.hansen".

Figure 13 - Checkpoint 2

Figure 13 - Checkpoint 2

Now open file "dvd.ef" by double-clicking on its name. Its content appears in the internal editor of Eclipse.

To run the SoProMach/java_dao_struts generator for the first time you have to re-open the external tools dialog following this menu path: Run -> External Tools -> External Tools... Select "DAO Sopromach", then click on "Run". Within short you should see a number of Java classes appear in the "dk.hansen" package, and a "Console" tab appear in the output message area of Eclipse. Click on this tab: your Eclipse should now look like the following picture.

Figure 14 - Applying the generator on "dvd.ef"

Figure 14 - Applying the generator on "dvd.ef"

Note that the generated files that appeared in the "dk.hansen" project are by default automatically compiled by Eclipse. The whole project should get rebuilt with no errors.

At this stage your Eclipse + SoProMach environment has produced the same code that Keld H. Hansen wrote for his tutorial, with some minor differences. The generated code includes:

  • nineteen Java files;

  • two JSP files;

  • one struts-config.xml file;

  • one app.properties file.

All of these files are made available in the same package "dk.hansen".

You can now instruct your code-generator-enabled Eclipse to produce similar code for a different application of the same type. Instead of the DVD manager code, you will generate equivalent code for a Book manager application.

Double-click on "book.ef" to open it in the editing area of Eclipse. Follow menu path "Run -> External Tools -> DAO Sopromach" to apply the SoProMach/java_dao_struts on file "book.ef". After doing so, you should get twenty-three newly generated files, and your Eclipse should look like the picture below.

Figure 15 - Applying the generator on "book.ef"

Figure 15 - Applying the generator on "book.ef"

Note that "book.ef" is slightly more complex than "dvd.ef": it has more fields, one of which is numeric, and its "search_keys" collection in section DB contains more than one field. This is reflected in all the generated code. Open some of the generated files related to "book" and compare them with their counterparts related to the "dvd" entity.

You can now complete the Eclipse-SoProMach integration example by repeating the previous step on files "cd.ef" and "vhs.ef". If all goes well your "dk.hansen" package will contain ninety-two generated files plus five hand-written files (four ".ef" files and DAOException.java). Your Eclipse should now look like the next picture.

Figure 16 - Generation completed

Figure 16 - Generation completed


Full list of in-depth articles - Feedback and questions - Request demo -

http:// www.somusar.com  / company  / news  / in_depth  / sep01_2004  - Powered by SoProMach
Copyright © 2003-2012 Somusar - Trademarks - Legal - Privacy - Webmaster