Jacorb Installation and Setup

Source: Internet
Author: User

1. Download and install Jacorb2.1

Download the Jacorb_2_1-compact.zip (already compiled version) and unzip it to disk, such as E:/jacorb.
Then, in order to find the package and jacorb.properties configuration file when debugging, you need to set the classpath= in the system environment variable.; E:/jacorb/idl.jar; E:/jacorb/jacorb.jar;  e:/jacorb/classes; Also, to facilitate the use of ant and command-line tools, add E:/jacorb/bin to the path

Modify the Idl.bat (Linux under IDL) file in E:/jacorb/bin and add execution parameters

@echo off
java-djava.endorsed.dirs= "E:/jacorb/lib"-classpath "e:/jacorb/lib/idl.jar;e:/jacorb/lib/logkit-1.2.jar;% classpath% "Org.jacorb.idl.parser%*


Next, copy the jacorb_properties.template in the E:/jacorb/etc directory to the e:/jacorb/classes directory and rename it to Jacorb.properties
Naming a service in CORBA is very important, editing the Jacorb.properties file, setting the Orbinitref.nameservice=file:/e:/ns_ref (here is the example, which can, of course, be for any httpurl or other path , this ns_ref file is generated when the naming service is started. The rest of the profile retains its default value.

  2.   Test whether the naming Service (ns,naming services) can start normally
    
  In the DOS window, enter
      NS E:/NS_REF
    If the following output instructions have been started normally
     [Configuration loaded from Classpath resource file:/e:/sss/web-inf/classes/jacorb.properties]
         Jacorb V 2.1, www.jacorb.org
        (C) Gerald Brose, Xtradyne technologies/fu Berlin, 16-feb-2004
    [jacorb.naming] Info:ns up


If there is no output, it may be that your jacorb.properties file is not placed in the directory where classpath resides.
If the NS is not started correctly, the following exception will appear when you run the following demo
[Jacorb.orb.intercept] Info:interceptormanager started with 0 SIs, 0 CIs and 1 ioris
....
[JACORB.GIOP] INFO:ClientConnectionManager:created new conn to target 192.168.4.161:4089
[Jacorb] ERROR:java.net.ConnectException:Connection Refused:connect


3. IDL Compile demo of grid example
After observing the correct boot NS, DOS Windows go to the Demo/grid directory to execute ant (not compiled if Ant is not installed)
E:/jacorb/demo/grid > Ant
This will do the IDL compile Server.idl file and generate the required source files for CORBA under e:/jacorb/demo/grid/generated
At the same time, Ant compiles all the Java source files and e:/jacorb/classes the. class file below.


4 Running the grid example, this example implements a simple service.

4.1 First consult the 2nd step to verify that the NS has started normally.

4.2 Starting the grid server
Executing in a DOS window (in the e:/jacorb/directory)
Jaco Demo.grid.Server
Or
Jaco Demo.grid.TieServer
Normal output:
[Configuration loaded from Classpath resource file:/e:/sss/web-inf/classes/jacorb.properties]
Jacorb V 2.1, www.jacorb.org
(C) Gerald brose, Xtradyne technologies/fu Berlin, 16-feb-2004
[Jacorb.poa] Info:oid:
1F 1E 04 (+). h@ .....
object is activated


In this case, you can see in the NS Output window:
[Jacorb.naming] Info:bound name:grid.example

In addition, you can use IDE tools such as JBuilder to build a project to run Demo.grid.Server, you must specify the VM parameters-djava.endorsed.dirs= "E:/jacorb/lib" (JBuilder in runtime Configuration), the results are consistent.


4.3 start grid client side
Jaco Demo.grid.Client
Output results:
Height = 31
Width = 14
Old value at (30,13): 0.21
Setting (30,13) to 470.11
New value at (30,13): 470.11
MyException, Reason:this is only a test exception, no harm done:-)


See this result shows that the grid example has been successfully run.

5. The control source, below we will brief analysis grid example:

Jacorb application development is generally divided into the following five steps:
1. Write IDL Interface definition
2. Compiling IDL interface definitions to generate Java classes
3. Implement the interface generated in step 2
4. Write Server startup class and register to Orb
5. Write client to get service object reference

5.1 First Write Server.idl file
About writing IDL Reference doc/programmingguide.pdf documentation

Grid.idl
IDL defintion of a 2-d grid:
Module Demo
{
Module grid
{
Interface MyServer
{
typedef fixed <5,2> Fixedt;
readonly attribute short height; Height of the grid
readonly attribute short width; Width of the grid
void set (in the short n, in the short m, in Fixedt value);
Fixedt get (in the short n, in the short m);
Exception myexception
{
string why;
};
Short opwithexception () raises (myexception);
};
};
};

5.2 Using tool bin/idl.bat to compile Server.idl
Idl-d.. /.. Server.idl

5.3 Implementation Interface
public class Gridimpl extends Myserverpoa

Fill in the constructor, and the methods such as interface, such as:
Public Gridimpl ()
Public Java.math.BigDecimal Get (short n, short m)
public void Set (short n, short m, Java.math.BigDecimal value)

5.4 Writing servers
This step is to write a class to invoke the Gridimpl class and register it with POA so that the remote object can pass
MyServer interface to access it.

1 initializes the Orb object.
Org.omg.CORBA.ORB ORB = org.omg.CORBA.ORB.init (args, null);

2) Use Poahelper to instantiate the reference to POA.
Org.omg.PortableServer.POA POA = Org.omg.PortableServer.POAHelper.narrow (orb.resolve_initial_references ("Rootpoa") ));

3 activates the object, otherwise it is "persisted," and cannot process any requests.
Poa.the_poamanager (). Activate ();

4 Converts a Java object into a CORBA object through POA.
Org.omg.CORBA.Object o = poa.servant_to_reference (new Gridimpl ());

5 causes the NC to bind to the object's reference (this process is done through a named server), noting that the name of the object is used as a parameter to bind ()
Namingcontextext NC = Namingcontextexthelper.narrow (orb.resolve_initial_references ("NameService"));
Nc.bind (Nc.to_name ("Grid.example"), O);

5.5 Write client Invoke service program
1) Create Orb objects
Org.omg.CORBA.ORB ORB = Org.omg.CORBA.ORB.init (args,null);

2 The client obtains a reference to a "grid" service through a named server
Namingcontextext NC = Namingcontextexthelper.narrow (orb.resolve_initial_references ("NameService"));
Grid = Myserverhelper.narrow (Nc.resolve (Nc.to_name ("grid.example"));

3 Use the Grid object for our calculations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.