File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes A typical Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "A typical Question" Watch "A typical Question" New topic

A typical Question

Koushik Ghosh

Joined: May 26, 2013
Posts: 25

Consider that I have developped a small desktop application in java swing using eclipse. I have exported the project to a jar file. when I right click and run it with java it operates perfectly. Using JAR-TO-EXE tool I have converted it to exe file as well which is also working properly. Now my question is that can I use that in my mobile? I'm using Samsung galaxy s advance...which has Android v2.3 OS. Does it support .exe or .jar file? If not then is there any way to run the code in my phone as well? I have the source code and using eclipse. Does eclipse have any Add-ons to export the code in such a format that works in my samsung phone?

Any comments or suggestion is appriciated.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

This article says Android doesn't have a JDK and suggests using an emulator.

In general, just an "exe" oversimplies things. An exe is meant to run on just one operating system. You can't take a Windows exe and run it on Linux and shouldn't expect to on Android. Also, you might be calling "non-mobile" APIs if you didn't develop this app with a phone in mind.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

No, you should not expect the application to work. Android does not support Swing, it has its own UI libraries.

Android would let you use a JAR as a library in your Android app, but the app itself must not be a JAR. So your strategy would be to isolate the UI (Swing) from the code, build the rest of the code into a JAR. Create an Android app (Eclipse has as an ADT drop-in), build the UI for the Android app, and add your JAR as a library to the action. What I do is have 3 projects in Eclipse:
1) JAR library which holds as the work/logic
2) Desktop project using Swing (or other UI). Uses the JAR from (1) as a resource
3) Android project with its own UI. Uses the JAR from (1) as a resource

You have to be careful: Android does not have a full Java implementation - it has a lot of it but not everything (for example no Swing). So check their API out to see what parts are available. Make sure your JAR doesn't using anything not present or it won't work.

See this instruction for getting the ADT plugin for Eclipse.

Koushik Ghosh

Joined: May 26, 2013
Posts: 25

Thanks man... that really helps
I agree. Here's the link:
subject: A typical Question
It's not a secret anymore!