Releasing a java application on different OS - java

I have a java application that I want to release as an exe or dwg etc so that users on different platforms can double click it and get it to start running.
But for my code to work really well I need it to work as a windows service and whatever the equivalent of this in other OS are.
Using Java web start is not a solution because as I understand it, if the client machine shuts down then the user will have to again double click on the exe.
I have tried java service wrapper but I can't see how to make it releasable.
Thanks
Pranabesh

If a commercial tool is acceptable for you, I'd recommend install4j. It can produce installers for the most common plaftforms, which specifically support installing the application as a service.
Quote from their Features page:
install4j offers full support for generating and installing services (daemons). For services, install4j generates service executables on Windows, startup items on Mac OS X and start/stop scripts on Unix/Linux platforms.

Java Service Wrapper is a way to go for Windows/Unix/OSX. I've been using it with no problems for some years. It's a great software and handles JVM crashes/hangs well automatically restarting the service if something bad happens.
What concerns the distribution of the application, I'd recommend NSIS on Windows. It can create a nice installer that will put the files where necessary and run the JSW stub to install the service on the target system. For Unix you can just package it in tar.gz and provide instructions on how to install the service (copy the sh script into /etc/init.d, install it using chkconfig or any other system dependent tool for managing startup scripts). On Mac you should package it into dmg.
You may also try izpack if you want a more cross-platform solution. izpack can run from the java web start, as a native windows application or mac application, check the utilities page.
IzPack is a one-stop solution for packaging, distributing and deploying applications.
It is fully cross-platform and generates a single installer. As such, it is an alternative to native solutions such as platform-specific installers and package managers.
IzPack-generated installers only require a Java virtual machine to run.

You would need to build a release package for each operating system you were to release on.
For Windows, for example, you will need to find an executable wrapper. It's been a while since I've done this, but I remember usign a couple that would actually build an installer as part of the proccess.
Launch4j is one I've just remembered

Related

Using MATLAB (Windows) generated Java package in Linux

As far as I know, I can run .mex files on Linux that were generated on Windows by installing Matlab Runtime on Linux (correct me if I am wrong). But what if I want to use a MATLAB generated java package, that was generated on Windows, on a Linux (like Ubuntu)?
Objective:
I have to test a feature that uses audio processing. If test is successful, we will buy the products we need. At the moment I have my requested license on Windows, since the requested license have machine specific limitation, I am able to generate some test java code on my Windows machine, now the application is to be deployed on android, so I learnt from google that it needs matlab runtime to run or compiler to use converted/generated code. Android system has no MCR or simple Matlab Runtime installation support, so I moved to this solution.
Use a linux to host servlet that takes some input from android, do processing return answer in terms of json or text. Now my java package is generated using Windows machine, and I am lost.
From my knowledge this code-convert-servlet-deploy-once approach is cost effective than MATLAB Production Server, since we have to buy license once for the specific products. Remember licensing phase is after we test if this approach is giving us desired results.
Specs:
Windows 10
MATLAB 2016a (Trial)
MATLAB products (Compiler/sdk, Signal Processing/Audio Processing Toolbox)
Package made using JDK 1.7.x (Exactly matching MATLAB jdk/jre version on Windows)
Ubuntu 16 Desktop (with Oracle jdk 8_101 installed, also MATLAB Runtime installed, I can also work with jdk 7.x (same as MATLAB used on Windows when generating package))
Questions:
How can I use this java package in Linux when I create a java program?
What software + licenses are needed to make it possible?
Should I install MATLAB ON Linux machine, generate Java Package ON Linux machine and use that package in java program ON same linux machine? ( I think I will need to request license for it again )
Are there any other methods? Am I missing something?
Java packages generated by MATLAB Compiler SDK are in general cross-platform - however, they may call mex files, or other libraries, that are platform-specific, and if they do the Java package as a whole will end up being platform-specific.
You aren't entirely clear about whether you're calling mex files or not; and you may be calling platform-specific libraries without realising it (for example, Signal Processing Toolbox might call out to some library for some of its operations).
In addition, your comment about being "able to run mex files on Linux that were generated on Windows by installing the MATLAB Runtime on Linux" is confused - mex files are not cross-platform, and the don't use MATLAB Runtime at all.
So with respect to platforms - you may be able to use a Java package generated on Windows on Linux, so long as it doesn't call any Windows-specific mex files or libraries. But if you generate it on Linux, you can rule that issue out, so it will be easier for you if you use the same platform for compilation and execution. It should be fairly easy for you to reassign your MATLAB license to a Linux machine to do that.
Am I missing something?
Yes: the way you're proposing to do things is very unlikely to scale well. If you have a Java servlet on your Linux server along with a Java package generated by MATLAB Compiler SDK, then whenever you make a call to the servlet it will make a call to the Java package, which will start up the MATLAB Compiler Runtime (MCR), run your MATLAB code, return the answer to the servlet, and then shut down the MCR.
The MCR takes quite a long time to start up (nearly as long as MATLAB). So each call will take rather a long time, just due to MCR startup times.
So you can get around that by creating some sort of utility tool that will start up a an MCR and keep it there, and pass through requests and return answers to the servlet.
But then you've only got one MCR - what happens if you get multiple requests at once? They'll be queued up (or dropped) and it won't scale. So you'll need to improve your utility tool, so that it manages a pool of MCRs and passes requests through to a free one, load-balancing them as it goes.
But then what happens if an MCR crashes, or runs ouot of memory? The utility tool will need to monitor that possibility, and restart any crashed ones.
And you'll need some extra stuff that will enable you to administer all that stuff conveniently.
Once you've done all that (which will be hard), you'll realise that you have now pretty much written MATLAB Production Server. I know it's expensive, but you might like to take another look at it before committing to the solution you're considering.

