Understanding zeromq java binding - java

I'm investigating zeromq as a message passing solution in a java project, but I find the instructions on java binding somewhat difficult to follow. http://www.zeromq.org/bindings:java
I am unfamiliar with java bindings, so these may be stupid questions, but can someone help me understand:
Why do I need to install anything?
Will jars I build on one machine work on another system? I need this application to be portable.
If so, why do I need to build my own jars to begin with?
I feel like the instructions provided on zeromq require base familiarity with building C projects that I lack, so perhaps I am just being dense, but this seems like a lot of work.

As a fellow user of the Java binding of ZeroMQ, I sympathize. ZeroMQ is definitely one of the more challenging Java dependencies to manage. In it's heart of hearts, ZeroMQ is native C code and the Java binding is a (relatively) light weight wrapper around a JNI interface to the core ZeroMQ library and this is why it is complex to deploy.
As an aside - if ZeroMQ is a good match for your application, it's well worth the trouble because there really is nothing quite like it. Unfortunately this means you need to go through all these steps to get it working so you can decide if it is what you really need.
ZeroMQ for Java is based on three components:
libzmq - the core ZeroMQ library (DLL - required for any language, not just Java)
jzmq - the native portion of the Java binding (DLL)
zeromq.jar - the java portion of the Java binding (JAR)
Will jars I build on one machine work on another system? I need this application to be portable.
Yes. The jar will be portable. You can build it on any machine and deploy it on any other. However thats the easy part. The hard part is creating the various DLLs that are required and those are not portable. Let's say you want to support Windows, Mac and Fedora Linux. You will need native development environments on Windows, Mac and Fedora and build the DLLs for each platform you want to support.
I don't know enough about Linux to say whether a DLL built on one distribution (say Fedora) will run on another (say Debian). If not, then you have more work ahead.
Anyhow, your application will be portable - ZeroMQ and JZMQ can run on a huge number of platforms - but you will need to have tight control over your deployment process to ensure that when you install each platform, the jar and the appropriate set of DLLs are installed, and they are installed in the right place.
Why do I need to install anything?
Technically you don't. But I think they recommend doing the make install step so that the include and library files are where the compilers expect them and also so that Java can load them when it is time to run your program.
If so, why do I need to build my own jars to begin with?
I'm not a committer so I cannot say for sure. I expect part of it is developer efficiency - they would rather be improving the code than creating jars for users who could create the jars themselves.
More importantly - since the jars are not enough and you have to build the DLLs anyways, it makes more sense to build the jars and DLLs together. That way you are certain the JNI wrapper has exactly the right native methods implemented in C to match the native declarations in the Java wrapper class.
Good luck. Hope this helps.

Personally I do think pre-made JARs would go a long way to helping 0MQ in java. While I work in Java at many sites, they do not provide MSVS and having to go through such a lengthy setup just to get a dll and jar seems counter productive to me.

You can also look at JeroMQ (Pure Java implementation of libzmq).
JeroMQ is a full Java stack that uses the same protocol and API of ZeroMQ and is an official project of the community. It makes life a lot simpler for Java users since there's no JNI, no C++ to build. It does everything ZeroMQ does except PGM multicast.

Related

Is the best way to package jsvc with your java service as source code, then have people who use it compile before using?

I've noticed that many open source projects use jsvc (the apache commons daemon) for wrapping a java program in a service. I've seen several ways of including it, as source or with binaries for common environments. Is source a preferred method?
Unless you have a well defined set of supported platforms (e.g. like Apache BigTop) then you are better off sticking with source packaging.
Especially when JVSC is built with shared libraries, keeping your bundled binaries compatible across platforms is going to be a larger headache than it's worth. For a case study in this difficulty, you can read the problems Hadoop ran into when it attempted to bundle JVSC (they opted to skip even including source and went with requiring external installation)

How to install third-party APIs?

Sorry if this has been asked before, I searched but couldn't find anything.
I'm a novice (like, just now moving on to true object-oriented programming) Java programmer taking AP Computer Science online. Outside of class, I've been working on some programs for personal use. One program that I'd like to write needs some third-party APIs, notably Apache Commons. I'd also like to have Google's Guava API available, among others. The only problem is, I have no idea how to make the APIs available to my IDE. I'm still trying to decide on an IDE, so I'd like to make the APIs available system-wide if possible, but at minimum I need compatibility with IntelliJ IDEA 9 CE. I'm on Mac OSX, but I sometimes have to work on a Windows PC.
You need to download the necessary JARs and then in NetBeans, I believe there is a "Libraries" or "Classpath" menu option somewhere toward the end. Thats where you'll need to add the libraries you plan on using by referencing any JARs you've downloaded.
You can see it here from their website

