110 likes | 279 Views
Tech-Day. starring: JBoss & EJBs special guest: Tomcat & Servlets. JBoss. Download JBoss from http://www.jboss.org get version 2.4.4 (you don’t need src) Uncompress it to /usr/local/jboss You will need to set the environment variable JAVA_HOME to point to your java directory.
E N D
Tech-Day starring: JBoss & EJBs special guest: Tomcat & Servlets
JBoss • Download JBoss from • http://www.jboss.org • get version 2.4.4 (you don’t need src) • Uncompress it to /usr/local/jboss • You will need to set the environment variable JAVA_HOME to point to your java directory. • Do this in /etc/profile
JBoss cont. • You should now be able to • cd /usr/local/jboss/bin • run.sh • Hopefully everything will come up • Now download my examples from the lecture page.
Building Hello World EJB • Place all java files in a directory ~/HelloBean • Place build.xml in the same directory • Place all other xml files in ~/HelloBean/META-INF • Compile and build the bean
Compiling the bean • Go get ant and install it • http://jakarta.apache.org • Compile all source files together ant compile • javac –d . *.java –classpath … • You will need a few jars in your classpath • JBoss connection jars • /usr/local/jboss/client/*.jar • list each individually • look in build.xml for an example
Building & deploying the bean • Create the bean jar file ant ejb-jar • jar cvf HelloBean.jar * • Deploy the bean ant deploy • cp HelloBean.jar /usr/local/jboss/deploy • At this point, you should see some messages go by from JBoss • [INFO,J2eeDeployer] J2EE application: file:/usr/local/jboss/deploy/HelloBean.jar is deployed.
Running the java client • Compile the java client ant compile • same as compiling the bean • you still need the client jars in your classpath • Run the client ant client • you still need the client jars in your classpath • You should see: client: [java] ClassPath is: C:\JBoss\client\jboss- j2ee.jar;C:\JBoss\client\jaas.jar;C:\JBoss\client\jbosssx- client.jar;C:\JBoss\client\jboss-client.jar;C:\JBoss\client\jnp- client.jar;C:\snell\public_html\TestApps\HelloBean [java] <font color="RED">Hello There From the Bean</font>
Working with servlets • Tomcat needs to see the jboss client jars • place them in /var/tomcat4/lib • Build the servlet ant servlet • you will need to modify some of the paths • Restart tomcat • Go to the servlet url
JBoss and PostgreSQL • You need to tell JBoss about PostgreSQL • edit /usr/local/jboss/conf/default/jboss.jcml <!-- ==================================================================== --> <!-- JDBC --> <!-- ==================================================================== --> … stuff … <mbean code="org.jboss.jdbc.JdbcProvider" name="DefaultDomain:service=JdbcProvider2"> <attribute name="Drivers">org.postgresql.Driver</attribute> </mbean> <mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=PostgresDB"> <attribute name="DataSourceClass">org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl</attribute> <attribute name="PoolName">PostgresDS</attribute> <attribute name="URL">jdbc:postgresql://localhost:5432/yourdb</attribute> <attribute name="JDBCUser">postgres</attribute> <attribute name="Password">postgres</attribute> </mbean>
JBoss & PostgreSQL • JBoss also needs to see your JDBC driver • place it in /usr/local/jboss/lib/ext
JBoss and mysql <mbean code="org.jboss.jdbc.JdbcProvider" name="DefaultDomain:service=JdbcProvider2"> <attribute name="Drivers">org.gjt.mm.mysql.Driver</attribute> </mbean> <mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=mySQLDB"> <attribute name="DataSourceClass">org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl</attribute> <attribute name="PoolName">mySQLDS</attribute> <attribute name="URL">jdbc:mysql://localhost/test</attribute> </mbean>