473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 7271
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*****@nowhere.com> wrote in message
news:uk**************@TK2MSFTNGP12.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*****@nowhere.com> wrote in message
news:uk**************@TK2MSFTNGP12.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*********@comcast.net> wrote in message
news:ea**************@TK2MSFTNGP12.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*****@nowhere.com> wrote in message
news:uk**************@TK2MSFTNGP12.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*****@nowhere.com> wrote in message
news:uk**************@TK2MSFTNGP12.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*****@nowhere.com> a écrit dans le message de
news:uk**************@TK2MSFTNGP12.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


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 #11


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 #12
JNBridge isn't a decompiler, it was an alternative to decompilation,
allowing you to use the .class java APIs from .NET in a last ditch effort to
do something.

The most famous Java decompiler is probably Mocha. Do a search for that, you
can't miss it.
Just be very careful about licensing and legal terms with regards to the
software you trying to get source code for.

-Rob Teixeira [MVP]

"Mick" <no*****@nowhere.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...


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 #13
JNBridge isn't a decompiler, it was an alternative to decompilation,
allowing you to use the .class java APIs from .NET in a last ditch effort to
do something.

The most famous Java decompiler is probably Mocha. Do a search for that, you
can't miss it.
Just be very careful about licensing and legal terms with regards to the
software you trying to get source code for.

-Rob Teixeira [MVP]

"Mick" <no*****@nowhere.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...


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 #14


Rob,

JNBridge: Ok, I get it now.

Decompilers: Yes you were right I found several.

Thank you very much for all your advice! Thanks to you and the other
repliers I think I can figure this thing out.

-Mick

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

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

Similar topics

3
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...
4
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...
1
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.,...
1
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...
2
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...
2
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...
5
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...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.