How to create a setup file for a project that was written in netbeans?

I have created a GUI application using Netbeans and it has a connection to a database( localhost).
Now I want to be able to distribute it as software.
Is there any way to produce a setup file for the Netbeans project? and how can I distribute a Netbeans project which uses a MySQL database?
how can I distribute a Netbeans project which uses a MySQL database?
You might want to get familiar with NSIS. NSIS will enable you to automate the installation process.
Your installation process will have to do the following:
Check that the Java Runtime Environment is the same version you used or higher.
Install your application JAR file somewhere.
Install the MySQL version that your application requires
Create and initialize the tables for your application.
Your installation process can do the following:
Create an uninstall executable.
Add an icon so that the user can start your application.
This installation process will take some time to develop and test.
You probably want to use an installer. Have a look at:
Install4j
Installshield (commercial)
Advanced installer if you target only windows platforms
There are many others but I hope this can help you...
Use the solution made by the suppliers of Java - Java Web Start.
The deployJava.js (described in the linked page) ensures the user has the minimum JRE needed to launch the app. & MySQL.
Launch the app. using Java Web Start.
Reference an installer-desc extension for installing the DB. Store any set-up details into the PersistenceService for later use.
JWS works on all major platforms for which J2SE is available and also provides..
..many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

execution of JAVA application with System.load(dll)

is it possible to run java app on linux (with installed java and etc) server with this execution of a command inside the java application?
System.load("path to .dll");
And..
www.mono-project.com can help me do my task for this application?
DLLs are Windows-specific native libraries. You cannot normally use a Windows DLL on a non-Windows operating system such as Linux. You'll need to have a Linux version of the DLL; this normally has the extension .so.
The Mono project is an open-source implementation of Microsoft's .NET framework that runs on Linux (and other non-Microsoft operating systems). It does not help you to run arbitrary DLLs on non-Windows operating systems.
I'm not sure if this will work on Mono but you might want to look at:
Launching an application (.EXE) from C#?
And here is a Mono example:
mono Process.Start how to find bash?
I'm wondering did you even do a search? :)

