Every person has its own way of setting up its developement environment. There is no ideal set up, but some are easier to maintain than others.
Mobile Development Kit has some useful features such as precompiling JSPs and building a WAR file for you, but it is slow when it comes to development cycles. Over my years at SAP, I understood that a couple of Ant scripts and a well set up Eclipse can be really more powerful than the MDK. Here is how!
1.Before starting to create your project, you have to install your development Mobile Infrastructure folder. I install it directly in the C:/. You can even create a backup copy to avoid reinstallation. After, you have to register that MI installation with the middleware and install the relevant applications (you have to do this because your application must be registered with the middleware to sync and appear on the MI homepage). Once this is done you can create your project.
2.When you receive code from SAP (in this case a mobile application ie. MAM), you should never directly change code from it. You should use the enhancement concepts to make your changes. So you should completly separate the sources in different folders. I suggest you keep the folder structure align between SAP and your own code on your disk before making that structure available to Eclipse. It will be easier for you afterward and it will be easier to set up your source control system. Let’s make the structure like this one:
The config folder is where you will put all the needed Ant build files and any extra configuration files you want (be it a launch target, a build target or even nightly build configuration for your in house system). The source folder is, well, for your Java sources. The webapps folder contains your application webapp folder. This is where you put the JSP and Tomcat related files.
3.Now you can create a project in Eclipse. To create a project, use the File > New > Project… and chose a “Java Project”. Give a meaningful name to the project: “Foo Guimont”. You also have to include the related libraries and all other stuff your project requires. Don’t forget to have a different output folder for your classes (otherwise both .java and .class will be mixed in one place, I guess I like to have organized stuff).
<property name=”project_mi” value=”$“/>
<target name=”copywebapp” description=”Copy the webapp files to the right place in MI”>
<fileset dir=”$/webapps/$The specified item was not found.“/>
You will be able to configure the script with the properties in Eclipse build phase editor. Let’s take a look…
6.Go in Project > Properties… menu item and click on the item “Builders” then create a new Ant builder.
Give a name to the builder : “Move webapps”. Select “buildphase.xml” Ant file as the buildfile. Go to the Properties tab and enter your project properties like this:
This builder will be called everytime you trigger a build for that project. The files will only be copied if you changed them so it is fairly fast. Eclipse takes care of moving your file to your MI folder so you are sure that what you have in there is the latest code. As you saw, only the webapps folder is copied. This is because the classes and libraries do not need to be in MI folder as long as they are loaded in the classpath in the Run Target.
7.Create your run target. Go Run > Run… menu and in the wizard create a “Java Application” run configuration for your project. Use the main class “com.sap.ip.me.core.FrameworkInitializer” (you have to include the libraries to be able to chose this class). In the “Arguments” tab write the following “-home:C:/MIFolder” (put your “MIFolder” name!).
Now you are ready to go! Hit the Run button and the build will be triggered, the webapp files
will be copied and your application will be launched within MI. Point your browser to http://localhost:4444/ and you should see it running.
I hope this post can be useful for some of you who asked questions about this. I a next entry I will talk about setting up a Ant build to create the complete deployable War file with precompiled JSP.