Building an Open Source EJB Server on Windows 2000

4-9-2003
Overview
This guide will use JBoss, Eclipse, and MySQL with other tools to support an EJB Server with a database.
This example will install everything in a directory named NetDB. Note that directory path names are important. Some tools might not work with too long of directory paths, or paths with spaces.

Other Notes:
Adding an Applet
Adding an EJB
Adding a client side bean
CMR Example

The tools that will be used are:
Tool NameVersionDescription
Apache HTTP Server2.0.44A server that can display web pages.
Ant1.5.2A tool like "make" that defines the build sequence.
EASIE1.0.6A plug-in for Eclipse that allows starting and stopping JBoss.
Eclipse2.1.0An integrated devlopment tool that can be used to develop Java applications.
JBoss3.0A server that can load Enterprise Java Beans and can compile JSP into servlets.
JMS1.0.2A Java Messaging Service library.
JUnit3.8.1A tool that is used to test Java code.
MySQL3.23.55An SQL database.
MySQL Connector/J1.5.2A JDBC driver for MySQL.
MySQLCC0.9.1A graphical editor (Control Center) for the MySQL database.
Sysdeo2.0.1A plug-in for Eclipse that allows configuring Tomcat
Sun BDK1.1Bean Developer Kit.
Sun EJB2.1Enterprise Java Bean support.
Sun JDK1.4.1.02A Java Developer Kit.
Tomcat4.1.18A server that can load Java servlets.
XDoclet1.2.2A tool that can read tags from Java source, and create XML files or other source.


Install Appache web server
Download the best available server from Apache. At this date, the file is apache_2.0.44-win32-x86-no_ssi.msi.
Double click to install with the MS Installer.
Change the default installation path from "Program Files" to "NetDB".
I used name www.mynet.org which built ServerName="www.mynet.org:80"
This doesn't work remotely, but this doesn't matter for now.

Clicking on the following should display local appache page on your server.
http://localhost/. You can also use your ip address like "http://xxx.xx.xx.xxx". Run ipconfig from a command line to see your ip address.

Change the following parameters in the conf\http.conf file.
Make directories that match these paths.
Make a "index.html" file in your DocumentRoot directory.
<html>
This is my page
</html>

Restart the server (on the Windows 2000 toolbar system tray). Click on the localhost link to see if it still works.

If you would like to use perl, make a perl file named first.pl and load it. Note that you will have to download perl or php to get things like this to work. Use this link to test it. http://localhost/cgi-bin/first.pl
Check for errors in logs\error.log.
See the ...\Apache Group\Apache2\manual\misc\tutorials.html for more info.

Install Java
Download the best available SDK from Sun. At this date, the file is j2sdk-1_4_1_02-windows-i586.exe.
Install it under D:\NetDB\jdk1.4.1.
Download the best available EJB support from Sun. At this date, the file is ejb-2_1-pfd-api.zip.
Extract it under D:\NetDB\jdkjars.
Download the best available Java Messaging Service from Sun. At this date, the file is jms-1_0_2b.zip.
Extract the jms.jar into D:\NetDB\jdkjars.

Install JBoss and Tomcat
Note that Tomcat does not have to be installed separately.
Download the best available JBoss/Tomcat release from JBoss. At this date, the file is jboss-3.0.6_tomcat-4.1.18.zip.
Extract into "D:\NetDB\JBoss".
For Windows 2000 set environment variables using the "Advanced" tab from the "System" icon in the control panel. If Eclipse is used, then there is no need to set any environment variables. Except that tomcat and JBoss need JDK_HOME to find tools.jar. See below for more info.



Run JBoss with Tomcat by running run.bat in the JBoss\bin directory. Note that Apache must also be running. Test with: http://localhost:8080/jmx-console. A JBoss screen should display.

Install Ant
Download the best available Ant release from Apache. At this date, the file is apache-ant-1.5.2-bin.zip. Extract it under D:\NetDB\Apache Group. Set ANT_HOME environment variable to D:\NetDB\Apache Group\apache-ant-1.5.2.

Install JUnit
Download the best available JUnit from JUnit.org. At this date, the file is junit3.8.1.zip.
Extract it under D:\NetDB\JUnit3.8.1.
Change the CLASSPATH environment variable and add D:\NetDB\junit3.8.1.