Installer for Java Desktop Application

I am developing an inventory system i-e a java desktop application. I am using Ms Access as database engine and there are certain modules e.g one makes reports using ireport and other such dependencies. I need to ask how can I make installer for my application which will install few fonts, copy database files, install jre to make it run etc. Please guide me in it.
Thanks in anticipation.
This is something I've briefly used in the past, and it may serve your needs. It's an open source installer builder system, tailored towards Java apps.
http://izpack.org/
I've used jsmooth which creates a single EXE-file that unpacks and run transparently. Not a full installer but worked well for us.
Note: I have not seen any Java installers which asks the "There is an update available. Update now?" question.
If this is important to you, then consider Java WebStart which checks for updates at each launch (but do not ask).

java background/daemon/service cross platform best practices

I am looking for the best way to make my desktop java program run in the background (daemon/service?) across most platforms (Windows, Mac OS, Linux [Ubuntu in particular]).
By "best way" I am hoping to find a way that will:
require a minimum amount of platform-specific code.
not require the user to do anything a general computer user couldn't/wouldn't do
not be a resource hog.
I understand that my requirements may be unrealistic but I am hoping there is some sort of "best practice" for this type of situation.
How to go forward?
You can run a Java application as a service (Windows) or daemon (Linux) using the Apache Commons daemon code.
Structure
Daemon is made of 2 parts. One written in C that makes the interface to the operating system and the other in Java that provides the Daemon API.
Platforms
Both Win32 and UNIX like platforms are supported. For Win32 platforms use procrun. For UNIX like platforms use jsvc.
Java code
You have to write a Class (MyClass) that implements the following methods:
* void load(String[] arguments): Here open the configuration files, create the trace file, create the ServerSockets, the Threads
* void start(): Start the Thread, accept incoming connections
* void stop(): Inform the Thread to live the run(), close the ServerSockets
* void destroy(): Destroy any object created in init()
You can turn any Java program into a service/daemon using the Java Service Wrapper. It is used by multiple OSS projects, and ships as part of the Nexus Maven Repository Manager so that it can be installed as a service out of the box. To use it, you, the author, just need to create a configuration file and then run a simple batch file to create the service on Windows or copy an init script to the correct runlevel on Linux.
You can use the SystemTray classes and install your app as any other in the default platform.
For windows it could be an scheduled task that run at startup.
For Linux and OSX I don't know (besides crontab wich is somehow too technical) but I'm pretty sure they both have a way to do the same thing easily.
Unfortunately (as of today) Apple hasn't finished the 1.6 port.
It won't be a real demon, but an app like Google Desktop.
I've heard Quartz is a good option. But I've never used it.
If you dont need free solution, you can use Advanced Installer (www.advancedinstaller.com), it can make win-service as well as MacOS installer from your JAR, and more..
Check out JDIC, the Java Desktop Integration Components project. It supports desktop integration like system tray (or equivalent) with a cross-platform API.
Others have mentioned Quartz, which is an enterprise job scheduler. It can be lightweight, depending on the jobs that are scheduled, but it doesn't have any features that are inherently desktop-oriented. On the contrary, many of its features depend on enterprise support like a relational database. If your application is primarily scheduling tasks, a headless Quartz service executing jobs, with a desktop client to interact with the service is reasonable approach.
The Apache Directory Daemon project sounds like the best cross platform way to do this (with Java wrappers for JSVC under POSIX and procrun under windows).
People sometimes have difficulties finding prunsrv.exe and/or prunmgr.exe (components of procrun), its not well documented on the apache site, generally it can be found in the archives (note. they say that procrun is tomcat5.exe)
for windows you can find it here:
http://archive.apache.org/dist/commons/daemon/binaries/windows/commons-daemon-1.0.7-bin-windows.zip (contains both 32 and 64 bit versions)
you dont need to implement daemon interface nor download it at all, prunsrv can be used to turn any app to windows service
browse that archive for other platforms

Categories

Resources