============= Few quick reminders: 1) Never run j2ee, any of its tools, or cloudscape database as root (at least for the installation described before) 2) Log in as j2ee and run everything as this user. 3) In the /home/j2ee/bin directory there are some utility scripts to start/stop/check start_j2ee -- starts cloudscape database and j2ee server stop_j2ee -- starts cloudscape database and j2ee server check_j2ee -- lists cloudscape and j2ee server if they run 4) Try not to kill j2ee or cloudscape. Use the scripts above, or the original commands: cloudscape -stop j2ee -stop 5) You can clean up ALL INSTALLED APPLICATION/BEANS and start again by typing: cleanup This may be useful at the learning stage. =============== Now the details ============ Retrieved latest greatest JDK 1.3.1 from java.sun.com (j2sdk-1_3_1-solsparc.sh) and run it in a temp directory to see what does it do. mkdir /tmp/j2sdk-1_3_1 cp .../j2sdk-1_3_1-solsparc.sh /tmp/j2sdk-1_3_1 cd /tmp/j2sdk-1_3_1 chmod 755 j2sdk-1_3_1-solsparc.sh ./j2sdk-1_3_1-solsparc.sh This created a directory j2sdk1_3_1 as JAVA_HOME I moved it to to /usr/local mv /tmp/j2sdk-1_3_1/j2sdk1_3_1 /usr/local I created a user called j2ee which was running Bourne like shell (in my case it was ksh) and whose home directory was /home/j2ee: As root I did: groupadd -g 2611 j2ee useradd -u 2611 -g 2611 -s /bin/ksh -d /home/j2ee -m -c 'J2EE Tree Owner' j2ee passwd j2ee Then created the top directory for j2ee distribution and chowned it to j2ee user: I went to http://java.sun.com, clicked on developer connection, and chosen Early Access Downloads from the left navigation bar. Logged in (if you are not a member of Development Connection, you can register -- it is free). I downloaded Java 2 SDK, Enterprise Edition 1.3 Beta Release (Feb 8, 2001) for Solaris sparc: j2sdkee-1_3-beta-solsparc.sh and the documentation j2sdkee-1_3-beta-doc-solsparc.zip to the directory /usr/local/j2ee1.3b I also did (as root): chown j2ee /usr/local/j2ee1.3b chgrp j2ee /usr/local/j2ee1.3b cd /usr/local/j2ee1.3b chmod 755 j2sdkee-1_3-beta-solsparc.sh mkdir /usr/local/j2sdkee1.3 chown j2ee /usr/local/j2sdkee1.3 chgrp j2ee /usr/local/j2sdkee1.3 You need to get both the kit and the docs, since kit is not bundled with docs. I unpacked them as user j2ee: cd /usr/local/j2ee1.3b ./j2sdkee-1_3-beta-solsparc.sh unzip j2sdkee-1_3-beta-doc-solsparc.zip cd j2sdkee1.3 mv * /usr/local/j2sdkee1.3 rmdir j2sdkee1.3 Since I already run an Apache web server on this machine, I made a symbolic link to the doc subdirectory from the document root of my Apache server: My $DocumentRootOfMyApache was /usr/local/apache_1.3.14/htdocs cd $DocumentRootOfMyApache ln -s /local/j2sdkee1.3/doc doc And then I could view the documents as: http://heechee.ccl.net:5180/doc I Looked at: http://developer.java.sun.com/developer/earlyAccess/j2ee/install.html Basically, it tells you the same stuff I am telling you. I created the following .profile script in /home/j2ee to set my CLASSPATH and PATH environment variables: -------------------------------------------------- #!/bin/ksh umask 002 set -o ignoreeof set -o emacs HOST=`hostname` export HOST JAVA_HOME=/usr/local/j2sdk1_3_1 J2EE_HOME=/usr/local/j2sdkee1.3 export JAVA_HOME J2EE_HOME CLASSPATH=${JAVA_HOME}/lib/tools.jar CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/dt.jar export CLASSPATH PATH=/usr/local/bin:${JAVA_HOME}/bin:/usr/bin:/usr/X11R6/bin PATH=${PATH}:/usr/openwin/bin:/home/j2ee/bin:${J2EE_HOME}/bin:. export PATH ------------------------------------------------------------ Then I logged out and in (rather than do . profile), to make sure that it does what I want. Note, I did not put the JSSE and JCE into the CLASSPATH. It seems that J2EE SDK has these classes already included in the j2ee.jar. Frankly, I hate the way it is organized that all classes go into one BIG (8Mb) jar file. When I want to replace the Tomcat 4.0beta1 with current version, I have to pack and unpack tars.... I did not edit any files and left everything at defaults (the way to go with betas...). Then I looked at: http://heechee.ccl.net:5180/doc/release/ConfigGuide.html but hold my temptation of changing anything. =========================== The J2EE SDK comes with a number of tools. They are located in the $J2EE_HOME/bin directory: cleanup -- a script which undeploys all deployed applications from J2EE server. At the learning stage, this is a used very often. Just do: $J2EE_HOME/bin/cleanup and you feel fresh and clean... deploytool -- X window GUI for deploying EJB applications To start a GUI mode do: deploytool or deploytool -ui The problem with GUI mode is that if you have the J2EE running on remote server, it takes some time to transfer pixels back and for. You may consider command line options to avoid this: It also has command line options like: a) listing all installed applications: deploytool -listApps ServerName for example: deploytool -listApps heechee.ccl.net b) uninstalling particular application: deploytool -uninstall ApplicationName ServerName for example: deploytool -uninstall petstore heechee.ccl.net c) installing particular application: deploytool -deploy SomeApplEarFile ServerName [SomeClientJar] where the optional SomeClienJar is an optional .jar file of a stand-alone Java application client. For example: deploytool -deploy /home/j2ee/jps1.1.2/petstore.ear \ heechee.ccl.net d) printing help on usage: deploytool -help e) deploying/undeploying connectors deploytool -(un)deployConnector RarFile ServerName cloudscape -- a database written in Java. It is started as: cloudscape -start & and stopped as: cloudscape -stop Before you start the j2ee server, you need to start the database. You probably need to shutdown the j2ee server before you stop cloudscape j2ee -- J2EE server. It is a command line script with following options: a) Show version: j2ee -version b) Start the j2ee server and send logging output to the terminal rather than file: j2ee -verbose & c) Stop the server j2ee -stop keytool -- creates selfsigned X509 certificates. This is different from the keytool which comes with J2SE (the standard edition java SDK) since it automatically adds the JCE. packager -- command line tool which helps you package components: .jar files for EJBs .war for web application .jar for application client .rar resource adapyer file. realmtool -- allows you to add and remove users, and to import certificate files a) show all realm names realmtool -show b) list users in the specific real realmtool -list RealmName c) add user to default(?) realm realmtool -add username password group1[,group2,...] d) adds a group to default realm realmtool -addGroup group e) imports certificate file realmtool -import Certificate -alis Name f) removes user from the realm realmtool -remove RealName UserName runclient -- runs a J2EE application client runclient -client ApplicationJar [-name Name] arguments verifier -- validates J2EE component files: .ear application files .jar EJB, client .war Web component It can be run from within deploytool, as command-line, or as GUI. a) verbose output verifier -v b) write results ri iyroyr file rather than Results.txt verifier -o OutputFile c) run as GUI verifier -u d) report level: verifier -a #all verifier -w #only warnings veryfier -f #failures only (default warnings and failures are reported). ------------------------- I went to $J2EE_HOME/bin and removed x privilege from others and group, so only j2ee can run these scripts. cd $J2EE_HOME/bin chmod go-x * Now is the time to make the startup and shutdown script. Since it was a rush installation, I did not have time to do it righ with pid file, etc. I created 2 scripts in $J2EE_HOME/bin 1) startup.sh -------------------------------------------------- #!/bin/ksh JAVA_HOME=/usr/local/j2sdk1_3_1 J2EE_HOME=/usr/local/j2sdkee1.3 export JAVA_HOME J2EE_HOME CLASSPATH=${JAVA_HOME}/lib/tools.jar CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/dt.jar export CLASSPATH PATH=/usr/local/bin:${JAVA_HOME}/bin:${J2EE_HOME}/bin:/usr/bin:/usr/X11R6/bin PATH=${PATH}:/usr/openwin/bin:/home/j2ee/bin:. export PATH echo `date` starting cloudscape >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 nohup ${J2EE_HOME}/bin/cloudscape -start >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 & sleep 2 echo `date` starting j2ee server >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 nohup ${J2EE_HOME}/bin/j2ee -verbose >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 & --------------------------------------------------- then did chmod 744 startup.sh 2) shutdown.sh ----------------------------------------------------------- #!/bin/ksh JAVA_HOME=/usr/local/j2sdk1_3_1 J2EE_HOME=/usr/local/j2sdkee1.3 export JAVA_HOME J2EE_HOME CLASSPATH=${JAVA_HOME}/lib/tools.jar CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/dt.jar export CLASSPATH PATH=/usr/local/bin:${JAVA_HOME}/bin:${J2EE_HOME}/bin:/usr/bin:/usr/X11R6/bin PATH=${PATH}:/usr/openwin/bin:/home/j2ee/bin:. export PATH echo `date` stopping j2ee server >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 nohup ${J2EE_HOME}/bin/j2ee -stop >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 & sleep 3 echo `date` stopping cloudscape >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 nohup ${J2EE_HOME}/bin/cloudscape -stop >> ${J2EE_HOME}/logs/heechee.ccl.net/j2ee/j2ee/startup.log 2>&1 & ---------------------------------------------------------- then did: chmod 744 shutdown.sh then tried them as user j2ee They, seemed to work. I then added a script to start them on boot-up: I bacame a root. and created the script /etc/init.d/j2ee.osc ---------------------------------- #!/bin/sh # # Start/stop the j2ee server # # J2EE_HOME=/usr/local/j2sdkee1.3 case "$1" in start) echo "Starting J2EE server as user j2ee: \c" su - j2ee -c "$J2EE_HOME/bin/startup.sh" ;; stop) echo "Stopping J2EE server as user j2ee: \c" su - j2ee -c "$J2EE_HOME/bin/shutdown.sh" ;; *) echo "Usage: /etc/init.d/j2ee.osc start|stop"; exit 1 ;; esac exit 0 ------------------------------------------------ Then did chmod 755 j2ee.osc Then tried it as root as: /etc/init.d/j2ee.osc start /etc/init.d/j2ee.osc stop Then I created links in /etc/rc3.d directory ln -s ../init.d/j2ee.osc S97j2ee ln -s ../init.d/j2ee.osc K27j2ee which will start/kill j2ee server on boot/shutdown ------------------------------------------------- ------------------------- Installed Pet Store example: Retrieved the latest PetStore EJB demo from java.sun.com (jps-1_1_2.zip size 2985459). I unplacked it in the j2ee home directory: unzip jps-1_1_2.zip which created a bunch of files under /home/j2ee/jps1.1.2 I linked the docs directory to the DOCUMENT_ROOT of my webserver as beforeL as root: My $DocumentRootOfMyApache was /usr/local/apache_1.3.14/htdocs cd $DocumentRootOfMyApache ln -s /home/j2ee/jps1.1.2/docs jps-docs And then I could view the documents as: http://heechee.ccl.net:5180/jps-docs Then I was following the http://mymachine/jps-docs/jps/install.html document: Logged in as user j2ee cloudscape -start & # note the &, the doc does not show it. j2ee -verbose & It gave me this: J2EE server listen port: 1050 Naming service started:1050 Binding DataSource, name = jdbc/Cloudscape, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true Binding DataSource, name = jdbc/DB1, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true Binding DataSource, name = jdbc/DB2, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true Binding DataSource, name = jdbc/InventoryDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true Binding DataSource, name = jdbc/EstoreDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true Binding DataSource, name = jdbc/XACloudscape, url = jdbc/XACloudscape__xa Binding DataSource, name = jdbc/XACloudscape__xa, dataSource = COM.cloudscape.core.RemoteXaDataSource@de462 Starting JMS service ... Initialization complete - waiting for client requests Binding : < JMS Destination : jms/Topic , javax.jms.Topic > Binding : < JMS Destination : jms/Queue , javax.jms.Queue > Binding : < JMS Cnx Factory : QueueConnectionFactory , Queue , No properties > Binding : < JMS Cnx Factory : jms/TopicConnectionFactory , Topic , No properties > Binding : < JMS Cnx Factory : TopicConnectionFactory , Topic , No properties > Binding : < JMS Cnx Factory : jms/QueueConnectionFactory , Queue , No properties > Starting web service at port:8000 Starting secure web service at port:7000 Apache Tomcat/4.0-b1 Starting web service at port:9191 Apache Tomcat/4.0-b1 J2EE server startup complete. Then I used the deploytool in the command line mode (rather then GUI): deploytool -deploy /home/j2ee/jps1.1.2/petstore.ear heechee.ccl.net It created a lot of output with the last 2 lines: Remote message: Deployment of petstore is complete.. Sender object Deploy Tool : client code at http://192.148.248.32:9191/petstoreClient.jar ========================= Playing with Pet Store I checked if petstore is deployed: deploytool -listApps heechee.ccl.net The following apps are deployed on heechee.ccl.net: petstore =========================== So far so good. I used my browser and zoomed on: http://heechee.ccl.net:8000/estore/index.html Still fine. I clicked on the link "Enter the store:" http://heechee.ccl.net:8000/estore/populate?command=checkTables&redirect=/control/language%253Flanguage%253DEnglish and got page which complained avut tables: The tables necessary to run the Java Petstore Application are not installed. Please select the "Install Tables" link on the banner. So I clicked on Install Tables: and it brough me to the page: Install Cloudscape tables (Recommended Based on Configuration) Install Oracle tables Install Sybase tables I clicked on the "Install Cloudscape tables" and tables were installed automagically. I understand that before you can run Pet Store, you need to have a store, i.e., some entries representing inventory, orders, etc., etc., in the database. Then, I clicked on "Return to Pet Store Demo" and got a nice picture of pets, categories, search, etc. I clicked on Sign-in in upper right corner, and got to sign-up page, I went back and clicked on Fish, Then angel fish, and added it to my cart. Then proceeded to checkout. It then asked me for names/addresses and cardnumbers. I ended up buying fish. ================================================= I. Now I wanted to add some EJB on my own... ----------------------------------------- So I visited the directory: ${J2EE_HOME}/doc/guides/ejb/examples I started from "Getting Started", Chapter 2 in the J2EE Developer's Guide (Guide is available from: http://heechee.ccl.net:5180/doc/guides/ejb/html/DevGuideTOC.html); Created a directory /home/j2ee/test I will be putting there all my successes and failures Started with converter: mkdir /home/j2ee/test/converter 1) Remote interface. Copied the /usr/local/j2sdkee1.3/doc/guides/ejb/examples/converter/Converter.java to /home/j2ee/test/converter 2) Then I grabbed the Home interface cp /usr/local/j2sdkee1.3/doc/guides/ejb/examples/converter/ConverterHome.java /home/j2ee/test/converter 3) I then copied the converted stateless enterprise bean: cp /usr/local/j2sdkee1.3/doc/guides/ejb/examples/converter/ConverterEJB.java /home/j2ee/test/converter 4) Now, I creted a script to compile the EJBs ------------------------------- #!/bin/ksh JAVA_HOME=/usr/local/j2sdk1_3_1 J2EE_HOME=/usr/local/j2sdkee1.3 export JAVA_HOME J2EE_HOME CLASSPATH=${JAVA_HOME}/lib/tools.jar:${JAVA_HOME}/jre/lib/rt.jar CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/dt.jar:${J2EE_HOME}/lib/j2ee.jar:. export CLASSPATH PATH=/usr/local/bin:${JAVA_HOME}/bin:${J2EE_HOME}/bin:/usr/bin:/usr/X11R6/bin PATH=${PATH}:/usr/openwin/bin:/home/j2ee/bin:. export PATH javac $@ --------------------- and saved it as /home/j2ee/bin/cb then made it executable: chmod 755 /home/j2ee/bin/cb Then, I did: cd /home/j2ee/test/converter cb * which is equivalent to cb Converter.java ConverterEJB.java ConverterHome.java in this case (I have only 3 files in this directory at this moment). This created 3 new files and my /home/j2ee/test/converter is now: $ ls -l total 12 -rw-rw-r-- 1 j2ee j2ee 263 May 28 11:47 Converter.class -rwxr-xr-x 1 j2ee j2ee 438 May 28 11:36 Converter.java -rw-rw-r-- 1 j2ee j2ee 666 May 28 11:47 ConverterEJB.class -rwxr-xr-x 1 j2ee j2ee 733 May 28 11:40 ConverterEJB.java -rw-rw-r-- 1 j2ee j2ee 276 May 28 11:47 ConverterHome.class -rwxr-xr-x 1 j2ee j2ee 432 May 28 11:39 ConverterHome.java ----------- II. Now, I will be trying to create the J2EE application. ----------------------------------------------------- a) Starting j2ee server. I use my script startup.sh in ${J2EE_HOME}/bin to do this (as user j2ee): ${J2EE_HOME}/bin/startup.sh b) Since I am working on my linux laptop, and the J2EE server runs on remote machine, I need to use the X-Window remote DISPLAY to see the deploy tool. I have two xterms opened on my laptop. On one I am logged in to my local laptop, and on the other I am logged in to the remote server machine: heechee.ccl.net. Do not try it on a slow modem. I am using cable modem, and it takes forever. There are command line tools to do the same thing, but I am learning here, OK? If you are sitting in front of the machine where the J2EE server is running, you just need to type: deploytool & If you are working from other machine, do the following: i) in my local laptop xterm (mylaptop.aaa.bbb.com) I say xhost +heechee.ccl.net ii) in the xterm looged in to heechee as user j2ee, I say: DISPLAY=mylaptop.aaa.bbb.com:0 export DISPLAY deploytool & This displays a lot of missing fonts warnings Font specified in font.properties not found [-monotype-courier new-regular-i---*-%d-*-*-m-*-iso8859-1] but hopefully reasonable substitutions are done for fonts to look reasonably. After some time the nice picture appears which tells you that this is a deploytool, which is then replaced by the actual Application Deployment Tool windows. c) Selected [File] menu from the top bar of the deploytool Selected [New] Selected [Application] Clicked on [Browse] In the [File name] field wrote /home/j2ee/test/converter and clicked on [New application] button on the right side This showed me a list of files in my /home/j2ee/test/converter directory. I erased current content of the [File name] field and entered there: ConverterApp.ear and clicked on the [New Application] button on the righthand side. It displayed the confirmation box, and I clicked on [OK]. III. Now, I will be trying to package the enterprise bean. ------------------------------------------------------ a) Selected [File] from the top bar menu Selected [New] Selected [Enterprise Bean] and the Wizard window appeared. I read what they had to say. Basically: i) identify EJB JAR file that will contain the bean ii) Select bean time (we are doing simple session bean here) iii) Identify EB class and its Home and Remote interfaces. Clicked [Next] The combo box appeared and I accepted the ConverterApp name in the "Enterprise Bean will Go In:" field. In the "Jar Display Name field I entered "ConverterJAR" in place of Ejb1 Clicked Add button on the right of "Contents:" area: "Edit Contents of ConverterJAR" boc appeared I typed the /home/j2ee/test/converter in the input field on the top and hit enter This displayed the files in the directory. I clicked on the Converter.class and clicked on Add button. then ConverterEJB.class and clicked on Add button. then ConverterHome.class and clicked on Add button. The class files were added to the "Content of ConverterJAR" area at the bottom of the "Edit Contexts of ConverterJAR" box. Now I cliced [OK] button at the bottom of the "Edit Contexts of ConverterJAR" box. Box disappeared and the classes were now shown in the "Contents:" area of the New Entrerprise Bean Wizard - EJB JAR. Now I clicked [Next]. The previous Wizard box was replaced by "New Enterprise Bean Wizard - General Box". I chosed: Bean Type: Session Stateless by clicking on radio buttons. Enterprise Bean Class pull down, I chosed: ConverterEJB Home Interface pull down, I chosed: ConverterHome Remote Interface pull down, I chosed: Converter Enterprise Bean Name field I typed in: ConverterBean then I clicke [Next]. New Wizarad window "New Enterprise Bean Wizard - Environment Entries" was displayed in place of old one. I clicked [Finish] button in this window. The wizard window was closed. b) deploying J2EE application In the left side tree listing I selected the ConverterApp view by clicking on the ConverterApp name. Then in the row which provides tabs: [General] [JNDI Names][Web Context][Security] I clicked on the [JNDI Names]. This displayed new boxes. In the JNDI Name field (on the right hand side) I entered: MyConverter and hit Enter. From the top bar I selected: [Tools] Deploy New window appeared. I selected the ConverterApp in the "Object to Deploy" pulldown and the local host for the "Target Server" pulldown (this was the only option). Then I selected on the [ ] Return Client Jar button. The entry field showed the path: /home/j2ee/test/converter/ConverterAppClient.jar which looked OK for me, so I clicked [Next] The "Deploy ConverterApp - JNDI Names" listed the: EJB ConverterBean MyConverter which looked OK, so I clicked [Next]. Then it told me to click [Finish] and I did. It displayed the gizmo with progress of deployment. After it finished, I clicked [OK] button. I closed the "deploytool" by choosing from the top bar: [File] [Exit] IV. Building the client ----------------------- I created another directory /home/j2ee/test/converterClient I copied the file /usr/local/j2sdkee1.3/doc/guides/ejb/examples/converter/ConverterClient.java to /home/j2ee/test/converterClient This client needs to have access to interfaces (compiled): Converter and ConverterHome. So I copied the interfaces from my /home/j2ee/test/converter directory cd /home/j2ee/test/converterClient cp -p /home/j2ee/test/converter/Converter.class . cp -p /home/j2ee/test/converter/ConverterHome.class . Of course, I could just put /home/j2ee/test/converter in the CLASSPATH but wanted to make sure that I have exactly what is needed nor more, not less. Then I compiled the Client as: cd /home/j2ee/test/converterClient cb ConverterClient.java Note... In the cb script I had to use rt.jar from the $JAVA_HOME/jre/lib directory. Now I tried to run the client. It requires classes from the ConverterAppClient.jar which was created during deployment of our Converter application with deploytool as described above. I made sure that J2EE server is running by ps -ef | grep j2ee Them, I ran it in the /home/j2ee/test/converterClient as: CP=$J2EE_HOME/lib/j2ee.jar:/home/j2ee/test/converter/ConverterAppClient.jar:. java -classpath $CP ConverterClient It told me: 12160.0 0.77 i.e., that 100 USD is 12160.0 yen, and 100 yen is 0.77 USD. ==============================