Install Eclipse, EASIE and Sysdeo
Download the best available Eclipse from http://www.eclipse.org/. At this date, the file is eclipse-SDK-RC2-win32.zip.
Extract it under D:\NetDB\.

Download the best available JBoss plugin from EASIE. At this date, the file is EASIEJBoss1.0.6.zip.
Extract it under D:\NetDB\Eclipse. This should add two more directories under the Eclipse plugins directory.
Change the Window Preferences-JBoss, Optional Program Arguments from catalina to "-c default".
Add D:\NetDB\jdk1.4.1\bin to path (for JavaDoc)

The following Sysdeo plugin instructions are not required to run the JBoss Template example. These can be skipped. They do allow control of Tomcat from Eclipse.
Download the best available Tomcat plugin from Sysdeo. At this date, the file is TomcatPluginV201.zip.
Extract it under D:\NetDB\Eclipse\plugins. This should add one directory under the plugins directory.
The plugin options can be turned on under Window-Customize Perspective.
Change the Window Preferences-Tomcat and choose Version 4.1.x. Change the Tomcat home to the correct location under JBoss. Add the projects to the classpath.
Under JVM Settings, add the tools.jar classpath.

You may have to make a shortcut to eclipse to start like: D:\NetDB\eclipse\eclipse.exe -vm d:\netdb\jdk1.4.1\bin\javaw.exe

Install XDoclet
Download the best available XDoclet from http://xdoclet.sourceforge.net/. At this date, the file is xdoclet-1.2.2.zip.
Extract it under D:\NetDB\XDoclet.


Install JBoss template example
Download the best available template from http://prdownloads.sourceforge.net/jboss/JBoss.3.0TemplateAndExamples.zip. At this date, the file is JBoss.3.0Template.Project.zip.
Install under D:\NetDB\JBoss\
Some of the following may not be necessary using Eclipse. See Build JBoss template below.
For more info, see the readme.txt instructions. Use command prompt to copy .ant.properties. Add junit.home=d:/NetDB/JUnit3.8.1 and correct xdoclet.home=d:/NetDB/XDoclet and jboss.home=d:/NetDB/JBoss. Make build.bat file that calls %ANT_HOME%\bin\ant and put into template directory if you would like to build the example at the command line.

Build JBoss template
Make a new java project in Eclipse. Point the directory to the top template directory.
Use Window-Show View to show Ant. Right click in the Ant window and choose Add Build File. Choose the build.xml file in the template directory.

If compiling displays an error, "TestEntityBean.java:18: cannot resolve symbol", "symbol : class SequenceGenerator", then simply build the target again.
If running JBoss displays an error about an already used port such as "java.net.BindException: Address already in use: JVM_Bind", "java.rmi.server.ExportException: Port already in use", kill javaw in the task manager. You may have to stop Eclipse to do this.
If running JBoss displays an error "Error compiling file", "Exception compiling Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath.", then edit the file d:\netdb\eclipse\workspace\.metadata\ .plugins\com.genuitec.eclipse.easie.jboss and set JDK_HOME to the proper path.

Use Window-Preferences and select Ant. Set the Runtime Additional classpath entries and browse and add sunjdk..\lib\tools.jar, xdoclet..\lib\xdoclet.jar, and jboss..\servers\default\lib\log4j.jar.
Create a "myhide" directory under the ant/lib directory. Move the xerxesImpl.jar and xml-apis.jar from the ant/lib directory into the ant/lib/myhide directory. Then in the ant preferences in Eclipse, browse and set ANT_HOME.
Select the Project-Properties-Libraries, and add both the jdkjars jar files. Also add the tools.jar file from the jdk. This contains the javac compiler.

Fix the Java JBoss template source code. Whereever there is a compile error in the source code, add the prefix "javax.ejb." to the entity that is not defined.
Comment out the javax.mail. code.
Prefix "MessageListener" with "javax.jms.".

No errors should be shown in the Eclipse console when starting JBoss from Eclipse. Some warnings may appear.

The JBoss server can be configured to load jars from other places than the lib directory. For example, they can be loaded from the deploy directory. To do this, add another classpath element to the jboss-service.xml file. There will then be two classpath elements as below:
  <classpath codebase="lib" archives="*"/>
  <classpath codebase="deploy" archives="*"/>

