Sunday, March 23, 2014

JTA Tutorial

Following http://www.javacodegeeks.com/2013/07/spring-jta-multiple-resource-transactions-in-tomcat-with-atomikos-example.html

Installed MySQL and manually created the two databases/tables
When importing downloaded maven project to Eclipse Kepler (JEE) got error. Resolved using http://qussay.com/2013/09/13/solving-dynamic-web-module-3-0-requires-java-1-6-or-newer-in-maven-projects/ (need to right click project and do Maven Update Project.) Note: I also checked "Dynamic Web Module" under Project Facets

Added a run configuration with goal "package" per "Cimbom" - http://stackoverflow.com/questions/9665569/where-did-eclipses-run-as-maven-package-go - need to ensure JRE tab is set to JRE of 1.7 (or else get error: "javac: invalid flag: -s" --probably cuz I had workbench default JRE set to 1.5 duh.)
Ran it it produced springexample.war in target folder root.

Click Servers tab and add Tomcat 7, selected it and click start button. That loads the webapp but doesn't create a springexample under Apache not sure why. would need to start Apache manually (from bin dir) and copy the above war file to webapps.
Load localhost:8080/springexample/appServlet and confirm get "Both employees are inserted!" Verify items are added in MySQL Workbench. Test Rollback scenario per article.


Sunday, March 9, 2014

Tomcat OpenShift Projects

Create new Maven Project in Eclipse
On "Select an Archetype" screen, for filter type "webapp"
select "maven-archetype-webapp" under Artifact Id
Enter a group-id and artifact Id and click finish
Delete the project from Eclipse (but not from hard drive)
open command prompt and go to root of new project (where resides pom.xml)
enter: mvn eclipse:eclipse -Dwtpversion=2.0
Import project into eclipse (kepler java EE)
Open Project properties
under Project Facets change java version to match the system (i.e. 1.7)
Add a Tomcat Server to Eclipse
Under Server Locations ensure "use Tomcat installation" is checked
Set Server path to tomcat server e.g. c:\apache-tomcat-7.0.52
Set Deploy path to C:\apps\apache-tomcat-7.0.52\webapps
Open Modules tab and click Add Web Module
Choose the new project and click ok
Expand Servers and Tomcat v7.0 Server
open file tomcat-users.xml
Add to tomcat-users element:

 <role rolename="manager-gui"/>

<role rolename="admin-gui"/>
<user username="admin" password="admin" roles="admin-gui,manager-gui"/> 

click Debug - Tomcat v7.0 Server at localhost
Open localhost:8080 in the browser
click Manager App (and enter credentials)
scroll to your new web app and click it to show your site

Deploy to OpenShift
in command prompt in openshift app dir (with .openshift, deployments, src, etc.) enter:
 git rm -r src/
in xplorer2, select the src folder of the Eclipse maven project in the left pane and in the right pane have the openshift app dir
click copy to, when prompted allow to merge src.
back in cmd, enter 'git add .' then 'git commit -m "blah"' then git push
Load it in the browser e.g. http://jbossas-<your namespace>.rhcloud.com/<warName>/index.jsp
Now you can modify the eclipse project, e.g. add a main.jsp etc (see http://awgtek.blogspot.com/2014/03/deploy-small-java-app-to-openshift.html) and after each test in local tomcat do another Deploy to OpenShift.

Deploy Struts app to OpenShift? No problem. Set up StrutsExample per http://www.mkyong.com/struts/struts-hello-world-example/
follow same instructions as "Deploy to OpenShift" above, i.e. git delete src and copy src folder from the Struts eclipse tested app. THEN make a change to the pom.xml that exists in the openshift app dir copying over the two dependency elements from StrutsExample for org.apache.struts. git add/commit/push. OpenShift will download the dependencies per the maven pom.xml.