I have studied Java Web Start and found it complex and clumsy for my purposes. In addition, my app needs to access the PC resources, which causes more hoops to be jumped through with Java Web Start. To add to the difficulties I need to access a 32-bit native library (libvlc) so I need to insure that my app runs under 32-bit Java. Is there an easy way to deploy my app without resorting to Java Web Start? Needless to say, I want everything to be contained in a single .exe file.
I would start by searching the Internet for keywords such as "java 2 exe" and "jar to exe", etc. Doing so yields many freely available software packages that convert Java programs into Windows executables, for example:
JexePack - http://www.duckware.com/jexepack/index.html
JarToExe - http://www.regexlab.com/en/jar2exe/
JSmooth - http://jsmooth.sourceforge.net/
And the list goes on. Perhaps one of them meets your needs?
I am answering my own question to help people understand how to do this, which has taken me some number of days to figure out.
My initial problem was that my app would run on some versions of Windows but on others it was having problems finding the libvlc native library. I finally figured out that my app must run with 32-bit Java in order to use the 32-bit native library. Thus, the problem then became how to insure that the user started my app with 32-bit Java.
I read about Jar2Exe (http://www.regexlab.com/en/jar2exe/) in another post and decided to check it out. It is a great little program that is very configurable so I figured that it must be able to handle my 32-bit Java problem. In fact, it does so without even needing to do any configuration. The resulting .exe file contains my app along with all the required jar files and starts up with the 32-bit Java. I am very pleased with this program and plan to buy a license, which is very cheap.
Hope this saves time for other people who are trying to solve a similar problem.
Related
I am writing a macro scripting program in Java (JavaFX). I would like to add global keyboard listeners to interact with the program while it is not focused. I have heard of JNativeHook, and it looks useful. My question is, if I decide to use this library, will my code still be portable? Could I still distribute it to others without requiring them to install other things?
You can absolutely include native libraries in a portable app as long as your code can find the DLLs in question and you bundle them with your software. I personally use SIGAR in portable apps and it works fine as long as the relative path remains the same, depending on how you load your DLLs.
******EDIT******
That is of course if you remain within a Windows environment and you are indeed talking about DLL files. If you mean additional JAR files that do not require anything else than java code contained withing JAR files then yes your app will be fully portable, cross-platform too. That is what i love about Java, i once developed a large app on Windows and it ported to Ubuntu with no modifications whatsoever.
You can make your app portable if you don't need any special insulation for a different device uses different platform so in your case the library you asking for JNativeHook need some requirements mentioned here https://github.com/kwhat/jnativehook#software-and-hardware-requirements. You have to give instruction to your user to have these requirements based on the platform he/she works on.
Does anybody know how to embed a Java runtime into a Mac Cocoa (sandboxed) app so that the app can run a .jar file without the user having to install Java separately?
We have a Cocoa application that we sell through the Mac App Store as well as on our own site which can use Java for a specific task. It's a writing app, and because the standard NSText exporters for .doc, .docx and .odt are very limited (not supporting headers, footers, images etc), we write out to RTF and then use Java-based converters (from Aspose.com) to convert the RTF to .doc, .docx or .odt, depending on the chosen export format.
I do this by by using NSTask to call on /usr/bin/java and run a bundled .jar file that runs the conversion routines. This all works beautifully--as long as Java is installed on the user's Mac. If it's not installed, our app asks the user if he or she would like to install Java to benefit from the enhanced converters, or instead fall back on the NSText lossy converters. If the user chooses to install Java, we call java_home --request to invoke OS X's Java installer.
However, now that Apple has ended (or is ending) direct support for Java, this approach is problematic. During our last Mac App Store review, we were told that we would soon need to stop asking the user if he or she wanted to install Java. I have read that Apple's recommended route going forward is to embed a Java Runtime Environment into Cocoa applications that need to run Java. (E.g: http://lists.apple.com/archives/java-dev/2011/Jul/msg00038.html )
Over the past few days, I've therefore been researching how I can go about embedding a JRE in my app, but I haven't found any instructions on how to do so anywhere - nothing that I understand, at least. Someone asked a similar question here a couple of years ago:
Bundling a private JRE on Mac OS X
However, the answers there, and on other sites I've found, are all about bundling a Java application as a Mac application, not about including a JRE with an existing Cocoa application. (Although I accept that my lack of experience with Java may mean that I just don't understand how to convert the instructions for my purposes - take me out of Xcode and I'm out of my comfort zone.) Likewise: https://wikis.oracle.com/display/OpenJDK/How+to+embed+a+.jre+bundle+in+your+Mac+app
It seems that a couple of applications have done this (e.g. Cyberduck), but no one has documented the process yet. From what I've read, I think I need to either grab the Java Virtual Machine from Oracle's JDK or OpenJDK and include that in my Cocoa app and call on java from within that, but if I did so, the Java executables within the copy of the JVM wouldn't be sandboxed, so my app wouldn't get through the MAS review process. So presumably I need to somehow build a copy of the JDK and sandbox it, most likely as part of my larger Xcode project? I'm not even sure where to start; I'm guessing it's still early days and that not many Mac developers have had to do this yet.
Has anyone got any experience of embedding a JRE into a Cocoa application in such a way that the app can just call on it using NSTask? And in such a way that the JRE is fully sandboxed and thus acceptable by the Mac App Store? Or, has anyone successfully created a sandboxed Cocoa app that runs a .jar file without needing a separate Java installation? If so, would you be willing to share how you did it?
(I took out a developer tech support incident with Apple asking for help on this, but was told that they couldn't help at all given that Java is now considered a third-party development environment.)
Many thanks in advance for any suggestions or pointers to web pages I may have missed.
I can't be sure, but I strongly suspect that when that Apple engineer says they suggest "embedding" the Java runtime, he doesn't mean "bundle a separate executable into your app bundle and run it in a separate process" so much as he means "spin up a Java VM within your own process and run what you need to in that VM." It's arguably more cumbersome to do this than it is to run Java in a separate process, but it is possible.
Have a look at the NSJavaVirtualMachine class. It may not help you if the user doesn't have Java installed, but the idea would be the same - you would just build yourself a library containing the Java Runtime, link it into your main binary, then create and manage the JVM using the JNI API. Google for JNI_CreateJavaVM.
I gave a quick example of spooling up a JVM and calling into Java using JNI in another question (Calling a Java class function from Cocoa with JNI), although that was predicated on using the Apple-bundled JavaVM.framework, so it doesn't include steps on building the library you would need to link. I don't have any experience with that, unfortunately.
To answer your sub-question about sandbox and aux binaries, that's not a problem. You just have to mark the binary as inheriting the sandbox.
Have an .entitlements file like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
</plist>
And make sure you have a build phase in Xcode that codesigns the aux binary:
codesign --entitlements myjava.entitlements -s "${CODE_SIGN_IDENTITY}" java
This is a single question, but with a couple of sub questions. I am planning a Desktop application using Java and I am using NetBeans as the IDE. Questions:
Why are there so many versions of Java? Java, Java SE, Java EE, Java Me
I want the application to store data locally, what is best Java DB or SQLite?
Do I need anything extra to create a setup file for my clients to install the application?
Is it there a Java solution similar to .Net OneClick to keep the clients updated to the latest version of the application?
I have plan to run the application in Windows, but if I have to ported to Mac or Linux how hard can it be?
There are different java libraries for different purposes. Java ME for instance, is designed for cell phones / mobile devices. You'll probably be fine with java SE, unless you need some of the features from EE.
Depending on how complex your data storage is going to be, you may not even need a "database." In java, any object which implements the "serializable" interface can be written directly to a file. So, if you're just trying to store things such as user settings, etc, you can create an object to store them, implement Serialiazable, and write it to disc.
Only if your application links to code libraries which you don't want packaged in the same directory. You can package it as a self-executing JAR from netbeans, it'll be similar in function to an .exe
(Shrug.)
If you are careful not to use operating system specific paths, a self-executing jar will work immediately on any operating system with the JVM installed. There may be a couple other quirks, but Java is built to be extremely portable.
Because you don't really need everything everywhere. For example you don't really need to use GPRS or SMS from you computer, or ORM from you phone. Each edition is targeted to a specific environment. This way you can have a lighter environment for mobiles, and a lot more components for enterprise applications (which you don't really need of a standard application).
I would advise you to use JavaDB (or Derby) but it really depends on you
Not really, you could offer a nice solution to install your application, but it's not necessary.
There is (I don't remember, but other answers will certainly help)
It's really easy, in particular for unix application, the executable creation will basically be a .sh file launched directly (you could of course have a real executable on UNIX, but it's really common and easyier to maintain to have .sh files) (you could also use .bat file on windows, but let's say that's just less common)
I re-read the question and might have not really answered the last point (I was still on .exe creation) so here is a second shot :
5.It's the main goal of java, to be ported everywhere. As long as your code doesn't use specificity of your system (or it's protected with ifs) your code will work everywhere. Of course you have to use the same java edition (edition, not version) and the same libraries or you could have problems.
Why so many Javas? Java, Java SE, Java EE, Java Me
So many environments. The first two are desktop, EE is server side, ME is phones.
..3. Do I need anything extra to create a setup file for my clients to install the application?
Use Java Web Start.
That also covers 4. & 5.
I have no opinion on which is the 'best' DB, but note that for small amounts of data, JWS provides mechanisms where even sand-boxed apps. can store and retrieve information, alternately the installer-desc element can be included in the launch file to install/set up the DB.
This problem is really befuddling me and hopefully someone could help me out. I've written some plugin libraries for a large java software. Everything works fine and well on my development computer. However, after I compiled and wrapped the software in Nullsoft Installer and install onto another computer, everything but the native dll plugins I developed runs, and I get a UnsatisfiedLinkError when I call System.loadLibrary. The installer works on my dev computer, the installed software runs fine even after I moved the original software. Here's what I do know:
the native libraries are deved in .NET (C++/CLI) hooked in by JNI
The software on the new computer is loading the right library path, can see the native dlls. In Java, I've added a segment to check the permissions on the files using File class, Java runs fine on library_dll.canRead() and library_dll.canWrite(), but hangs/crashes on library_dll.canExecute().
If anyone can help me, I would really appreciated it!!! Thank you all!
Does the target computer have .NET installed, and the right version of .NET at that?
I can't say I've ever done any .NET/JNI interop - it sounds potentially tricky to me. Have you looked at using JNBridge to make things easier?
Thanks Jon! No, the target computer does not have .NET installed (at least none more than the ones windows have at default). But it seems like JAVA/JNI can't even load the dll... I will try installing .NET framework and see
.NET/JNI interop was not the difficult part, that is working on my dev comp... It was tricky but not too difficult.
I would suggest that you run FileMon on the computer which is giving the problem, and then try to run your application. After FileMon captures data, you should see all file accesses made by your Java application and see the exact failure which leads to the UnsatisfiedLink error. For example, it may be that some dependency of your JNI DLL is missing on the other computer (this sounds like a good possibility, after security/permission errors).
Is it possible to integrate a Matlab program into a Chrome extension using the Matlab Builder JA?
Essentially, I have a computational tool in Matlab that I want to make more user-friendly and widely-available for other researchers with few or no programming skills. The best way to do this seems to be deploying it on the web--and, since I don't have access to a web server, in a Chrome extension. In order to deploy Matlab on the web via Java, it seems I need to upload the JRE or JDK and do a lot of other configurations on a server, like in http://www.mathworks.com/help/javabuilder/web-deployment.html (need a Matlab account to view).
Any workarounds for the extension that don't require a web server? Or other ideas to distribute my package to non-programmers so that they can use it?
Thanks!
I was in a similar situation, and I solved it in a slightly more elegant way than trying to play with web plugins:
In order to make the functions of my package accessible to non-programmers, I built a very simple GUI using guide in matlab, which allowed users to open data files, choose processing parameters, run the analysis, and export the results. Guide is very simple to use, and there are some good tutorials online. Then in terms of distributing it, I packaged all the necessary matlab files into a single folder, and then wrote a bash script (linux/mac) that would copy the files into a sensible directory, make a shortcut in /usr/bin/ (so that the GUI could be opened directly from the command line by running scatter_analysis without invoking any other display from matlab), and finally make a double-clickable shortcut on the desktop. The only prerequisite is that the user has matlab installed already.
I presume you're using windows, which I know nothing about, but I think it's likely that you can come up with a similar solution on the windows platform with far less effort than wrestling with web plugins? Unfortunately I cannot share my code - I'm in the process of selling it and any disclosure would violate the terms of the sale.