The spring framework has emerged over the last few years as a versatile and efficient support structure for multiple types of Java applications. The MVC component facilitates the development of rich web-driven applications. The SpringSource tool suite(STS) is an Eclipse derivative software package bundling the necessary tools to develop efficiently with the Spring framework. The Spring 3 MVC project is a Maven compliant project and the guide will make use of it to include a LexEVS dependency.
This guide will illustrate how to use a local instance of LexEVS in a Spring 3.0.x MVC project and how to deploy it to a Tomcat 6 server from within STS. It was tested using LexEVS 6.0 and Windows 7. This should be applicable to other environments and future versions of LexEVS, but some parameters, especially paths, might need to be formatted differently.
This guide will NOT explore how to leverage LexEVS programatically or how to best develop with the Spring framework. The reader is invited to explore the multiple resources on the web that can help in this endeavor.
You will need internet access to complete this guide.
Please follow carefully the steps mentioned in this guide.
Once all the steps have been followed successfully you should have a functional LexEVS Local Runtime instance.
In order to facilitate subsequent testing, please load and activate the test terminology Automobiles.xml located in the folder {LEXEVS_HOME}\test\resources\testData\Automobiles.xml
.
Make note of your installation folder.
Navigate to the Tomcat 6 download page and download the appropriate package for your system. The binary core distribution (zip) is the most usual one.
Unzip the content of the file in the desired folder and make note of it.
Navigate to the STS download page to download the software. Please note that you don't have to fill out the form. If you do not wish to fill it all, just check the checkbox to accept the license terms and click on the link "Download Page" bellow the "Download Now" button.
Choose the appropriate version for your environment and install it. Make sure that you have the Java JDK 1.6 (or less ideally 1.5) installed.
During setup, make sure to make a note of where you installed the program. During step 4, make sure "Apache Maven 2..." in selected.
You can launch STS and select the location of your workspace. You will then be presented with the Welcome page. You can close it with the "x" next to the tab on top left. This will bring a Spring perspective.
Open STS. It should be enabled by default but make sure you're in the Spring perspective. In the left lower corner should be the server view.
You should now see an entry named "Tomcat v6.0 Server at localhost" in the server view.
It might take some time before your back to a responsive Spring perspective. STS will need to download some dependencies for the project.
You should then see your project testlex in the package explorer view on top left part of the windows.
There is a little bug that is annoying in STS regarding missing XML definition. You should see a tiny warning icon on your project and if you drill down, it relates to the file "log4j.xml".
The issue has been described in a Spring forum post but the "Key" that needs to be entered is "//APACHE//DTD LOG4J 1.2//EN" and NOT "//LOGGER" (this changed from the previous STS version).
The solution is:
SpringSource install folder}\sts-2.7.1.RELEASE\plugins\org.apache.log4j_1.2.15.v201012070815.jar
!/org/apache/log4j/xml/log4j.dtd
at the end of the path (without the ")-//APACHE//DTD LOG4J 1.2//EN
(without the ")Once you follow the instructions, you need to add and remove a space to trigger a modification then save the file. The warning should be gone. Do this for both log4j.xml files:
The Spring 3 MVC project being a Maven compliant project, we will add LexEVS as dependency. It is not available in a public repository so we will need to install in our local repository first.
You will need four files to successfully add LexEVS as a dependency.
LEXEVS_HOME}\runtime-components\lexbig.jar
LexEVS POM file: This includes the information on the dependencies LexEVS will rely on. You can download it !Lexevs-6.0.0.pom.zip|thumbnail,width=10px! |
This dependency also has a POM file which you can download !Ddlutils-1.0-PATCHED.pom.zip|thumbnail,width=10px! |
As these Maven dependencies are not available in a public repository, we will need to add them to our local repository.
Open a command window and navigate to the {SpringSource install folder}\maven-2.2.1.RELEASE\bin folder. On windows 7, you can use the file explorer to navigate to this folder and then "Shift+right click" in the folder and select "Open command window here".
Should you have an error message stating the need for a JAVA_HOME system variable when you execute the MVN commands, please follow the appropriate steps for your system to add it (steps provided bellow for Windows 7).
On Windows 7, click on the start button, then right-click on computer and select properties.
Select Advanced system settings in the left pane and select the advanced tab in the window that opens up. Click on Environment Variables button.
Click on the button New in the lower half of the window and add JAVA_HOME as a name and the path to your JRE installation as a value. Click OK 3 times to close the windows. Close and reopen your commmand window and it should now work.
For all the following commands, please change *E:* to the path of the folder chosen to place the four files above.
mvn install:install-file -Dfile="E:\ddlUtils-1.0-PATCHED.jar" -DpomFile="E:\ddlutils-1.0-PATCHED.pom" |
mvn install:install-file -Dfile="E:\lexbig.jar" -DpomFile="E:\lexevs-6.0.0.pom" |
LexEVS currently uses JUnit during runtime. This is a bit unusual and might change in a future release but for now, it needs to be adjusted.
package org.test.test; import static org.junit.Assert.*; import org.LexGrid.LexBIG.Exceptions.LBInvocationException; import org.LexGrid.LexBIG.Impl.LexBIGServiceImpl; import org.LexGrid.LexBIG.LexBIGService.LexBIGService; import org.LexGrid.LexBIG.DataModel.InterfaceElements.CodingSchemeRendering; import org.junit.Test; public class LexBigConnect { @Test public void test() throws LBInvocationException { LexBIGService lbSvc = LexBIGServiceImpl.defaultInstance(); System.out.println("The currently active terminologies are:"); for(CodingSchemeRendering csr : lbSvc.getSupportedCodingSchemes().getCodingSchemeRendering()) System.out.println(csr.getCodingSchemeSummary().getFormalName()); assertTrue(true); } } |
-DLG_CONFIG_FILE="\{LEXEVS_HOME\}\resources\config\lbconfig.props" |
I# n STS, double-click on the "Tomcat v6.0..." entry in the server view (left lower corner).
-DLG_CONFIG_FILE="\{LEXEVS_HOME\}\resources\config\lbconfig.props" |
Although this is unlikely the way in which you will integrate LexEVS in a MVC project, it will confirm that using the project with Tomcat works. This assumes that you have at least one loaded and active terminology in your local LexEVS Server.
package org.test.test; import java.text.DateFormat; import java.util.Date; import java.util.Locale; import org.LexGrid.LexBIG.DataModel.InterfaceElements.CodingSchemeRendering; import org.LexGrid.LexBIG.Exceptions.LBInvocationException; import org.LexGrid.LexBIG.Impl.LexBIGServiceImpl; import org.LexGrid.LexBIG.LexBIGService.LexBIGService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * Handles requests for the application home page. */ @Controller public class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); /** * Simply selects the home view to render by returning its name. * @throws LBInvocationException */ @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) throws LBInvocationException { logger.info("Welcome home! the client locale is "+ locale.toString()); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate ); Integer n = 1; LexBIGService lbSvc = LexBIGServiceImpl.defaultInstance(); for(CodingSchemeRendering csr : lbSvc.getSupportedCodingSchemes().getCodingSchemeRendering()){ System.out.println(csr.getCodingSchemeSummary().getFormalName()); model.addAttribute("term"+n.toString(), csr.getCodingSchemeSummary().getFormalName()); n++; } return "home"; } } |
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page session="false" %> <html> <head> <title>Home</title> </head> <body> <h1> Hello world! </h1> <p>The time on the server is ${serverTime}.</p> <p>One of the active terminologies on the LexEVS server is: ${term1}</p> </body> </html> |
This guide was contributed by the TRANSFoRM group / INSERM U936.