By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,190 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,190 IT Pros & Developers. It's quick & easy.

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

P: n/a


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
Share this Question
Share on Google+
14 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a


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

P: n/a


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

P: n/a


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

P: n/a


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

P: n/a


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

P: n/a


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

P: n/a
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

P: n/a
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

P: n/a


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 discussion thread is closed

Replies have been disabled for this discussion.