As learning EJB, usually I want to create new case from a old one, it is boring because there are always some variables name need to change, so I write a script to avoid such a thing.
The script named crtsess.sh, it doesn't depend on any old case, just creates a simple Session EJB directly. it has a welcome() method,which returning a string, the module name and EJB name can be specified as arguments of script. I test it on Weblogic 12c:
$ crtsessb.sh # show usage
Usage: crtsessb.sh moduleName ejbName
$ crtsessb.sh testejb TestEjb # this will create a new directory "testejb"
$ find testejb -type f
testejb/build.xml
testejb/runclt.sh
testejb/classes/com/examples/TestEjbClient.java
testejb/classes/com/examples/TestEjb.java
testejb/classes/com/examples/TestEjbBean.java
$ . ./setDomainEnv.sh # set Weblogic environment
$ cd testejb
$ ant # build and package module
$ ls *.jar
testejb.jar
Now we can start Weblogic and deploy testejb.tar on it, if it is OK:
$ runclt.sh # test EJB from a remote client
TestEjbsays: Welcome to EJB TestEjb!
Though this case looks useless, hopefully it is easy to add some business logic in it.
#!/bin/sh
createDesc()
{
cat > $module/ejb-jar.xml 2> /dev/null <
$ejbnamecom.examples.$ejbnamecom.examples.${ejbname}BeanStateless
!
cat > $module/weblogic-ejb-jar.xml 2> /dev/null <
$ejbnamejava:global/$module/$ejbname
!
}
createBuild()
{
cat > $module/build.xml 2> /dev/null <
Build file to compile the Session EJB example $ejbname
!
}
createRun()
{
cat > $module/runclt.sh 2> /dev/null < $srcdir/$ejbname.java 2> /dev/null < $srcdir/${ejbname}Bean.java 2> /dev/null < $srcdir/${ejbname}Client.java 2> /dev/null < 0)
url = argv[0];
System.out.println("$ejbname says: " + returnMessage());
}
public static String returnMessage() {
try {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, url);
InitialContext ic = new InitialContext(p);
$ejbname ejb =
($ejbname)ic.lookup("$ejbname#com.examples.$ejbname");
return ejb.welcome();
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
}
!
}
#### main ####
if [ $# -lt 2 ]
then
echo "Usage: $0 moduleName ejbName"
exit 1
fi
module=$1
ejbname=$2
srcdir=$module/classes/com/examples
mkdir -p $srcdir
# createDesc
createBuild
createRun
createCode