2. Creating a Tomcat Server for Cortex API
2. Creating a Tomcat Server for Cortex API
Make sure you have the wtp-developer profile activated in your Maven settings.xml file. If wtp-developer is not active, activate the wtp-developer profile and rebuild your project by running mvn clean install in your Elastic Path root directory. The rebuild applies the changes made to settings.xml.
Creating a Tomcat Server in Eclipse for the Cortex API
You must add the Cortex API as an External Web Module in Eclipse and add the Search Sever and ActiveMQ-broker as an regular Web Module. Search is required for Cortex API's search capabilities and ActiveMQ-broker is required to submit an order complete message when finalizing purchases. For more information on these web applications, see the Commerce Engine Developer Guide: https://docs.elasticpath.com/display/EP/Elastic+Path+Documentation
To create a Cortex API Tomcat server in Eclipse:
- In Eclipse, choose File -> New -> Other.
- In the list of wizards, select Server -> Server and click Next.
- In the server type list, expand Apache, select your Tomcat version and click Next.
- Click Browse and locate the your root Tomcat directory.
- In the JRE drop-down list, select jdk1.7.0_21 and click Next.
- Select ep-search-webapp and activemq-brokerand click Add.
- Click Finish.
- In the Servers tab, double-click your application server to display the server's Overview tab.
- Click Modules.
- Click Add External Web Module...
- Add the Cortex API web application: Document base: <ExtensionDirectory>\commerce-api-webapp\target\commerce-api-webapp-1.0-SNAPSHOTPath: /cortex
- In Eclipse's package explorer, open Server\<Your Server Name>\context.xml
- In context.xml, insert the following code before the </Context> tag:
<Resource auth="Container" name="mail/Session" type="javax.mail.Session"/commerce-legacy/> <Resource name="jdbc/epjndi" auth="Container" scope="Shareable" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" username="USER" password="PASSWORD" driverClassName="DRIVER" url="JDBC_URL" /> <Resourceauth="Container"name="jms/JMSConnectionFactory" type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory" factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="tcp://127.0.0.1:61616"/commerce-legacy/>
- In context.xml, replace the following:
- USER and PASSWORD with the account that can access your database
- DRIVER with the JDBC Driver that corresponds to your DBMS and JDBC_URL with
your Database Connection URL:
- In the Servers tab, right click your server, select Clean... and click OK.
- In the Servers tab, right click your server and select Publish.
- Click Finish.
Configuring the Tomcat Server
- In Eclipse, choose Window -> Show View -> Other.
- Select Server -> Servers and click OK.
- Click the Servers tab.
- In the Servers tab, double-click the server you just created to display the server's Overview tab.
- Expand Timeouts, set Start to 180 and set Stop to 60.
- Under Server Locations, make sure Use workspace metadata is selected.
- Under General Information, click Open launch configuration.
- Click the Arguments tab and add the following arguments to the end of the VM arguments.
-Xmx1024m -XX:MaxPermSize=512m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:CompileCommand=exclude,org/apache/velocity/runtime/directive/Foreach,render
If you are developing with Cortex API, add -ea to the VM argument shown above. This turns assertions on, which Cortex API's code uses. Be aware assertions may cause issues if they are enabled for the other web applications.
Adding Cortex Studio to the Tomcat Server
- In Eclipse's package explorer, open Server\<Your Server Name>\server.xml
- In server.xml, insert the following code before the </host> tag:
<Context path="/commerce-legacy/studio" docBase="C:\EP-rel\Cortex\Tools\Learning the API\CortexStudio.war" cachingAllowed="false"> <Resource auth="Container" name="mail/Session" type="javax.mail.Session"/commerce-legacy/> <Resource name="jdbc/epjndi" auth="Container" scope="Shareable" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" username="USER" password="PASSWORD" driverClassName="DRIVER" url="JDBC_URL" /> </Context>
- In the server.xml, replace the following:
- docBase with the location of your Cortex Studio WAR
- USER and PASSWORD with the account that can access your database
- DRIVER with the JDBC Driver that corresponds to your DBMS and JDBC_URL with your Database Connection URL:
- In the Servers tab, right click your server, select Clean... and click OK.
- In the Servers tab, right click your server and select Publish.
- Click Finish.