| Subcribe via RSS

Tutorial : Hello EJB3

May 30th, 2008 | No Comments | Posted in Java

After I wrote this article http://www.noppanit.com/?p=90. It’s about EJB2. I wrote it from scratch. So, this article I will be writing about EJB3 and I will write it from scratch as well. To compare??EJB3 with EJB2, I found that EJB3 is a lot more comfortable, but it can’t beat Grails anyway. ^_^. So, let gets start.

First, create a project.

??It will look like this

Create an interface like this

Insert this code inside the interface
@Remote <– It’s an annotation for telling J2EE container that this is RemoteInterface

CODE JAVA
package com.noppanit.ejb.interfaces;
import javax.ejb.Remote;
@Remote
public interface MyBeanFacade {
???????????????????? public String sayHello(String name);
}

Insert this code for MyBean.java
@Stateless <– is for telling J2EE container that this is stateless bean with mappedName=”HelloWorld” this is for Global JNDI For more information

CODE MyBean.java
package com.noppanit.ejb.bean;
import javax.ejb.Stateless;
import com.noppanit.ejb.interfaces.MyBeanFacade;
@Stateless(mappedName=”HelloWorld”)
public class MyBean implements MyBeanFacade
{
???????????????????? @Override
???????????????????? public String sayHello(String name) {
?????????????????????????????????????????? return “Hi “+name;
??????????????????????}
}

That’s it what you should do so for. The next thing is pack the project to .jar file and deploy it to your favorite J2EE container. For this topic I chose Glassfish, because it comes with J2EE package that I installed. You can see that we don’t have to create ejb-jar.xml at all, because this job is done by the power of annotation.

InitialContext context = new InitialContext(); <– // by default this line will look up in jndi.properties, but I’m using Global JNDI. So, we don’t have to create jndi.properties

And this is the code for Stand-alone client

CODE Client
public static void main(String[] args) throws Exception {
??????InitialContext context = new InitialContext();
??????MyBeanFacade bean = (MyBeanFacade)context.lookup(“HelloWorld”);
??????System.out.println(bean.sayHello(“Toy”));
}
Tags: , ,

Tuning : Set heap and perm for OC4J

May 30th, 2008 | No Comments | Posted in Application Server

Go to ${ORACLE_HOME}\opmn\conf\opmn.xml
And Insert “-mx1024m -Doc4j.userThreads=true -XX:MaxPermSize=128″ this parameter is inside??data node and??arrtibute??value. This is not default you??have to set it for every OC4J??instance??you??have created

CODE XML
<process-type id=”home” module-id=”OC4J” status=”enabled”>
???????????????????????????? <module-data>
?????????????????????????????????? <category id=”start-parameters”>
???????????????????????????????????????? <data id=”java-options” value=”-Xrs -server -Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy -Djava.awt.headless=true -Dhttp.webdir.enable=false -mx1024m -Doc4j.userThreads=true -XX:MaxPermSize=128m“/>
?????????????????????????????????? </category>
????????????????????????????????????…
?????????????????????? </process-type>

Windows : Delete a service, by using Registry

May 28th, 2008 | No Comments | Posted in Techniques, Windows

Run Regedit and browse to this… and then delete the service you want

REGISTRY
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services

Basic HTML tab, using javascript

May 28th, 2008 | No Comments | Posted in Web Sites

This will show how to create tabs control in HTML.

CODE JAVASCRIPT
var ids = new Array(‘tab1′,’tab2′) // declare array of tabs

??

CODE JAVASCRIPT
function switchID(id) // function for switch between tabs
{
hideAllID(); // hide all the tabs
showDivID(id); // show the selected tab
}

??

CODE JAVASCRIPT
function hideAllID() // function for hide all tabs in the page
{
for(var i=0;i {
hideDivID(ids[i]);
}
}

??

CODE JAVASCRIPT
function hideDivID(id) // function for hiding the selected tab
{
if(document.getElementById)
{
document.getElementById(id).style.display = ‘none’;
}
}

??

CODE JAVASCRIPT
function showDivID(id) // function for showing the selected tab
{
if(document.getElementById)
{
document.getElementById(id).style.display = ‘block’;
}
}

This is how you are going to create in html files

CODE HTML
<a href=’javascript:switchID(‘tab1′);’>Something1</a>
<a href=’javascript:switchID(‘tab2′);’>Something2</a>

??

CODE HTML
<div id=’tab1′ style=’display:block;’>Content1</div>
<div id=’tab2′ style=’display:none;’> Content2</div>
Tags: , , ,

Oracle Application Server : Error starting JMS-Server

May 27th, 2008 | No Comments | Posted in Application Server

Well, one day I just finished my work. I shutdown the computer. Everything looked nice. But when I came home, and I tried to start my OC4J. It threw me an error, so I couldn’t start my OC4J. I searched through My.Google. And find something that might useful.

If the server has been shutdown properly. Everything works just fine, but if not, the server will write some lock files in the ${ORACLE_HOME}\j2ee\home\persistence\ And the starting process won’t work. So, needless to say, just delete all those files and everything might work so well. At least it did work for me.

Tags: , , ,

Create OC4J instance by using command-line

May 27th, 2008 | No Comments | Posted in Application Server, Knowledges

Because I’m using Oracle Application Server 10.1.3 and I could not find create oc4j instance, So I have to use command-line to create one.

CODE
$ createinstance -instancename yourinstancename

and then enter the password.
That’s it