How can I create a .msi file for a Java program ? (eclipse)

I have a java project which I'm hoping to package and sell. How can I create a .msi file which will install my program on other windows computers?
If there are any tutorials, please direct me to them. I'm also using Eclipse if that has any bearing on how to create the .msi file.
Thanks
I've been using WiX extensively for creating MSI packages. It has quite a steep learning curve, but once you know what you're doing, it is very powerful. You said earlier that it needs Visual Studio installed, but I think it's just .NET 3.0, not the whole IDE.
I used this WiX tutorial when I got started, and it's got pretty much everything you need in there if you want to go down this route.
If you're after something simple, search for a tool called WixEdit on SourceForge. This has a GUI for building MSIs - it's not perfect, but pretty easy to use and produces professional results.
I'll repeat, WiX has a very steep learning curve, and if you're just after a simple way to package your application, NSIS might be easier; or, you could use the standard IExpress.exe tool built into Windows to create a self-extracting .exe (but they don't "feel" as good as an MSI).
There's nothing special about Java apps when it comes to creating MSI's other then you have to make sure you have a JVM/JRE installed just like you have to make sure the .NET framework is installed for .NET applications.
Your question is too broad to be able to answer. Implicit in your question is "What tool should I use?" and once that's decided "How do I make an MSI using this tool?"
For the first question, check out:
Windows Installer Authoring Tools for Developers
Use NSIS: http://nsis.sourceforge.net/Main_Page . It creates executable file that will do the same thing, and it is free.
If you specifically want to create an MSI package, and assuming you don't want to pay for something like InstallShield, look at Wix. http://wix.sourceforge.net/
I believe you want to look at Native Packaging, which according to this link was first introduced with JavaFX 2.2
https://netbeans.org/kb/docs/java/native_pkg.html
Since it seems to be official Netbeans docs, I imagine it is sanctioned by Oracle. Here is the counterpart for Mac for interested readers.
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html

What are good InstallAnywhere replacements for installing a Java EE application?

Which (commercial or free) installer tool would you recommend to replace InstallAnywhere as the installer for a Java EE application? What do you specifically like about it, and what are its downsides?
Some requirements:
Must support running custom Java code as part of installation procedure
Must support Windows, including latest 64-bit versions like Windows Server 2008; support for other target operating systems is a plus
Must be able to install a bundled application server (such as Resin or Tomcat) as a service on Windows
Must support basic stuff like copying and moving files around, editing configuration files, extracting ZIPs, etc.
(Must support bundling a specific version of JRE; at the very least by including a ZIP to be extracted)
Edit: a few more points:
Preferably does not depend on a preinstalled JRE (or any other 3rd party runtime environment or library) on target machine; in other words, can produce an independent Windows .exe (or .msi)
The tool should preferably be cross-platform so that installer development can be done on Linux, Windows, or Mac.
Should preferably have a decent GUI for putting the installer together. Once that is done, however, it must be possible to skip the GUI and make installer building part of automated build process.
In this case, unfortunately, SO didn't tell us much that we didn't know already (and indeed the tool we ultimately chose was not mentioned in any answer). However, I'm posting our experiences here, as they might be helpful to others later on.
We (quickly) evaluated the following installer tools, mostly by looking at their websites and browsing for other information on the web: Actual Installer, Advanced Installer, BitRock InstallBuilder, Inno Setup, Install Creator, Installer VISE for Windows, InstallShield, install4j, IzPack, NSIS, openInstaller, Scriptlogic MSI Studio, Smart Install Maker, Symantec Wise Installation Studio, and WiX.
We screened out most of them early on, and ended up shortlisting two options for closer evaluation: BitRock InstallBuilder and install4j. For these tools, we downloaded evaluation versions and did some prototyping, to see if the things that are most important to us are really supported, and how easy or hard it is to get things working.
Both of the options were good in many things (and both seemed good alternatives to InstallAnywhere):
They produce completely native and pretty Windows .exe installers that are
easy to customise with your own graphics etc.
Both tools could easily be automated so that installer building is triggered from Ant. (With install4j it literally took me just five minutes to learn it and then implement it.)
Both companies seem to have good support (well, at least for prospects evaluating their products ;-) Especially from BitRock we got very quick replies.
In the following things install4j seemed better than BitRock for our needs (many of these are subjective, of course, so YMMV):
install4j definitely has better support for running custom Java code - it can be done at any point during the installation, and regardless of whether there's any preinstalled JRE on the system.
BitRock uses a more hard-coded sequence of installation steps while install4j is more flexible. In install4j, adding custom screens and forms (with or without custom Java code), asking user for input, etc., can be done at any point, before or after installing any files.
Also some basic things like defining the filesets that are to be copied to the target system, and adding an installation step to replace certain strings in configuration files seemed somewhat easier in install4j.
install4j has better support for JRE bundling
When creating installers on Linux, the look & feel of install4j IDE was nicer (more "native") than that of BitRock
(install4j's licensing options were better for us - we strongly preferred a couple of floating licenses to named licenses for all developers or an expensive "site license")
So ultimately we went with install4j. Here are some more details on why it was impressive:
Its IDE, where you put the installer together, is very simple and easy to use - I could figure out how to do most things I wanted quickly, even without looking at documentation. And when I did have to check something in the documentation (e.g. how to refer to installer variables; how to get started writing custom Java code against the install4j API), it didn't take long to find what I needed.
You can completely customise the screens and actions during the installation procedure, and also add custom screens and actions (coded against their Java API) at any point. This was important to us because we need to reuse existing custom Java code from the old InstallAnywhere installer.
In some small details, install4j seems ideal for Java developers. For example, if you want to add a validation script to check some user input, you can code that very quickly in the install4j IDE itself, using plain old Java, with coding assistance resembling that of IntelliJ IDEA.
We deemed the cost of install4j floating licenses reasonable, considering how good the tool is (and downright bargain compared to the inflated pricing of InstallAnywhere...)
In short, it seemed like the best installer tool available for deploying Java applications.
We created BitRock InstallBuilder, a crossplatform installation tool after some frustrating experiences with InstallAnywhere and specially its cousin (now defunct) InstallShield MP. More than half of our clients use our tool to package Java-based software but the tool is native, not Java-based. That means we have a number of advantages such as native look and feel (incl. Vista, GTK, Qt, etc.) and no need to do self-extraction previous to installation (faster startup, less space requirements) to mention a couple. To answer your specific questions:
Supports calling Java code as part of the installation at multiple points in time (such as when a certain page is displayed, files being copied, at uninstall time, etc.). The code is not compiled in the installer, but it can be called externally and the result used in the installer. If you are more specific about which kind of code that you need I can provide specific sample code. We have a lot of built-in actions for functionality that needs to be manually added to other installers, so you may not need to write that code in the first place!
We support all versions of Windows, including 64bit and Windows 2008 (multiple customers have certified on those platforms using our installers)
We support bundled applications servers, including Tomcat, Resin, JBoss and others. Take a look at BitNami for examples of such stacks that we have created.
We support copying and moving files, substituting values in config files, unpacking files and most other common installation functionality. One of our principles is that the installer should provide built-in support for common installation actions and have an easy, clean interface for invoking external code that is specific to a client's product.
We support bundling JREs, as you mention is often enough just to bundle the JRE directory and setting the appropriate value for JAVA_HOME in the launching scripts
You can take a look at some of our customers such as MySQL, Samsung, Motorola, GitHub, etc. InstallBuilder is a commercial product, but we offer free licenses for open source projects and discounts for small business and microISVs.
Just want to add that my company has used InstallAnywhere for about 6 years but we have decided to move on. The reason is two fold.
First of all their pricing is absolute highway robbery and the licensing is severely restrictive compared to direct competitors like INstall4J and BitRock.
My other problem with InstallAnywhere is the product is only minimally maintained. I have been using the product for 6-7 years through many different versions and bugs are rarely fixed and you surely can't expect new features. Essentially all you can expect is that they will add support for the new version of windows/mac as it comes out. Their support charges are quite pricey, but I have never had a support request actually implemented. When I first bought the product I believe it was from a company called ZeroG who were focused solely on this product. They actually maintained and improved the product. Back then it was the only real ticket and they were leaps and bounds above the competition.
Then it was acquired by Macrovision and then Flexera. Ever since ZeroG sold the product it has been an ancillary product for the owning company and the focus on it has been poor. It seems like it was bought more to complete a suite of products rather than because the company actually wanted to maintain the product.
Word of caution, evaluate these products carefully because you can become tied to them. We would have left the product sooner, but we put so much effort into not just the installer, but setting up an automatic update scheme based on the features/limitation of the product that it is expensive to leave the product because of the labor investment to reproduce this in a new product.
Just my take, but I wouldn't recommend InstallAnywhere.
I can vouch for izPack. It's Ant-based so you can package up an Ant install in it, and that Ant install can contain custom tasks, and/or scripts written within your Ant build.xml (e.g. using Groovy, Beanshell or any BSF-enabled scripting language). So it'll cover your customisable requirement.
I've used it in the past for all the above - unzipping/services/custom code. It's multi-platform, although I can't vouch for that specific instance above (64bit Windows). But if it runs Java, you should be fine.
The one headache is the JRE. You'd obviously require some JRE to run this. However I think you should be able to pack up and execute a specific JRE installation within izPack.
Currently we are using GetDown to handle distribution of our swing applications. We use Tomcat to distribute updates and GetDown to download those updates. It's really flexible and powerful, and much better than java WebStart and because it produces check sum for changes it saves bandwith and downloads just changed files.
A good tutorial : http://www.hascode.com/2012/05/creating-updatable-java-applications-using-getdown-and-the-getdown-maven-plugin/
Project website : https://github.com/threerings/getdown
Deployment in an multi-platform environment is always a big source of troubles. It think that the optimum solution would target the creation of native packages for all platforms, like RPM, DEB or MSI ... the ones that could be installed unattended also.
Developers should work on making the application self-healing and run without installation.
Doing so will payoff in minimize the deployment efforts.
I know this is not quite a solution as you where asking but sometimes you may get better results this way.
Remember that you'll get free updating service on Linux if you follow these.
I still hope Microsoft will add something similar to MSI (and that would not require you to register at them). Meanwhile for Windows you can take a look at Google Updater just released as open source - http://code.google.com/p/omaha/
They released a similar product for Mac OS http://code.google.com/p/update-engine/ but sad that they didn't think about creating one product from these two.
You can try the SetupBuilder Gradle Plugin to create a native *.msi installer with a simple Gradle build script.
It is free.
Supports 32 bit and 64 bit Windows. Also Linux and OSX.
Bundle the Java VM under Windows and OSX, does not required a preinstalled Java VM.
Can run Java Code before or after the installation.
Can create a windows service/daemon.
Has not a GUI but use Gradle. If you already use Gradle as build script language then it is very easy.
you may be interested in launch4j
Jonik, thanks for posting such detailed feedback of your experience. I wanted to write a follow up answer, since you raise some good points.
After certain base requirements are met (which unfortunately InstallAnywhere does not any more) there are not really 'bad' or 'good' tools, but rather tools that are better suited for some projects. It seems you studied carefully all options and install4j will work better for your project. This is probably a good choice, since you have an existing Java codebase from your previous installer that you want to reuse (though I would like to think some of that code would not be necessary with InstallBuilder :)
Regarding InstallBuilder, we support customizing the screen sequence using the <insertBefore> tag (we probably should better document this). It is also straightforward to bundle a JRE (just including the java/ folder in most cases) but I think your criticism is valid: since this is a common task we should do a better job at documenting / making it accessible though the GUI, including drag-and-drop in all supported platforms. We already have in our roadmap improving the GUI in the areas you mention. The funny thing is that a lot of our customers find the XML format so easy to use that they prefer editing it using their programming editors (as if they were editing HTML)
Finally, regarding licensing, our current model does not require purchasing additional licenses if those extra programmers will just be building the installers (not designing them) or purchasing extra licenses for build or continuous integration machines. In any case, a couple of floating licenses for install4j are more expensive than a full Enterprise Site license for BitRock:)
Thanks again for the feedback
I recommend having a look at cmInstall, which can be found at
http://sourceforge.net/projects/cminstall/
It meets almost all your requirements and it's open source. Plus I'm one its developers :).
[yes] Must support running custom Java code as part of installation procedure
[yes] Must support Windows, including latest 64-bit versions like Windows Server 2008; support for other target operating systems is a plus
[can be easily done by using 3rd party libs- e.g.:Tanuki Software] Must be able to install a bundled application server (such as Resin or Tomcat) as a service on Windows
[yes]Must support basic stuff like copying and moving files around, editing configuration files, extracting ZIPs, etc.
[yes - or you can programatically download & unzip it ]Must support bundling a specific version of JRE; at the very least by including a ZIP to be extracted
6.[no - it needs jdk 1.6 installed, support for .exe or .msi is planned for future]Preferably does not depend on a preinstalled JRE (or any other 3rd party runtime environment or library) on target machine; in other words, can produce an independent Windows .exe (or .msi)
[yes] The tool should preferably be cross-platform so that installer development can be done on Linux, Windows, or Mac.
7.[no - the cminstall framework is "developer based" - but easy to use.Just read the tutorials from http://sourceforge.net/project/showfiles.php?group_id=250019&package_id=305489 and see how easy it is to build an installer!] Should preferably have a decent GUI for putting the installer together. Once that is done, however, it must be possible to skip the GUI and make installer building part of automated build process.
I have also reveiwed few of the open source multi platform installers. Here is my comment:
BitRock InstallBuilder: Only Great for free and open source developers as it gives free license for use in open source projects.
InstallJammer: Good free and open source multi platform installer. Only one concern that as soon as one downloads the executable build from InstallJammer, the anti-virus program will immediately delete it. Somehow files built from InstallJammer are being caught as False Positives. You will have to work a bit more security certificate before publishing.
Izpack: Good free and open source multi platform installer. It may be a bit cumbersome for people not used to with ant. May be great when used with GUI front-ends like PackJacket.
I've seen several people recommend IzPack, but I honestly don't know if it meets your requirements. It's at least free :)
Sun offers an open source installer:
OpenInstaller
I'm sure that all your requested features are supported.
But it seems for me a little too hard to configure.
But guess what: It has not only a GUI but also a (pseudo-graphic) CLI.
Nice screenshots and info here.

What's the best way to add a self-update feature to a Java Swing application?

I'm trying to figure out a way to add a self-update feature to a Java/Swing application I'm working on.
Basically I've got a bunch of jar files with extra functionality to be re-deployed to the installed users when they change. Nothing complicated, just check if a new version has been released, download them over HTTP, and then optionally offer to restart the app to the user.
I had a look at webstart, and it could work. But this particular app does some funky stuff with classloading and GC memory settings that don't look like they are supported via webstart, or will at least complicate matters. (It's a tweaked build of JMeter)
I also went down the road of adding in this plugin handler http://swing-fx.blogspot.com/2008/06/add-auto-update-and-plugins-to-your.html, but it is very alpha, and tries to do too much with the usual bugs you get with alpha stuff.
I did the exact same thing. But that was long back so there are probably better tools today.
What I found out I needed was a loader. The loader main program did not have the app jars in classpath. It first downloaded an update if required and then created a custom classloader with the app jars in class path and invoked the main method of the application main class. It is not very complicated. IIRC I needed to do this because the jars could not be overwritten in windows if they were already in classpath.
Hope this helps.
we had a swing app 6 years ago that had self-update. like you suggested,
1)it downloaded the latest jars over http,
2) copied them to a folder.
3) since the swing app is launched using a .BAT file, after user said YES, we would shut down the swing app and look for any files in the update folder. if yes, launch another .BAT file to copy the NEW JARs to the required directory.
4) then re launch the swing app.
Updates, plugins, separation of concern etc. are exactly what OSGi is about - you might want to take a look at this. It won't come free (read: with a steep initial learning curve, especially when you are currently using classloading tricks) at least there are good open source implementations (felix - see felix.apache.org, equinox - see www.eclipse.org and others)
For these implementations autoupdaters are available - if you write your modules correctly it's possible to update at runtime without restarting.
I believe you should look again at Java WebStart, or at least detail the "funky classloading" which you think is going to cause problems (as it might also cause problems with any solution proposed here).
IIRC, you can set command line parameters using Java WebStart ( http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html#resources ).
I would definitely first try out Webstart. We've had lots of success launching even the early Eclipse RCP apps using Webstart, and you can probably not get more funky classloading issues than with the OSGI framework (Eclipse Equinox).
Could you perhaps give some more detail in your question about you classloading approach?
Regarding the GC and other VM settings: these are easy to specify in your JNLP (Java Network Launching Protocol) files used by Webstart for launching apps.
The Java Web Start is good choice. The GC stuff is not important. Classloading could be problem. But when you got trusted by user you can grant AllPermisions and you will be able to do custom classloading. Maybe it will be good to reconsider funky stuff with classloading. It is really necessary? Or look at NetBeans. There should be found inspiration for auto-update.

Categories

Resources