473,544 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use Java .class files from C# or .NET?



I wrote a C# program that interfaces with a data vendor over the web
using an API they supplied and their examples in C#.

Now I have another data vendor's API and example that I want to add to
my C# program. But this new API is written in Java. They gave me an
example source code that uses their API but the actual API looks like it
is stored in a few .jar files. I unzipped those .jar files into many
.class files. I think these .class files are kind of like Java's
version of compiled .dll files or library files, right? Anyway they are
not source code.

I can convert the example into C# using the "Conversion Assistant" in
.NET. But then it can't access any of the libraries in the actual API.

I don't know anything about Java except for what I have tried to glean
from this newsgroup. I would like to convert the Java API to C# but it
looks like that is not possible, right? Or I would like to access those
.class files from C#, but again, I guess this is not possible. I read
somewhere that those .class files can be converted to COM files and then
access from C#, is this possible?

I downloaded j2sdk-1_4_2-nb-3_5_1-bin-windows.exe from Sun's website. I
guess I could convert my C# program to Java but then I probably won't be
able to access the first vendor's API that is using .NET their .dll.

Sorry if I'm not making much sense here, I'm so confused. Does anyone
have any suggestions?

Thank you,
Mick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
14 7306
You cannot directly do anything with Java class files as far as I know from
C#. But what you could do is look into compiling the Java source code with
J#. This will at least generate IL and then you would at least be able to
use other .NET languages with it like C#. I don't know if J# has anyway to
extract from the jar file or not.
--
Sam Gentile [C#/.NET MVP]
..NET Blog http://samgentile.com/blog/
"Mick" <no*****@nowher e.com> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...


I wrote a C# program that interfaces with a data vendor over the web
using an API they supplied and their examples in C#.

Now I have another data vendor's API and example that I want to add to
my C# program. But this new API is written in Java. They gave me an
example source code that uses their API but the actual API looks like it
is stored in a few .jar files. I unzipped those .jar files into many
class files. I think these .class files are kind of like Java's
version of compiled .dll files or library files, right? Anyway they are
not source code.

I can convert the example into C# using the "Conversion Assistant" in
NET. But then it can't access any of the libraries in the actual API.

I don't know anything about Java except for what I have tried to glean
from this newsgroup. I would like to convert the Java API to C# but it
looks like that is not possible, right? Or I would like to access those
class files from C#, but again, I guess this is not possible. I read
somewhere that those .class files can be converted to COM files and then
access from C#, is this possible?

I downloaded j2sdk-1_4_2-nb-3_5_1-bin-windows.exe from Sun's website. I
guess I could convert my C# program to Java but then I probably won't be
able to access the first vendor's API that is using .NET their .dll.

Sorry if I'm not making much sense here, I'm so confused. Does anyone
have any suggestions?

Thank you,
Mick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2
"Mick" <no*****@nowher e.com> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...


I wrote a C# program that interfaces with a data vendor over the web
using an API they supplied and their examples in C#.

Now I have another data vendor's API and example that I want to add to
my C# program. But this new API is written in Java. They gave me an
example source code that uses their API but the actual API looks like it
is stored in a few .jar files. I unzipped those .jar files into many
class files. I think these .class files are kind of like Java's
version of compiled .dll files or library files, right? Anyway they are
not source code.

Hi Mick,

Just an idea - I'm wondering if you could write a wrapper for the API in J#
and then talk to the J# wrapper with C#.

Joe
--
http://www.csharp-station.com
Nov 15 '05 #3
IIRC, the jbimp.exe tool from the J# SDK can convert Java 1.1 .class files
to IL, I believe. However Java 1.1 was so long ago that you essentially
have to re-write your Java specifically to compile to 1.1 just to get it to
work, and then you might as well have ported it to J#.

Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Sam Gentile [MVP]" <Ma*********@co mcast.net> wrote in message
news:ea******** ******@TK2MSFTN GP12.phx.gbl...
You cannot directly do anything with Java class files as far as I know from C#. But what you could do is look into compiling the Java source code with
J#. This will at least generate IL and then you would at least be able to
use other .NET languages with it like C#. I don't know if J# has anyway to
extract from the jar file or not.
--
Sam Gentile [C#/.NET MVP]
.NET Blog http://samgentile.com/blog/
"Mick" <no*****@nowher e.com> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...


I wrote a C# program that interfaces with a data vendor over the web
using an API they supplied and their examples in C#.

Now I have another data vendor's API and example that I want to add to
my C# program. But this new API is written in Java. They gave me an
example source code that uses their API but the actual API looks like it
is stored in a few .jar files. I unzipped those .jar files into many
class files. I think these .class files are kind of like Java's
version of compiled .dll files or library files, right? Anyway they are
not source code.

I can convert the example into C# using the "Conversion Assistant" in
NET. But then it can't access any of the libraries in the actual API.

I don't know anything about Java except for what I have tried to glean
from this newsgroup. I would like to convert the Java API to C# but it
looks like that is not possible, right? Or I would like to access those
class files from C#, but again, I guess this is not possible. I read
somewhere that those .class files can be converted to COM files and then
access from C#, is this possible?

I downloaded j2sdk-1_4_2-nb-3_5_1-bin-windows.exe from Sun's website. I
guess I could convert my C# program to Java but then I probably won't be
able to access the first vendor's API that is using .NET their .dll.

Sorry if I'm not making much sense here, I'm so confused. Does anyone
have any suggestions?

Thank you,
Mick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 15 '05 #4
inline:

"Mick" <no*****@nowher e.com> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...


I wrote a C# program that interfaces with a data vendor over the web
using an API they supplied and their examples in C#.

Now I have another data vendor's API and example that I want to add to
my C# program. But this new API is written in Java. They gave me an
example source code that uses their API but the actual API looks like it
is stored in a few .jar files. I unzipped those .jar files into many
class files. I think these .class files are kind of like Java's
version of compiled .dll files or library files, right? Anyway they are
not source code.
Correct, although you can easily decompile them. Check the web for tools.
There are quite a few that turn java byte code back into java syntax.
I can convert the example into C# using the "Conversion Assistant" in
NET. But then it can't access any of the libraries in the actual API.

I don't know anything about Java except for what I have tried to glean
from this newsgroup. I would like to convert the Java API to C# but it
looks like that is not possible, right? Or I would like to access those
class files from C#, but again, I guess this is not possible. I read
somewhere that those .class files can be converted to COM files and then
access from C#, is this possible?
Only by using J++ or a Java-to-COM bridge as far as I know. I don't
recommend it. You'll be going through too many wrappers.
If you can retrieve the source code from the class files by decompiling
them, and then tweaking them into C#, i'd go that route.
I downloaded j2sdk-1_4_2-nb-3_5_1-bin-windows.exe from Sun's website. I
guess I could convert my C# program to Java but then I probably won't be
able to access the first vendor's API that is using .NET their .dll.

Sorry if I'm not making much sense here, I'm so confused. Does anyone
have any suggestions?


Try using this Java-to-.NET bridge:
http://www.jnbridge.com/index1.htm

I haven't personally used it, so I can't attest to its suitability for your
needs, but it's a start.

-Rob Teixeira [MVP]
Nov 15 '05 #5
Yes, the .class files are the output of the java compiler. The java runtime
loads classes either from individual .class file or from .jar files which
are nothing more than zip files containing .class files (you can open a .jar
file with standard zip tools).

J# includes a tool to convert .class or .jar files into .NET assemblies. The
tool is called JBIMP and you should be able to find its documentation in the
Studio 2003 documentation.

But there is no guarantee that JBIMP will solve your problem because J# is
based on an old version of the Java framework (JDK 1.1.4 while most Java
developers use JDK 1.4 these days). So, if your .class files only use JDK
1.1.4 APIs, JBIMP will do the job, but if they use newer APIs, JBIMP won't
be able to convert them. Then, you will need to rework the Java code so that
it only uses JDK 1.1.4 APIs (you 'll need the source) or investigate other
options (like communicating with a separate process that runs your java
code).

Bruno.

"Mick" <no*****@nowher e.com> a écrit dans le message de
news:uk******** ******@TK2MSFTN GP12.phx.gbl...


I wrote a C# program that interfaces with a data vendor over the web
using an API they supplied and their examples in C#.

Now I have another data vendor's API and example that I want to add to
my C# program. But this new API is written in Java. They gave me an
example source code that uses their API but the actual API looks like it
is stored in a few .jar files. I unzipped those .jar files into many
class files. I think these .class files are kind of like Java's
version of compiled .dll files or library files, right? Anyway they are
not source code.

I can convert the example into C# using the "Conversion Assistant" in
NET. But then it can't access any of the libraries in the actual API.

I don't know anything about Java except for what I have tried to glean
from this newsgroup. I would like to convert the Java API to C# but it
looks like that is not possible, right? Or I would like to access those
class files from C#, but again, I guess this is not possible. I read
somewhere that those .class files can be converted to COM files and then
access from C#, is this possible?

I downloaded j2sdk-1_4_2-nb-3_5_1-bin-windows.exe from Sun's website. I
guess I could convert my C# program to Java but then I probably won't be
able to access the first vendor's API that is using .NET their .dll.

Sorry if I'm not making much sense here, I'm so confused. Does anyone
have any suggestions?

Thank you,
Mick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #6


Bruno,

Thank you, that was informative. I did try JBIMP but it had so many
Unresolved classes that it failed. So I guess this means it was
compiled using a newer JDK, right? And since I don't have the source
code for the .classes then I can't convert, unless I decompile them.

Thank you,
Mick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #7


Rob,

Ok I will look for a decompiler.

I looked at www.jnbridge.com, it looks like a wrapper instead of a
decompiler, but I haven't tried it yet, plus I can't afford it right
now.

Do you know any good/cheap decompilers?

Thank you,
Mick

P.S. Thank you to everyone that replied, it was very helpful.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #8


Unfortunately the only source code I have is just an example that uses
the .class files. I don't have the .class files' source code. I have
tried to compile the example into J# but then it can't find most of the
import stuff. I think this is because all the .classes are still in
Java and it can't find them.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #9


Bruno,

Thank you, that was informative. I did try JBIMP but it had so many
Unresolved classes that it failed. So I guess this means it was
compiled using a newer JDK, right? And since I don't have the source
code for the .classes then I can't convert, unless I decompile them.

Thank you,
Mick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3271
by: Hal Vaughan | last post by:
My first Java project has gotten to the point where there are so many .java and .class files that I'd like to keep them separated so I can easily keep files straight. I have my /home/me directory and I want to put my .java files in /home/me/src and my class files in /home/me/bin. For now, I'm keeping the .java files in /home/me/src and,...
4
6548
by: Abdelhalim MIMOUNI | last post by:
hi, i'm new to java, and using sun last JDK, and i'm trying to understand how work this feature when we want to compile at command line ? i'm trying to set the classpath to the directory of the package but still always not working! thank's. -- AbdelHalim MIMOUNI
1
6035
by: Larry Menard | last post by:
Folks, I've written the world's simplest java UDF, and it is complaining that it can't load the method. The class seems OK, it's complaining about the method. The JDBC Sample UDFs (e.g., scUDFReturningErr) seem to work fine, so I made sure that I'm doing everything the same way the sample is. My class file is in the right place. My method...
1
9594
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
2
6931
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
2
3247
by: Janna | last post by:
I have the Java JVM installes on my server. I uncommented extension=php_java.dll in php.ini I uncommented and proerpyl filled out the section in php.ini: java.class.path ="C:\InstantRails\php\extensions\php_java.jar;C:\JavaSources\MyStuff" java.home = "C:\Program Files\Java\jdk1.5.0_10;C:\Program Files\Java\jre1.5.0_10\lib"
5
6264
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
0
10720
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not...
0
7424
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7365
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7772
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7376
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7709
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1841
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
988
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
661
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.