Calling Java class in vb

Aishwari

Member
Joined
May 18, 2009
Messages
5
Programming Experience
10+
Hi,

I am new to vb.net and currently researching about the features available in it. Please apologize if this question does not belong to this category.

In order to call a java class in vb, I found the following procedure and I tried.
(1) create a java class (eg: MyTest .java)

as

public class MyTest
{ public int myfunction(int value1, int value2) { return value1+value2; }

(2) compile to get a MyTest.class

(3)register Mytest.class using javareg.exe file from Microsoft SDK for Java using
javareg /register /class:MyTest /progid:MyTest

and see a MessageBox displayed with Succesfull register Class message

(4) copy MyTest.class to C:\Winnt\Java\Trustlib\

(5) open a New Project on Visual Basic. And paste this brief code on the Form Load event for example and run it. Set x = CreateObject("MyTest") MsgBox x.myfunction(1, 1)

I did all the above steps but when I run the vb program (Step 5), I get the error message "Cannot create ActiveX component". Unhandled Exception message.

I am using Java 1.5 and Visual Studio 2008.

Could you please let me know what I am missing and how to resolve this.
Please let me know if you need additional information to resolve this.

Thanks
Aishwari
 
Just a question

Are you creating a web project? Just curious because I'm trying to think why you would use Java in a non web app.

If you are building a web project I can help with placing and calling Java from VB code behind.

Ty
 
Hi,

Thanks for responding.

I am trying to build a thick client application and not web app. We have java batch applications (both built in house and vendor supplied) and we would like to call some of the methods from that java apps in the new VB application.

Please let me know if youneed additional information

Thanks
Aishwari
 
You can use Java dll's in .net (Console, WinForm, WebForm and WPF) just like you do with ActiveX and .Net dll's

It does add another deployment complexity because you'll have to make sure the end users have not only the .Net framework to run the app but they'll also have to have the JVM for the java dll's to run the same app.
 
Hi,

Thanks for responding.

Could you please eloborate more on it as I have never used Java dlls and new to .net technology

In response to TyB's earlier response, please let me know how to call java class in a VB.NET web application

Thanks
Aishwari
 
Sure, I'm not a Java person so I don't know the tools to use but the concept is the same.

You compile the java code into it's bytecode file, then you reference said bytecode file in .Net app (webapp or winform) by right clicking the project name and click 'Add Reference' (or similar)
 
Hi,

Thanks for clarifying it.

I searched on the web for creating dlls fromjava and not much information available to do that. So, I checked on Java forum and they had mentioned that it is not possible to create a dll from java.

I understand that you are not a java person and hence not familiar with the way to get a dll. But, is there any other approach to call java class from vb.net?

Thanks
Aishwari
 
[FONT=&quot]How do I download OWL API in my VB.NET Application? I would like to run SWRL rules uppn OWL ontology an duse the results in my VB.NET application

this OWL API is a java file [/FONT]
 
Back
Top