Signup · Login
Stardeveloper.com  
Home · Articles · Forums · Advertise · Contact
Article Categories
.NET  .NET
  ASP (15)
  ASP.NET (26)
  ADO (16)
  ADO.NET (10)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Latest Forum Activity
what is the right code to link the asp page t..
by amylisa on 22 Jul 2008 Go To Post

Can Loader.asp Get Form Elements
by azziham on 14 Jul 2008 Go To Post

Good asp resource sites
by codemylife on 3 Jul 2008 Go To Post

Re: Unable to insert data in an Access databa..
by asia on 3 Jul 2008 Go To Post

Re: problem with do while loop
by idsanjeev on 30 Jun 2008 Go To Post

Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article

Hosted by Securewebs.com
 
Home : .NET : COM : Building COM objects using Java classes as components
 

Building COM objects using Java classes as components
by Faisal Khan.

Overview
Web developers can use Java to make COM components which will provide additional features to their web applications. In this tutorial we will compile a Java class and then we will register it into the system registry. Later we will access it as COM object from our web pages.

Tools of trade
I will presume here that your operating system is Microsoft Windows. You will need a Java compiler, you can download Java Development Kit from Microsoft's SDK for Java web site. It contains the javareg.exe tool which we'll be needing later to register our java classes as COM components. Just make sure you download the latest version.

Writing the code
Open your favorite notepad and write down the following Java code exactly as it is :

public class ReturnText {
	public String GetText() {
		return "Hello World!";
	}
}

You may want to copy the above code and then paste it onto your note pad. If you examine the above code, you will notice that our above Java class is pretty much straight forward with only one public method GetText, which returns a String "Hello World!". Now save this file as "ReturnText.java".

Compiling ReturnText.java
Now go to the DOS prompt and compile Java class file using the command below :

jvc ReturnText.java

A ReturnText.class file will be created if every thing goes well.

Registering Java class
We will register ReturnText.class using javareg. JavaREG is a tool for registering Java classes as COM components in the system Registry. Write down the following command at the DOS prompt :

javareg /register /class:ReturnText
	/progid:StarDeveloper.ReturnText
	/typelib:ReturnText.tlb

After successfully registering the Java class file you will see a dialog box telling you that your Java class has been registered. Now copy ReturnText.class file into windows/java/trustlib/ directory on Win 9x or winnt/java/trustlib/ directory on Win NT. This copying is a must step, our COM object won't work without it.

Calling ReturnText component from the web page
Open your favorite notepad and write down the following code :

<%
	Dim sd
	Set sd = Server.CreateObject("StarDeveloper.ReturnText")

	Response.Write sd.GetText
	
	Set sd = Nothing
%>

Now save it as ReturnText.asp in your root directory of your server. Note that you will be requiring Personal Web Server on Win 9x or IIS on Win NT. You can place your ASP page any where you want from where you can call it using HTTP. I am just simplifying the things out here. Now point your browser to http://localhost/ReturnText.asp. If everything has gone on well you should see the following output on your web page :

Hello World! 

Congratulations you have just built and tested your first Java COM object. Having done this you can now make better and useful COM components for your web site and applications.


 ( No Further Pages )

Related Articles
  1. Accessing ASP Intrinsic Objects From Java Component

Comments/Questions ( Threads: 10, Comments: 19 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. javareg
  2. Accessing COM from Java and Vice-versa
  3. Building COM objects using Java Jar files ( 1 Reply )
  4. How to import user packages?
  5. Using Javareg to register calling class files
  6. Send command line argument to Java Program ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  7. Building COM objects from JDK1.4 ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  8. Don't understand ( 3 Replies ) This thread contains 2 replies by the Author of this Article. This thread contains 2 replies by Faisal Khan.
  9. Imported Classes ( 2 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  10. problem in registering java classes as com components ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2008 Stardeveloper.com, All Rights Reserverd.