I am developing a Java 1.6 based cross-platform (Mac OS X, Win and Linux) application. For better integration on Mac Os platform I have to use Mac OS X specific classes, which are neither available on other platform's JDK or JRE nor can be distributed with the application.
My questions is what is the best strategy to keep code compilable on both Mac OS X and Win platforms without maintaining two different versions?
There is a play with ClassLoaders. It is very similar for plugin development, at least there is used often:
you will build the main, cross platform application
you will declare an interface
you will create a "plugin loader" which will load available plugins. on macosx the mac one, on windows the windows one.
develop and build 3 plugins: mac, linux, windows
-autolink it at runtime with classloader.
I think you won't be able to compile code that uses those classes, unless you restrict all uses to reflection. And that probably leads to a lot more problems than it's worth.
You could extract the Apple-Specific parts into a separate artifact/project and compile that only on Mac. And reference that via a pre-defined (shared) interface in the main project. This way you can simply try to load the Apple-specific code via reflection and if that doesn't work, use a dummy implementation.
Related
I just developped my first program with JCUDA (on eclipse) and i want to execute it on other machines that don't have the same nvidia-driver and compilers i used to develop it.
How can I export just the executable to another machine and execute it without recompiling the code ?
Any help will be appreciated
(Sorry, this may not fully answer your question if you expected a step-by-step-manual. I'll consider doing some experiments here, and maybe extend this answer or add the information on the website)
For the driver API, the CUDA version on the target system must at least be that of the corresponding JCuda version - otherwise, newer CUDA functions would simply not be supported.
Regarding the runtime libraries, quoting from the CUDA FAQ:
Q: What do I need to distribute my CUDA application?
Applications that use the driver API only need the CUDA driver library ("nvcuda.dll" under Windows), which is included as part of the standard NVIDIA driver install.
Applications that use the runtime API also require the runtime library ("cudart.dll" under Windows), which is included in the CUDA Toolkit. It is permissible to distribute this library with your application under the terms of the End User License Agreement included with the CUDA Toolkit.
So in doubt, you may include the "cudart.dll" that you used for compiling your application into the distribution package.
Newer versions of CUDA also support static linking against the runtime DLL, but this is not (yet?) done for the JCuda runtime library.
Eclipse is java application and should run on OS that has compatible jvm, eg: Linux distribution of eclipse should work on linux whatever may be the hardware, but still Eclipse has a separate distro based on arch , like ppc, x86 etc.
I tried the eclipse source build and it has parameter for hardware.
Is this because eclipse is built that way? or its jvm limitations
Eclipse uses SWT, which is a GUI that uses platform-native UI facilities.
http://eclipse.org/swt/
If you look into the plugin directories, you'll see lots and lots of dlls, at least under windows. This is for stuff like SWT, for the GUI. Also, for the builtin web browser, which is based upon XULRunner.
Is eclipse platform independent?
As per my knowledge, eclipse is written in java. If it is so eclipse should be platform independent. But there are different eclipse for different OS???
No, you need to download a platform specific version because of SWT which accesses the native GUI libraries of the operating system using JNI. Note that Eclipse provides versions for most platforms (see for example All Platforms for the Eclipse SDK 3.5.1).
There are distributions of Eclipse for most Intel/AMD based platforms and for major UNIXs.
You are also supposed to be able to compile and build it yourself on other platforms.
The differences stem primarily from three issues:
1) Availability of needed Java distribution on the platform (e.g., late introduction of newer Java versions on Mac).
2) 32bit vs. 64bit
3) Underlying UI toolkit
While Eclipse can run under Swing, it may look like crap and perform pretty badly.
People often expect more from the IDE, so the SWT can use some native widgets. Some plug-ins also need more direct access to the graphic subsystem. This, there are specific distributions of Eclipse that use specific platform graphic infrastructure. The most notable example is again Mac OS, where there was initially a version for Carbon, but only much later did a Cocoa version show up.
Most OS should support Eclipse. As long as it supports Java and SWT
If it is 100% java-based application, yes it will be platform independent. The problem is some code of Eclipse is not Java, so it's obvious that because of this code, Eclipse is not 100% platform independent. You can however just change that particular native jars with the suitable jars for your platform and Eclipse will then run correctly.
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
I have created an exe with a launch4j Ant script and build.xml file. I want to bundle the JRE in my application and have to distribute it to clients. How do I do this?
Thanks,
Rajani
Well, just bundle everything under $JAVA_HOME/jre into your distribution (presumably a Zip/TAR file) and then have your scripts reference that (i.e. use the java executable under $JRE_HOME/bin to run your java program).
Remember that if you do this, you will have to deliver different distributions for different target platforms (Windows,OSX, linux etc) and architectures (or one bloated uber-distribution of course, but no one will thank you for that!).
This works great... if you want your program to run on just a single version of a specific OS.
Generally, though, bundling a JRE is a bad idea. Even on Windows, there are three versions of the JRE: one for x86, one for x86-64, and one for Itanium. Even if Sun does make it hard to find the 64-bit versions, they still exist.
The 64-bit versions of Java for Windows are actually on java.sun.com, but not java.com.