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 the guide for installing LexEVS 6.0 Local Runtime.
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.
Click on Finish. 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 ")log4j.xml
files:
src/main/resources
src/test/resources
Select the \[textlex\] folder project in the package explorer window then click on play button or click on the menu "Run" \-> Run The next window will ask you how you want to run the project. Select "Run on server". |
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
Unzip it to the same location \[E:\] |
Place it in the same directory \[E:\] |
Unzip it to the same location \[E:\] |
As these Maven dependencies are not available in a public repository, you 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).
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.
Select the project folder \[testlex\] in the Package Explorer view and unfold it. |
Select the \[textlex\] project. Right-click on it and select Maven \-> Add Dependency from the context menu. |
Select and unfold the project folder \[textlex\] in the package explorer. |
Navigate to src/test/java. You should see an empty package \[org.test.test\] |
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); } } |
Select the new button (white rectangle with a little yellow \+) The name of the profile will be defaulted to the name of your class \[LexBigConnect\] |
-DLG_CONFIG_FILE="\{LEXEVS_HOME\}\resources\config\lbconfig.props" |
Then click Apply followed by Run. You should then see a successful completion of a JUnit test. The console log will also show "The currently active terminologies are:" followed by the name of the terminologies \[Automobiles\] if you loaded it. |
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> |
Select the project \[textlex\] in the Package Explorer. |
This guide was contributed by the TRANSFoRM group / INSERM U936.