Saturday, 6 February 2016

How to resolve application war not being deployed properly in JBOSS server

If you see any such following info in the server console

INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found xxx.war in deployment directory. To trigger deployment create a file called xxx.war.dodeploy

Try to create and place a file named xxx.war.dodeploy in deployments folder
say for EAP6.1 on standalone its C:\JBOSS\jboss-eap-6.4\standalone\deployments\

How to Convert Eclipse project to J2EE/Web project

1)  Right click on the Project.
2)  Click Properties
3)  Choose Project Facets
4)  Choose Dynamic web module check box(Choose the required version of it say 3.0/3.1)
5)  Choose Java and provide the required version which supports appropriate dynamic  web module version.

How to resolve Error "Dynamic Web Module 3.1 requires Java 1.7 or newer"

If you see the error while choosing Dynamic web module 3.1 from Project Facets(Right click on the Project and click on properties) then Choose Java (the required version of Java) and then click Apply.

How to add Maven Plugin in Eclipse Helios

Go to Help ==> Install New Software... ==>  Click on Add... button ==> Provide Name as Maven Tools & Location as http://download.eclipse.org/technology/m2e/releases/1.3

How to add Jboss Enterprise Server Tools in Eclipse Helios

Go to Help ==> Choose Install New Software... ==>  Click on Add... button ==> Provide Name as JBoss Tools & Location as  http://download.jboss.org/jbosstools/updates/stable/helios/

Friday, 22 January 2016

How to set up H2 Database in the local windows machine

Latest version of  H2 jar can be downloaded from http://repo2.maven.org/maven2/com/h2database/h2/1.4.190/h2-1.4.190.jar

Place the jar in some folder say c:\lib 

H2 database can be started as mentioned below
Go to the folder where the h2*.jar is present say and type cmd from Eplorer.
It will open up a command prompt 
Then type the command as like below
 C:\lib>java -cp h2-1.4.190.jar org.h2.tools.Server

Then a screen will be opened up in the webbrowser.
Some default values will be present in the username, schema ... 
Provide password as sa and then submit
A screen will be shown with tables and schema on the left pane and on the right pane you can type in the sql queries.









How to connect H2 database with Hibernate?

Create a persistence xml as follows
          Provide the location of the h2*.jar in the value of the property hibernate.connection.url section
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="DefaultPersistenceUnit"  transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:h2:c:/lib/test" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"></property>
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.password" value="sa" />
<property name="hibernate.connection.username" value="sa" />
</properties>
</persistence-unit>
</persistence>

Create an entity as like below

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "VEHICLE")
@NamedQuery(name = "Vehicle.findAll", query = "SELECT b FROM Vehicle b")
public class Vehicle {
@Id
@Column(name = "vehicle_number")
private Integer number;

public String getName() {
return name;
}

@Column(name = "vehicle_name")
private String name;

public Integer getNumber() {
return number;
}

public void setNumber(Integer number) {
this.number = number;
}

public void setName(String name) {
this.name = name;
}

}

Below is Test class to test the Hibernate+H2db connection

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

public class TestHibernate {
public static void main(String[] args) {
Vehicle vehicle= new Vehicle();
EntityManager entityManager = Persistence.createEntityManagerFactory("DefaultPersistenceUnit")
.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(vehicle);
entityManager.getTransaction().commit();
entityManager.close();
}

}


Create a table as like below in the h2 browser window

create table VEHICLE
(
  code NUMBER(3) not null,
  name VARCHAR2(100) not null
)
;