Problems deplyoing a Service POJO
deus.machinarum May 23, 2006 5:50 PMHi all,
I'm doing a MUD game for uni where the central class would be World, a Service POJO that manages all the game logic and that the clients connect to. The problem is that I can't seem to deploy it as a Bean.
Here's the code for the Management Interface:
package functional; import org.jboss.annotation.ejb.Management; //@Management public interface WorldManagement { //for testing String tell(); void create() throws Exception; void start() throws Exception; void stop() throws Exception; void destroy() throws Exception; }
Here's the implementing class:
package functional; import java.util.Vector; import javax.ejb.Remote; import org.jboss.annotation.ejb.Service; import org.jboss.annotation.ejb.RemoteBinding; import org.jboss.annotation.ejb.Management; import javax.persistence.*; import java.io.Serializable; @Service (objectName="SE:service=world") //@Remote(WorldRemote.class) //@RemoteBinding (jndiBinding="SE/World") @Management(WorldManagement.class) @Entity @Table(name="World") public class World implements WorldManagement,Serializable{//, WorldRemote{ //private static final long serialVersionUID; private String createdBy; private String description; private String name; private Room startingRoom; @OneToOne private Vector<Room> rooms; public World(String createdBy, String description, String name, Vector<Room> rooms){ this.name = name; this.description = description; this.createdBy = createdBy; this.rooms = rooms; } public boolean addRoom(Room room){ return rooms.add(room); } public boolean removeRoom(Room room){ return rooms.remove(room); } /** * @return The description of the new Room */ public String move(Player player, Exit exit){ String temp = "This is a default debug message."; if(exit == null) return "There is no Exit in this direction."; if(!exit.isOpen()){ if(player.hasKey(exit.getOpens_with())){ exit.open(); player.removeItemfromInventory(exit.getOpens_with()); temp = "You used a key to open the door.\n"; } else{ return "You need a key you don't have to open this door."; } } if(movePlayer(player, player.getCurrentRoom(), exit.getOtherRoom(player.getCurrentRoom()))){ temp += player.getCurrentRoom().getDescription(); return temp; } //default only, should never be reached return temp; } private boolean movePlayer(Player player, Room from, Room to){ if(from.remove(player) && to.add(player)){ return true; } return false; } public boolean addPlayer(Player player){ return startingRoom.add(player); } public boolean removePlayer(Player player){ return player.getCurrentRoom().remove(player); } public String tell(){return "test";} /** * @return Returns the createdBy. */ public String getCreatedBy() { return createdBy; } /** * @return Returns the description. */ public String getDescription() { return description; } /** * @return Returns the name. */ @Id public String getName() { return name; } public boolean kill(livingThing part){ //in case of Player GUI Update return part.getCurrentRoom().remove(part); } public void initiateBattle(livingThing fighter1, livingThing fighter2){ Battle battle = new Battle(fighter1, fighter2); livingThing toKill = battle.start(); kill(toKill); } public void initiateTrade(Player player1, Player player2){ } public boolean pickUp(Player player, String item){ return true; } public boolean drop(Player player, String item){ return true; } /** * @param The player to update * @return The Strings concerning the things that changed for the player */ public Vector<String> getGUIUpdate(Player player){ return null; } //Lifecycle methods, no functionality yet public void create() throws Exception { System.out.println("World - Creating"); } public void start() throws Exception { System.out.println("World - Starting"); } public void stop() { System.out.println("World - Stopping"); } public void destroy() { System.out.println("World - Destroying"); } }
and here's the ant file:
<project name="SE" default="all" basedir="."> <property name="src.dir" value="${basedir}/src"/> <property name="build.dir" value="${basedir}/build"/> <property name="deploymentdescription" value="${basedir}/deploymentdescriptors"/> <!-- please edit this to your jboss installation --> <property name="jbossDeployDir" value="/Programme/jboss-4.0.4.GA/server/default/deploy"/> <property name="earFile" value="SE.ear"/> <!-- The build classpath --> <path id="build.classpath"> <fileset dir="C:\Programme\jboss-4.0.4.GA\client"> <include name="*.jar"/> </fileset> <fileset dir="C:\Programme\jboss-4.0.4.GA\lib"> <include name="*.jar"/> </fileset> </path> <!-- Deploy created ear File --> <target name="deploy"> <!-- delete old ear --> <delete file="${jbossDeployDir}/${earFile}" quiet="false"/> <!-- copy new ear to jboss/deploydir --> <copy todir="${jbossDeployDir}"> <fileset dir="${build.dir}/jar" includes="${earFile}"/> </copy> </target> <!-- Undeploy created ear File --> <target name="undeploy"> <delete file="${jbossDeployDir}/${earFile}" quiet="false"/> </target> <target name="prepare"> <mkdir dir="${build.dir}"/> <mkdir dir="${build.dir}/classes"/> <mkdir dir="${build.dir}/jar"/> <mkdir dir="${build.dir}/SE"/> <mkdir dir="${build.dir}/zip"/> </target> <!-- MUST use JDK 1.5 compiler --> <target name="compile" depends="prepare"> <javac destdir="${build.dir}/classes" classpathref="build.classpath" debug="on"> <src path="${src.dir}"/> </javac> </target> <!-- Package all the EJB classes --> <target name="package-ejb" depends="compile"> <jar jarfile="${build.dir}/jar/SE.jar"> <fileset dir="${build.dir}/classes"> <include name="**"/> </fileset> </jar> </target> <!-- Creates an ear file containing all the modules as well as application.xml. --> <target name="assemble-app"> <jar jarfile="${build.dir}/jar/SE.ear"> <metainf dir="${deploymentdescription}"> <include name="application.xml"/> <!-- <include name="j-boss.xml"/> --> </metainf> <fileset dir="${build.dir}/jar" includes="*.jar"/> </jar> <delete file="${build.dir}/jar/SE.jar"/> <delete dir="${build.dir}/classes"/> </target> <!-- Package the source zip file --> <target name="assemble-src" depends="prepare"> <copy todir="${build.dir}/SE"> <fileset dir=".."> <include name="SE/**"/> <exclude name="**/.svn"/> <exclude name="**/build"/> </fileset> </copy> <zip destfile="${build.dir}/zip/SE.zip" basedir="${build.dir}/SE" /> </target> <target name="clean"> <delete dir="${build.dir}" /> </target> <target name="all"> <antcall target="clean" /> <antcall target="package-ejb" /> <antcall target="assemble-app" /> <antcall target="assemble-src" /> <antcall target="deploy" /> </target> </project>
and here the client trying to access the bean:
package client; import functional.*; import java.util.Vector; import org.jboss.annotation.*; import javax.management.MBeanServer; import org.jboss.mx.util.MBeanServerLocator; import org.jboss.mx.util.MBeanProxyExt; /** * * */ public class Client { private static WorldManagement world = null; /** * Diese Methode wird beim Start des Clients aufgerufen. */ public static void main(String[] args) throws Exception{ try{ MBeanServer server = MBeanServerLocator.locate(); world = (WorldManagement) MBeanProxyExt.create( WorldManagement.class, "SE:service=world", server); //Calculator calculator = (Calculator) ctx.lookup("SE/CalculatorBean/remote"); //System.out.println("1 + 1 = " + calculator.add(1, 1)); //System.out.println("1 - 1 = " + calculator.subtract(1, 1)); //System.out.println(calculator.test()); System.out.println(world.tell()); // } catch(Exception e){e.getMessage(); e.printStackTrace();} //Login login = new Login(); /*Vector<Item> test = new Vector<Item>(); Item item1 = new HealthPack(50); test.add(item1); System.out.println(test.contains(item1)); Item item2 = test.get(test.indexOf(item1)); test.remove(item1); //test.add(item2); System.out.println(test.contains(item1)); System.out.println(test.contains(item2)); */ } }
When i run the client i get the following error:
java.util.NoSuchElementException
at java.util.AbstractList$Itr.next(AbstractList.java:427)
at org.jboss.mx.util.MBeanServerLocator.locate(MBeanServerLocator.java:79)
at org.jboss.mx.util.MBeanServerLocator.locate(MBeanServerLocator.java:92)
at client.Client.main(Client.java:29)
The weird thing is that when i deploy the SE.ear file I can see the server
start the SE application, but not my world bean. I can however see it via the jmx-console.
I have two more general questions:
1. Can a bean be an entity bean and a service bean at the same time?
2. If I offer a management interface for the clients do I still need a remote interface?
Thank you for your time, any help would be greatly appreciated
cheers