Finally, the following link will display a page that says: "The next ID of a Test Entity is": and then a number that increments every time the page is refreshed. http://localhost:8080/web-client

Install MySQL
Download the best available MySQL server from MySql.org. At this time, the file is mysql-3.23.55-win.zip.
If you ever want to run MySQL as a server, create a file named C:\MY.CNF.
Add the following lines to MY.CNF.
[mysqld]
basedir=D:/NetDB/MySQL
datadir=D:/NetDB/MySQL/Data

Run Setup.exe.
Run mysql/bin/winmysqladmin. Enter a user name of mysql, and a password of mysql. Right click on its icon in the system tray and click "Show Me". Right click on the icon in the program and click "Hide Me".
Start a command prompt and run D:\NetDB\MySQL\bin\mysql -u mysql -p. Enter mysql for the password. Try "select user();" or "select 1+1". Then create a JBossDB database using "create database JBossDB".

If a graphical editor for MySQL is needed, then download and install the MySQLCC program from the MySQL site.

Download the best available MySQL Java connector from http://www.mysql.com/downloads/api-jdbc-stable.html. At this time, the file is mysql-connector-java-3.0.6-stable.zip.
Extract to D:\NetDB\MySql\ConnectorJ.

Hookup JBoss to MySQL
Edit the file jboss\server\default\conf, and change the lines
from <datasource>java:/DefaultDS</datasource>
<datasource-mapping>Hypersonic SQL</datasource-mapping>
to <datasource>java:/MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>. Also change standardaws.xml in the same directory in the same manner.
Copy the mysql-service.xml from the jboss/docs/examples/jca directory to the jboss/server/default/deploy directory.

Copy the mysql-connector-java*.jar from the mysql/ConnectorJ directory into the jboss/tomcat-4.1.x/common/lib directory.

Change the mysql-service.xml line "jdbc:mysql://dell:3306/jbossdb" to "jdbc:mysql://localhost:3306/test". This will use the database "test" on the localhost machine. Copy the xml from the mysql-service.xml file into the jboss/server/default/conf/login-config.xml file under the <policy> xml element. Change the yourprincipal, yourusername and yourpassword to mysql.
Change the ant.properties file lines to "type.mapping=mySQL" and "datasource.name=java:/MySqlDS"

Change template example to use MySQL
Edit the SequenceGeneratorBean.java code.
Change the ejb tags to:
 * @ejb:env-entry name="DataSource_Name"
 *                value="MySqlDS"
 * @ejb:resource_ref res-name="jdbc/MySqlDS"

Change the aJNDIContext.lookup to aJNDIContext.lookup("java:/MySqlDS").

No errors should be shown in the Eclipse console when starting JBoss from Eclipse. Some warnings may appear. After JBoss has started, run the following link. http://localhost:8080/web-client

Tips

Finished
Now that your environment is set up, you can start modifications.
Add Applet

Path/Jar References
The following is some information about how paths affect the template example.
OptionFeaturesPath Files Modified
Eclipse -vm command line switch May be required for Eclipse package explorer eclipse/workspace/.metadata/.plugins/org.eclipse.jdt.core/pref_store.ini eclipse/workspace/.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml eclipse/workspace/.metadata/.plugins/org.eclipse.jdt.launching/pref_store.ini
Eclipse Window Preferences-Ant-Runtime for Tools.Jar Required for Eclipse Ant build eclipse/workspace/.metadata/.plugins/org.eclipse.ant.core/pref_store.ini eclipse/workspace/.metadata/.plugins/org.eclipse.core.resources.../state.dat eclipse/workspace/.metadata/.plugins/org.eclipse.ui.externaltools/dialog_settings.xml eclipse/workspace/.metadata/.plugins/org.eclipse.core.resources.../state.dat
Running JBoss template ant build after ant runtime settings ok JBossTemplate/build/bin/run-client.bat JBossTemplate/build/bin/run-client.sh
Running JBoss Finding jars jboss-service.xml
Eclipse Project Properties for JMS.JAR Required for Eclipse package explorer eclipse/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/JBoss Template/org.eclipse.jdt.core/state.dat JBossTemplate/.classpath
Hosted by www.Geocities.ws

1