1.) To run JBoss through eclipse, simply add it to the servers.
2.) To run JBoss on local host (explorer), go to JBoss folder, then bin, and then simply run the Run.bat file. By default it runs on Port 8080. So make sure that this port is free for jboss to run.
3.) By default if you run the JBoss, it will run only on local host, but you cannot run it through remote system. To run it through remote system, you have to run the Run.bat with some arguments. Make another bat file in the same location, say mybat.bat. now edit this mybat.bat and write these lines in it:
Run.bat –b 0.0.0.0
After that you can run the JBoss through your mybat.bat file instead of running it through Run.bat. The arguments 0.0.0.0 are the address of the remote user. Giving it in this (0.0.0.0) format means anybody can run your jboss on his/her system. If you specifically want to give the address of remote user, than you can give the address of remote user in place of 0.0.0.0 (i.e. say 192.168.0.9 instead of 0.0.0.0).
4.) Before going ahead, please make sure that jboss is working fine at your local as well as through remote system.
JDK and API’s Required for running jboss on eclipse
1.) Make sure that you are using jre 22.214.171.124 or higher version and you have the required API’s (axis.jar, commons-discovery-0.2.jar, commons-logging.jar, jaxb-api.jar, jaxrpc.jar, saaj.jar, wsdl4j.jar).
2.) Configure the jboss in eclipse properly.
Creating Web Services has two parts. First is creating Web Service and second is creating WebService Client.
Creating WebService in eclipse:
1.) First create a new dynamic web project say Project1.
2.) Now create a package say pkg in src folder and create a class say Addition.java. This class will be having the methods which the user wants to access remotely. This class is also known as Endpoint.
3.) Now define a method in this class, say a method named addNumbers(int x,int y) which simply returns the addition of these two parameters.
4.) After creation of the class, right click on the class, go to web services, click on the create web service. Now we will be creating a WebService i.e. our first step.
5.) Now a window will appear, now in the first column named Web service type, select Bottom up java bean Services. In the second column named Service implementation, give the package name and your Endpoint class name i.e. pkg.Addition.
6.) On the below of these two columns, select start service from the chooser bar and select No client from the bar below this. Give java Proxy in the client type.
7.) Now click Finish button. Now it will first start the jboss if not started.
8.) After the end of this process, it will create a wsdl folder inside the WebContent of the same project. Inside the wsdl folder, there is an xml file. Which is named like Endpoint.wsdl i.e. Addition.wsdl.
9.) Now first of all you should be able to run this xml file through jboss inside eclipse as well as outside the eclipse(i.e. on the explorer). To run it through eclipse, simply right click on the xml file and select option run on server. It will run the xml file in your browser inside eclipse. Now you can use the same url to run this xml on the explorer outside eclipse.
10.) Remember one thing, jboss cannot run its two instances i.e. in eclipse as well as outside(through Run.bat) simultaneously. So you have to stop the jboss from inside the eclipse to run it outside. Otherwise it will through exception that port is already in use.
11.) If you want to run jboss from remote address, then start jboss through mybat.bat created by our self instead of Run.bat.
Creating WebService Client:
Now we can create a WebService client to call the Endpoint class generated.
1.) Create another dynamic java project say Project1Client. It will act as a client for our Project1 project to receive methods.
2.) Now select the project, go to file, new and select others. Now select Webservice Client inside WebServices.
3.) Now when you select this option, a window will appear. Now in the service definition give the url of the wsdl xml i.e. address of Addition.wsdl which you have run last time. Url will look like http://localhost:8080/Project1/wsdl/Addition.wsdl.
4.) Note that if you want to access this web service on remote site, then give here proper address of the server system(ip of your system here) i.e. http://192.168.0.62:8080/Project1/wsdl/Addition.wsdl for example. but before giving this proper ip address, make sure that your Jboss in running from outside the eclipse and you are able to run this url from your or from remote system. If the Jboss is not running from outside, it will show error that “service definition selected is invalid”. If you are going for your localhost, then no need to run jboss from outside. Then it will also work if your jboss is started inside the eclipse.
5.) Now from below bar, select the “start client” option.
6.) Now click next button.
7.) Now if you have given the remote ip address in the service definition, then after the next button click, you have to stop the jboss from outside. Now click on next button and then select start server. It will start jboss inside the eclipse.
8.) Stopping jboss outside in necessary after first step, because if you don’t stop it, you will not be able to run jboss inside your eclipse.
9.) Now after everything completes without any exception, you will see a package created in your src in your this project(Project1Client). i.e package name pkg, the same package name you have given in the Project1.
10.) There would be some classes in this package i.e. one is having same name as your endpoint i.e. Addition.java, AdditionProxy.java, AdditionService.java, AdditionServiceLocator.java, AdditionSoapBindingStub.java. These are the classes which are automatically created in your WebService client project.
11.) Now the AdditionProxy.java is the class which you will be using to access your methods remotely.
12.) Now make a new class in the same package in your client project say Myclass.java.
13.) Now in this class you can call the object of proxy class i.e. AdditionProxy.java.
Say for example: AdditionProxy object =new AdditionProxy();
System.out.println(“Addition of two numbers:”+result);
14.) When you will run this class with code something like this, it will show you the output as the addition of two numbers 2 and 3.
15.) If you are running this class on the same system, then make sure that jboss is running inside your eclipse.
16.) If you want to see the result on remote system, then simply copy whole package i.e. pkg and copy it on some remote system in any project. Also add the API’s to project if required.
17.) Now before running it on remote system, you need to do one change in the AdditionServiceLocator.java. there is mentioned the address of your server system in the variable Addition_address variable. By default, there is given a local system address. Change it and give the ip address of your server system instead of localsystem.
18.) Now you can run Myclass.java to see the output, but before running make sure the your jboss in running (outside eclipse through the mybat.bat file) on the server system.
19.) Now when you will run this class, you can see this output :
Addition of two numbers:5