wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes JavaBeans and class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JavaBeans and class" Watch "JavaBeans and class" New topic
Author

JavaBeans and class

Jas on
Greenhorn

Joined: May 03, 2001
Posts: 7
Hi all,
I've created two JavaBeans, and I convert one bean (Bean A.jar) into ActiveX control. Inside a COM application, I load this ActiveX control, and then try to call the other bean (Bean B.jar), which is outside this container. Fail!!! class path has been set up already, and if I replace the Bean B.jar with B.class in the same directory, everything is ok. Why?
I'm currently creating a bridge between COM and Java object, and has gone through Sun's related tutorial. Please help. Many thanks.
Jas
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
From http://java.sun.com/docs/books/tutorial/jar/basics/run.html

JAR Files as Applications - 1.2 platform only
In version 1.2 of the JDK software, you can run JAR-packaged applications with the Java interpreter. The basic command is:
java -jar jar-file
The -jar flag tells the interpreter that the application is packaged in the JAR file format.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Jas on
Greenhorn

Joined: May 03, 2001
Posts: 7
Hi Cindy,
I'm using jdk1.3, and those jar files run well in command line. The problem is I have to call those Beans in a COM application (XMetaL, and XML enable software). For this purpose, I create a JavaBeans and then package it as an ActiveX control using Sun JDK plug-in: sun.beans.ole.Packager. After that, I load this ActiveX control into XMetaL, everything is fine so far. From ActiveX control, I call the outside java class (I mean outside this packager container and XMetaL), it is ok as long as I put those java classes into same directory with XMetaL. However, if I wrap those java classes as a JavaBeans or jar files, the inside Beans (ActiveX control) cannot find it, even in the same directory.
Again, I went through all related materials from Sun website already. You may consider XMetaL as a COM software, such as MS Visual Studio. Actually, I test it in VB6, same problem.
I may not clearly state my question in my first post. Actually, everything is fine when I call a beans from other beans in jdk1.3, and it is still ok when I call java class from ActiveX control inside a COM application. However, I'm stuck when I use a Beans to replace those java class.
Any comments will be greatly appreciated.
Jas
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
So this is REALLY an ActiveX question (something that I know absolutely nothing about).
Well let's give it a day, and if no one can figure it out, I'll move this to another forum for a try.
Jas on
Greenhorn

Joined: May 03, 2001
Posts: 7
Opps... How can help???
Jas on
Greenhorn

Joined: May 03, 2001
Posts: 7
After lunch, I'm still thinking this is a Java question. B.class can be found in run time, but B.jar cannot be found!?
When we use jdk in command line, we can use -jar to tell the interpreter that this is a jar format; however, when I try to find this class from a COM application, it doesn't know that the class is packed inside the jar, so class no found. I also try to
place the file B.jar in the lib/ext directory of the JRE, still doesn't work!!!
For my understand, one of the difference between jar and class file is the jar file has to be un-zip in run time if we try to access its inside class; whereas the class file can be accessed directly. Is it the reason for my question? This is just what I think in my lunch time. Any comments?
Jas
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
No. We use the classes that Sun provides in jar files all the time without unzipping them.
I just don't know how to tell COM or ActivieX to look in a jar file.
Have you tried explicitely adding the jar file to your classpath?
Jas on
Greenhorn

Joined: May 03, 2001
Posts: 7
I agree with you, Cindy. We can use -jar tell jdk that it is jar format, but how to tell COM apps in run time?
I set all necessary class path properly, and even try to use extension - place the file B.jar in the lib/ext directory of the JRE.
Jas
Michael Pearson
Ranch Hand

Joined: Mar 11, 2001
Posts: 351
How about posting the exact text of your CLASSPATH and PATH so Cindy doesn't have to guess if you made a simple mistake and are overlooking it. That happens to most of us every now and then when we're pouring over the same settings. After awhile it all looks correct.
Here are my settings as an example:
PATH = D:\jdk1.3\bin;D:\jdk1.3\jre\bin;D:\jdk1.3\jre\classes
CLASSPATH = .;D:\jdk1.3\lib;D:\Java;D:\jdk1.3\jre\lib\ext\JavaRanchCommon.zip
If I'm going to use classes from JavaRanchCommon.zip I just include the appropriate import statement at the top of my class application file like this...
<code>
import com.javaranch.common.*;
public class DoStuff
{
...
}
</code>
If I compile the code as a stand-alone class I can use javac DoStuff.java. Even if I package it into a -jar file the compiler will find the classes in JavaRanchCommon.zip by referencing the CLASSPATH I set to D:\jdk1.3\jre\lib\ext\JavaRanchCommon.zip.
I can't believe COM applications would access the data any differently. This is suppose to be portable source code.
Let's see your PATH and CLASSPATH settings?!
Mike
Jas on
Greenhorn

Joined: May 03, 2001
Posts: 7
Micheal,
What I did is EXACTLY like you said, even classpath and path setting(I run it in WIN2000 Pro and JDK1.3). Some key pointes I want to emphasize:
1. Everything is fine when I run in command line using javac and java to compile or run those classes, Bean A.jar can call Bean B.jar as long as they as in classpath and import them in a testing class (like you pointed out).
2. When I put Bean A.jar into an packager that it works as a ActiveX control, A.jar still can call outside java class, B.class; however, if I remove B.class and replace B.jar, it cannot find B.jar.
3. Every setting, classes and Beans have been tested successful in jdk command line before putting into a COM application.
4. Actually, I think that place B.jar in classpath only affect for jdk, no affect other COM apps when they try to find B.jar. SO how they can find B.jar? I put B.class in the same directory with this COM application, and this app can find B.class, and invoke it successfully. The trick one is that it cannot find B.jar in the same way (all classpath setting is still not changed).
Actually, I went through all materials what I can find on web, including Sun's JavaBeans to ActiveX control, still cannot get the answer. This may be a tiny problem, but it stucks me three days. My project has to call JavaBeans from a COM apps, I have no choice.
Any help will be highly appreciated.
Jas
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Everything you say points to the fact that it is a COM problem. Something in the way that COM looks for class a jar files is not set up right.
Have you tried asking this question at a (I regret having to say this) Microsoft forum. Perhaps one of their COM experts can solve your problem.
*************************************************************
OK, I looked myself: Apparently you need to use a .cab file

Will the Microsoft Virtual Machine for Java support the .jar file format?
Jar support is the same as .zip. .jar = .zip + manifest. So Microsoft will support uncompressed and compressed .jar files, but not signed .jar files. If you need Java security (beyond sandbox) in Internet Explorer 4, you need to use a signed .cab file. This applies to all fine-grained Java security (including running in a sandbox on the local machine using the Package Manager).

Can my applet that is inside a .cab file use class files from outside the .cab that are not installed in the local machine's CLASSPATH?

Class files from a Web server cannot be used by classes in a .cab file with the Microsoft VM for Java, build 1517 and earlier. With build 2057 of the VM, from the Microsoft SDK for Java 2.0 Preview, you can use classes from outside of the .cab file.

Microsofts VM search path: http://support.microsoft.com/support/kb/articles/Q177/1/68.ASP
An article on CAB and JAR files and how they work with DCOM, and converting them. http://msdn.microsoft.com/library/periodic/period98/ss_cab2jar.htm
Jas on
Greenhorn

Joined: May 03, 2001
Posts: 7
I just check all links you provided. I still cannot get what I want. Anyway, I will fight it by my own. I really appreciate your comments. Thank you!!!
 
GeeCON Prague 2014
 
subject: JavaBeans and class