LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-28-2010, 06:46 PM   #1
ilgaar
LQ Newbie
 
Registered: Jan 2006
Distribution: Backtrack
Posts: 12

Rep: Reputation: 0
How to compile .jar Java byte-codes into native machine codes?


Hello, I am using Linux and I come across applications that are written in Java and are compiled to .jar executable Java byte-codes, however this applications require a Java runtime environment which consumes resources. I was thinking if there is a convenient way to compile these codes into native machine binary codes, to make a fast, compact application without the need for a Java environment. I know I can compile Java codes with gcj into binary codes, however in order to compile these applications one needs the .java files, which I have no access to. Is there a way to compile an executable .jar application into a native machine code in Linux? I'm not familiar with java, so I would be glad if you explain the process in details. What do I need?
 
Old 08-28-2010, 06:57 PM   #2
Blender3D
Member
 
Registered: Jun 2010
Distribution: Linux Mint 9 x64, Linux From Scratch
Posts: 46

Rep: Reputation: 17
Java is made to run from a .jar file. That is what is (kind of) simple about Java: one .jar file runs on 32-bit and 64-bit computers, even if they have Windows, Mac, Or Linux. It is really compatible.

Quick Google search gave me this: http://gcc.gnu.org/java/

As for the source code, the .jar is actually a zip file. Extract it, and you should find a .class file somewhere.
I only know of DJ Java Decompiler for Windows, but you should be able to decompile the .class file into a .java file.

That might get you a bit farther.

To compile it, get GCJ (this is for Ubuntu):
Code:
sudo apt-get install gcj
Then, compile it (I am guessing that this will work. If not, post what happens):
Code:
gcj /path/to/your.file -o /path/to/your/output.file
Now run the binary and see what happens (I'm not sure if this includes all of the libraries and classes, so it might not work at all).

Good luck.

Last edited by Blender3D; 08-28-2010 at 07:06 PM.
 
Old 08-28-2010, 08:12 PM   #3
ilgaar
LQ Newbie
 
Registered: Jan 2006
Distribution: Backtrack
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for the reply. I upacked the jar file...

Thanks for the detailed reply. You are right .jar file is an archive, so I unpacked it. now I have two .class files, one is Launcher.class and the other is Launcher$1.class, I'm not sure what they mean exactly, and which one is the correct one. I also have JD Java Decompiler that I just downloaded and installed, which is very powerful, I can see the source code without even decompressing the .jar file. hmm.. there are too many files. There should be a practical way to this. If I can run .jar file with a Java runtime environment, then there also should be a way to compile it into binary native machine code.

Last edited by ilgaar; 08-28-2010 at 08:22 PM.
 
Old 08-28-2010, 08:40 PM   #4
ilgaar
LQ Newbie
 
Registered: Jan 2006
Distribution: Backtrack
Posts: 12

Original Poster
Rep: Reputation: 0
I decompiled the whole package

I decompiled the whole package, and now I have a folder with hundreds of source files, I don't think decompiling is the right path. But because there was nothing to lose I tried to compile the Launcher.java which was a Launcher.class previously into a native machine code with a usual

Quote:
gcj --main=Launcher -o Launcher Launcher.java
and just as I expected, I got numerous warnings and errors. as an example :

Quote:
Javadev/install.source/org/jvnet/lafplugin/PluginManager.java:83: warning: Set is a raw type. References to generic type Set<E> should be parameterized
/* */ public Set getAvailablePlugins()
I don't think decompiling is the right path or even practical. Though I have never wrote a single line code in Java, the decompiler was a really powerful application.
By the way, I tried DJ and Jad java decomipler, and unfortunately for some reason they are not very Linux friendly, and neither worked for me.
 
Old 08-28-2010, 09:28 PM   #5
Blender3D
Member
 
Registered: Jun 2010
Distribution: Linux Mint 9 x64, Linux From Scratch
Posts: 46

Rep: Reputation: 17
Hmm, just what the doctor expected

Me, being an amateur Java programmer (I can read the code at the very least), I am thinking that this might be some error with the changes in the new versions of Java, as I remember something of the form "Array<type>" or something like that mentioned in one of my books as a new feature. Maybe the compiler is a bit too old...

Why exactly are you trying to compile it into native machine code? I don't think that there will be any speed changes, if that's what you're hoping for...

Would you mind posting the application (a link would be good) you are trying to compile? I could take a stab at it, if you would like...

Last edited by Blender3D; 08-28-2010 at 09:30 PM.
 
Old 08-28-2010, 10:26 PM   #6
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
Using raw types shouldn't be a problem. Developers are urged to transition to typed generics but it the advice not absolutely mandatory. I think the real problem you'll experience is that gcj is many versions behind the sun (not Oracle) JDK or the open JDK, especially the graphics part. I think gcj hardly supports, say, swing at all. You would have to code a native GUI (using something like gnome-java) for a properly functioning binary.

Last edited by jay73; 08-28-2010 at 10:28 PM.
 
Old 08-28-2010, 11:20 PM   #7
ilgaar
LQ Newbie
 
Registered: Jan 2006
Distribution: Backtrack
Posts: 12

Original Poster
Rep: Reputation: 0
So far it has been great

Alright. thanks for all your information. As far as I can understand from what you are telling me, gcj is way behind to support SUN Java or even Open JDK. That's a good piece of info.
now that I have the sources, (thanks to my powerful decompiler).
The only problem is to compile them into native machine code.
What do you recommend, other than gcj of course.
Any open source application to accomplish this task? any idea?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to compile .jar Java byte-codes into native machine codes? ilgaar Linux - Software 1 08-30-2010 12:52 AM
Intel machine codes. sevs Programming 2 04-10-2010 12:08 PM
Are the hex codes for colors in a jpg the same codes as used in html? abefroman Linux - Security 3 07-31-2005 03:21 PM
Cannot compile LDD example codes... okeyla Linux - Hardware 0 05-03-2005 08:30 PM
trying to compile untared codes josejose Linux - Newbie 5 10-07-2004 09:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration