Openxava 2017 - Eclipse + Tomcat + Mysql

10761 read •  •  Posted in  •  Share


This time I will show you how to use the fast development framework: Opexava. This framework is very interesting since it can be a fast solution for projects with no time, for demos, even for business projects. As everything has its advantages and disadvantages. Let’s begin!!

Requirements:

How it works?

Openxava convert java pojos to java web application.

openxava-pojo

Basics Concepts:

Business Component

The main part OpenXava are the business component. In the Openxava world, business component is a java class with jpa annotations.

Controllers

A controller is a set of actions. An action could be a button or hyperlink which user could be use.

Application

An application is a set of modules. A module is a business component with one or more controllers.

In this post, We are going to create a java web application (war file) and deploy it in tomcat server.

Steps

1.- Create Openxava Project from Template.

Download openxava zip from http://www.openxava.org/es/downloads and unzip it. It should look like:

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/openxzava-zip_orig.png

Using eclipse open the workspace folder. It should look like:

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/openxava-eclipse_orig.png

So now, in order to create a new project, we execute an ant task called CrearNuevoProyecto.xml located inside of OpenXavaTemplate project

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/crear-nuevo-proyecto_orig.png

Enter some name of application. In this case : “Empresa”

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/ant-input_orig.png

After some minutes, a nre project called Empresa is ready to use due to openxava engine. Select this new project and F5

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/new-emtpy-project_orig.png

2.- Java Entities

Firs we need create a package. If my application is empresa, a common package could be : org.empresa.model or com.empresa.model. After that , we need a new java class. In this example : Cliente.java

This class will become in a module

3.- Database configuration

Only this files should be changed:

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/modificar-openxava_orig.png

Persistence.xml

hibernate.cfg.xml

build.xml

Descargamos el driver de coneccion para nuestra base de datos. Para este ejemplo usaremos mysql.(Requisito numero 4) Luego en el archivo build, en el tag : seteamos la ruta de este jar descargado:

Download mysql driver (#4 requirement). After that, update tag whit file path of mysql driver.

This step is only to : database tables creation. In deployment stage, this jar file should be added to application or tomcat server.

context.xml

Add a new datasource in context.xml file, located inside conf tomcat folder :

Files should look like :

4.-Tables creation from java model

  • Create a new scheme in database called empresa. This scheme should be same as used in persistence.xml , hibernate.cfg.xml and context.xml
jdbc:mysql://localhost:3306/empresa
  • Start mysql and execute ant task called : updateSchema. Right click in build.xml > run as > ant build … and select “update schema”

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/actualizar-esquema_orig.png

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/build-actualizar-esquema_orig.png

If no errors, console look like:

https://gist.github.com/jrichardsz/6964217

Go to your database and new tables appear.

5.- Build artifact : .war

As default, Openxava has configured an ant task to directly deploy the project. Openxava has its own tomcat inside downloaded zip:

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/openxava-tomcat_orig.png

This is good for a demo but for real environments we need an artifact in order to deploy it in some server.

To do that, we need to change build.xml file and enable target=”deployWar” task:

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/actualizar-esquema_orig.png

Now execute deployWar ant task. Right click in build.xml > run as > ant buil …

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/openxava-desplegar-war_orig.png

If no errors, console look like:

https://gist.github.com/jrichardsz/6959755

We can see the war file path in log :

[jar] Building jar: \..\openxava_download\workspace.dist\Empresa.dist\Empresa.war

Note: This way need 3 jars : ejb.jar, jta.jar y mysql-connector-java-5.1.18.jar

We have two choices:

  • Unzip our war file and add this jars to WEB-INF\lib folder.

  • Add this jar in tomcat server (lib folder)

Deploy web application

Finally, we deploy our war file as any java web application. In tomcat case, copy war file to webapps folder:

..\..\apache-tomcat-7.0.39\webapps

and execute startup.bat located in

..\..\apache-tomcat-7.0.39\bin

if all is good, no errors in tomcat appear.

7.-Access to web application:

URL could be something like this:

http://<app-server-host>:<port-app-server>/<eclipse-project-name>/modules/<name-of-java-class>

In our case:

http://localhost:8080/Empresa/modules/Cliente

And in browser:

http://jrichardsz.weebly.com/uploads/2/3/2/4/23244862/openxava-browser_orig.png

Tomcat log look like:

https://gist.github.com/jrichardsz/6964425

War of this post could be downloaded from:

https://github.com/jrichardsz/videotutoriales/blob/master/000016/resources/workspace/Empresa.rar

So after all, we have a CRUD application ready to use!!

HTH.

System.exit(0)


Until the next,
Richard Osmar Leon Ingaruca

Richard Osmar Leon Ingarucas-signature