I've been reading up on PhoneGap and really like it. I'd like to see if I can use it with GWT to write Java apps that deploy to many different platforms (web, mobile web, android, iphone, winphone, etc.).
It looks like the PhoneGap SDK comes with different versions of cordova.js for each native platform you want to support. So it looks like the Ant build will have to somehow package the GWT-generated JavaScript to the correct version of cordova.js:
3098DJU39I4F9IF9.html + cordova-android.js
3098DJU39I4F9IF9.html + cordova-iphone.js
3098DJU39I4F9IF9.html + cordova-windows-phone.js
I'm generalizing here, and I know those aren't the correct file names (although, obviously, 3098DJU39I4F9IF9.html is the GWT-generated code).
But then something has to kick-off PhoneGap's ability to take each of those pairings and produce the correct packaged container: an APK, IPA or XAP for each platform respectively.
So I first ask: how does a PhoneGap developer normally go from 3098DJU39I4F9IF9.html + cordova-android.js to having a myapp-android.apk, or from 3098DJU39I4F9IF9.html + cordova-iphone.js to having a myapp-iphone.ipa? Does the PhoneGap SDK have a command-line tool that does this?
Once I understand that much, I'm trying to figure out how to automate this packaging/binding process from an Ant build. Are there any known Ant tasks that already do this? Or do I need to kick off a shell from inside Ant and just run the shell commands? Thanks in advance!
#rooftop is right, you have to build the native app using native SDK even if you are using Phonegap. The benefit lies in creating the UI and behavior of the app using HTML5, CSS and JS.
So, if you are not using any of the native functionality or custom Phonegap plugins, you can just have a bare minimum package structure of native apps for each of the platforms and then simply move the correct files into the concerned folders (in Android it is assets folder) of those package structures using copy task of ant. Thereafter, you can use command line compile and build tools specific to each platform to build and package the app.
Hope this helps.
EDIT: Added more details about other platforms
Basically, all SDKs contains command line tools. In fact I used to compile and build from command line, to automate the process, even for standard Windows apps (Console, Web Apps etc) which are usually performed via Visual Studio's easy to use environment. You can see this for extended tools over standard SDK for Windows phone development.
Similarly iOS is based on UNIX so there we get the power of majority of command line tools for compile, build and automation and XCode provides command line tools for building.
Further for Android, you may find this helpful.
You should really be using Cordova, the renamed version of PG that is an Apache project now. Command line tools were recently released for Cordova. I have not used them so I am not sure if they will help you with building or not. Typically the way you woul create the binary for the device, say an IPA file for iOS would be to actually use Xcode and the native SDK to compile and package your app. This means you need all of the native tools and SDK for each platform. There is also a hosted service from Adobe that will build the native bits for you for a fee. It used to be called phone gap build, not sure if that is still the name. You might want to look at IBM Worklight, as it does many if the things you asked about. The developer edition is free an Eclipse based for the IDE.
Related
I'm using a library (https://github.com/PhilJay/MPAndroidChart) for plotting data in an android app. When app-release.apk is created by the program it is ready to be installed on the tablet I use for testing.
What is puzzling to me is how the parts of the library, which i use, follow with the release. In other scenarios, for example in Visual Studio and c# - program being installed on Window machine, libraries require dll files to be installed and registered on each targeted machine. In my scenario the library is written specifically for Android, but if I somehow managed to include a c++ or a c# library in my Android app using tools like libstdc++ or MONO, would it work the same way when it comes down to app-realease.apk?
Are all classes in a library included in the app-release.apk or just the parts that I use?
Thanks in advance and please let me know if the question is unclear before downvoting it!
Normally, when you build your APK, all the libs you have imported (jars) are included and transformed to dex files, as the rest of your code. So, yes all the classes are included, even if you don't use them.
You can use Proguard to remove them from the APK. Look at this post :
Use Proguard for stripping unused Support lib classes
I would like to install both the Google-Eclipse plugin (which I believe also install the GAE SDK) for my Eclipse instance, so that I may take advantage of a lot of the IDE tools and features it comes with, and also so that I can run my app from inside Eclipse.
I would also like to install just the pure GAE SDK so that I can run my app outside of Eclipse on my regular system.
Because the GAE SDK is a diverse and complex beast, I am worried about having two instances of the GAE SDK installed on the same machine (setting conflicting ENV VARs, trying to open the same port number, etc.).
Obviously, I would take care to never be running the 2 GAE dev servers (1 that ships with the Eclipse plugin, and the other that ships with the pure SDK) at the same time, but that might not guarantee that I have 0 conflicts.
I would also be fine with just installing the Eclipse plugin if there was a way to configure the GAE SDK that it ships with to run both from Eclipse as well as the bash shell. That would probably be the easiest but I don't believe this is possible to do.
Any thoughts as to what my options are here? Thanks in advance!
You can do that by having a single SDK installed and using it for both Eclipse and also for bash shell.You can do that by following the steps below:
Download a Suitable GAE SDK from here and install it.
Open Eclipse and Select Help->Install new software.
In work with box enter the url as http://dl.google.com/eclipse/plugin/4.2 and from the list of available softwares select only "Google Plugin for Eclipse" software and select any other required plugin but not the SDKs. Keep it unchecked!
After installing the selected plugins, in Window->Preferences->Google->AppEngine click on add and then select the installation directory as the directory from step 1 and give a suitable name. Make it as default.
Now you are good to go.If you need to run from shell, invoke dev_appserver from the installation directory. Or if you want to run from from eclipse just run it from there.
I'm new to the programming scene. Been working with C++ for about 5 months now, and have decided I want to start getting into Java. I'm using Eclipse as my IDE, and obviously Java for the language. I'm trying to write a simple HelloWorld application, which can be run through a command prompt executable.
In Visual Studio, it seems it's rather easy to create an executable. All I've ever had to do is use a pull down arrow and choose Release, and then run my build. The purpose of wanting to be able to write/run Java in command prompt is so that I'm able to practice some of the language basics before I go in full force with Swing.
So bottom line, what is the easiest way to create a command prompt .exe written with Java?
Thanks in advance!
Java doesn't natively allow building of an exe, that would defeat its purpose of being cross-platform.
AFAIK, these are your options:
Make a runnable JAR. If the system supports it and is configured appropriately, in a GUI, double clicking the JAR will launch the app. Another option would be to write a launcher shell script/batch file which will start your JAR with the appropriate parameters
There also executable wrappers - see How can I convert my Java program to an .exe file?
See also:
Convert Java to EXE: Why, When, When Not and How
Creating a native installer using jpackage
A java packaging tool named jpackage was released as part of the Java Development Kit (JDK) version 16.
This tool works in conjunction with native packaging tools for various platforms (e.g. WIX for Windows, RPM, and DEB for Linux distributions, DMG for Mac) to allow building native installers for Java applications which can then be run as executables. For distribution, it may be possible to distribute just the executable for the application, independent of the installer (I don't know, I didn't try that).
A nice, tutorial style, blog post that describes the use of the jpackage tool to create a native Windows installer for a Java application is:
How to create a Windows Native Java application (generating .exe file)?
Customizing the runtime image using jlink and jdeps
The packaging tool can (optionally) be combined with the jlink tool:
jlink - assemble and optimize a set of modules and their dependencies into a custom runtime image
This allows you to customize the runtime image for your application to only include the required custom selected modular parts of your application code, java runtime, and 3rd party libraries, rather than distributing a complete java runtime.
Optionally, you can also use the jdeps tool to determine inputs to jlink.
Complete discussion of usage of jdeps + jlink + jpackage + a native bundle creator (e.g. wix/rpm/deb/dmg) is outside of scope for a StackOverflow answer, but various resources can be found on the web if you search.
Creating a standalone .exe instead of an installer
This can be done using warp-packer to create a exe out of the image and app launcher created by jlink.
How to create a standalone .exe in Java (that runs without an installer and a JRE)
Third party tools can help deliver a solution
If you wish to use all these tools in combination, things can get complicated, and I'd advise using a 3rd party utility or template to help perform this task. For example:
badass-jlink-plugin (documentation) -> "allows you to create custom runtime images for modular applications with minimal effort. It also lets you create an application installer with the jpackage tool."
For JavaFX specific applications (as your question has a JavaFX tag), you could review:
JPackageScriptFX -> "demonstrates how projects can use scripts to build self-contained, platform-specific executables and installers of their JavaFX applications via the jdeps, jlink, and jpackage tools."
For native mobile deployments, see Gluon Mobile
This question was Windows specific, but for completeness, if your target is native application deployment on a mobile device, then likely you will need to use a 3rd party solution such as Gluon Mobile.
Background Rationale (ignore if not needed)
creating a native installer using jpackage might be a bit of work, so why would you do it?
Here are some reasons:
When an application is distributed via an installer created using jpackage, that application can be installed on a target system without requiring the user to manually install other dependencies (such as a Java Runtime). The installer will take care of ensuring that your application and any dependencies it requires are installed.
The application ships with its own customized version of the Java Runtime. This means that if the user doesn't install a JRE, and, if they have installed a version of the JRE which is incompatible with your application, your application will still function correctly.
The application can be installed and uninstalled using standard OS facilities for the target platform. Most users of those platforms are familiar with these.
Yes, Java is cross-platform for the most part, but many users don't care much about that, instead they just want a smooth and familiar installation (and uninstallation) experience for their application and jpackage can help accomplish that.
Typical Java programs compile into .jar files, which can be executed like .exe files provided the target machine has Java installed and that Java is in its PATH. From Eclipse you use the Export menu item from the File menu.
Creating .exe distributions isn't typical for Java. While such wrappers do exist, the normal mode of operation is to create a .jar file.
To create a .jar file from a Java project in Eclipse, use file->export->java->Jar file. This will create an archive with all your classes.
On the command prompt, use invocation like the following:
java -cp myapp.jar foo.bar.MyMainClass
I have gone through the Android guide for other IDEs, and I've got the basic build and install working fine using ant and a simple Emacs compile command. I'm aware of some of the existing tools for developing Java and XML in Emacs. I've also seen the EmacsWiki page recommending two Emacs packages, EmDroid and android-mode
I'd like to hear what people recommend, in terms of Emacs packages, small functions, or just workflows.
As a side note, I have decent familiarity with Eclipse, and I did setup the ADT plugin. However, emacs is my primary editor, and I'd like to see how I can use it here.
I too use Emacs for my Android development.
Although I do not use any Emacs packages for it.
Simply write in Emacs and then from a terminal use the android-sdk (ant, android, keytool, jarsigner, adb).
You can always use M-x compile from within Emacs, but I usually prefer a plain old bash shell for Android.
Sorry my work flow isn't really exciting.
Currently android-mode.el is in better shape, plus you can easily fork it to add your own submissions to the developers over Github.
Both of the modes are pretty basic however, and just give you a set of functions to call the various Android development tools.
You are probably aware of jde and ant-mode.el - if you're not, I've just mentioned them.
They'll help you with the general Java / Ant support you'll need for Android SDK development.
You can try Android-emacs-toolkit. http://code.google.com/p/android-emacs-toolkit/
Android-emacs-toolkit helps to build android development environment on emacs. It contains a emacs major mode which help to develop android sdk and ndk program.
It provides support for create new avd, launch avd, create new android project, build and rebuild Android sdk project, build and rebuild Android ndk project, install and uninstall apk, run executable ndk project, output emulator log on emacs.
This toolkit tested on WindowsXP/7, Ubuntu11 with android-sdk and android-ndk-r7.
For building Android itself (ie. AOSP, CyanogenMod...), look in the $(TOP)/development/ide/emacs directory. ATM, you'll find android-common.el, android-compile.el and android-host.el.
These can be used to make modules/packages inside Emacs, replacing commands like mm and mmp.
I have used these three open source tools for packaging my java apps, but they all look like abandon-ware now. All three are very good pieces of software. What are the options now? (or is using Java for desktop app development no longer a "hot" market for app developers to build & maintain these tools?).
1) exe wrapper:
jsmooth - no new development in 2.5 years - does not support 64 bit.
launch4j - no new development in over a year, supports 64 bit, but you can't sign the exe created by launch4j, so I prefer jsmooth, but it does not support 64 bit.
2) onejar:
It works, but there has been no new development or web site update in more than 2.5 years. So, just want to switch to something that's supported / have a backup plan if it suddenly breaks with a new build of Java.
Thanks
Edgar
Launch4j has just been updated ! http://launch4j.sourceforge.net/changelog.html
Did you check IzPack? This is a great piece of software to create cross-platform installers:
IzPack is an installers generator for the Java platform. It produces lightweight installers that can be run on any operating system where a Java virtual machine is available. Depending on the operating system, it can be launched by a double-click or a simple 'java -jar installer.jar' on a shell. The most common use is to distribute applications for the Java platform, but you can also use it for other kinds of projects. The main benefit of IzPack is that it provides a clean and unique way of distributing a project to users using different operating systems.
Some really famous companies and projects use it for many years (Sun Microsystems, JBoss/RedHat, the Scala language project, some ObjectWeb/OW2 projects, XWiki and many more). If it's good for them, it should be good for you :)
Since none of the answers were approved, and JavaFX 2.2 has not been mentioned above (was not available at the time of the answers) here goes:
JavaFX 2.2 (part of Java Runtime and SDK since 7u6) allows building native exe/dmg/rpm's that tag along the full RT component as well. I believe this is a valid answer to your need, as well as an officially supported solution from Oracle.
https://blogs.oracle.com/talkingjavadeployment/entry/native_packaging_for_javafx
Have you tried IzPack (http://izpack.org/)?
You can try
http://winrun4j.sourceforge.net/
Has an exe with 64bit support and is quite easy to configure with an ini file.
As I was fed up with recent security changes in Java Webstart, I created my own tool, JNDT. It's under GPL.
It goes farther than akauppi's suggestion because it allows to create GNU Linux packages even under Mac and Windows :) I use it to create Mac bundle under GNU Linux too. For the moment, it's just a single Ant library with a few dependencies that allows to create native self-contained application bundles for GNU Linux, Mac OS X and Windows. I use it for my first person shooter and I'm very happy with it. It bundles the JRE but it can use the system JRE if you want.
P.S: JNDT is able to create a native Windows installer as an executable with NSIS even under GNU Linux.
I understand that the GPL license discourages some developers to use my tool. In this case, rather use PackR.
Maven 2 provides the ability to create a jar which contains all the dependencies as part of its assembly plugin. This combined with the jar plugin configuration of the manifest file (and specifically setting Main-class to the Class with main) is all you need to do basic packaging.
To some extent Java web start is now considered the better way to distribute Java applications and Maven 2's assembly capability combined with web start gets you everything you need without going via the exe route.
If you just want an exe (instead of a full-blown installer) you can make one with NSIS:
http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation
Yes, NSIS is an installer but you can have it just run a jar in the same directory by stripping out all of the installer stuff. Basically it works like launch4j but is a lot more configurable.
If you are using gradle, there is a plugin that uses launch4j (under the hood) and works great. It doesn't even require you to download or install launch4j, it is totally automated.
https://github.com/TheBoegl/gradle-launch4j