I want to know how to make a java program that can be used to open stuff up. Ex: notepad++, win zip.... Do I have convert the jar to .exe first? Also, does the file chosen get passed in to String[] args?
By the way, I know that it works with cmd but thats not what I'm asking.
Depends on the OS. Under windows, you need to attach some details into the registry.
Have a look at the 3rd answer in Utilising a file association in a Java application for an example?
You could also have a look at http://www.rgagnon.com/javadetails/java-0592.html
UPDATE
Also, when the OS executes the program, you should receive the file as a command line parameter through the main method
I don't know if this will work suit your needs or not, but you could also take a look at File association in Mac
There's many choices on how to make a Java program runnable. Like you mention, the simplest choice is to use the command line. If you want to make it work with most OS's GUI interfaces (and the Open With dialog) the easiest choice is to make an executable jar. IDEs can make this very easy for you, in Eclipse just right-click on the project and select Export > Java > Runnable JAR file.
Another excellent option is to turn your application into a Java Web Start application, which lets users easily run Java programs being served up online.
Alternatively, like you mention, you could convert it into an .exe file:
Compiling a java program into an executable
How do I create an .exe for a Java program?
How can I convert my Java program to an .exe file?
Deploy the app. using Java Web Start.
JWS 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..
Here is a demo. of the file services in which the app. is associated with the file type .zzz.
..does it get passed via the windows file chooser?
No. It gets passed to the main as either -open filename or -print filename. What the app. does with those strings is up to it. The demo. linked above will prompt the user in the sand-boxed version, simply because it is sand-boxed. The other one should work without showing prompt or dialog.
Related
I have an application that has an applet that does two simple things:
Download an executable jar file from our server (if the user doesn't already have it) to an specific folder in the user's PC
Execute the jar file with the corresponding parameters
This jar file monitors an Office file for changes and send it back to our server.
The problem is the war Chrome is creating with Java with this NPAPI thing. So I have until September to think of an alternate technology or stop the Chrome support.
Do you think of some other way to achieve the same result? Just download and execute. Doesn't seem that hard =(. Can HTML 5 do that?
EDIT
I was looking into Java Web Start and became a little happy. It appears that it can do what I want: executing a up to date jar file passing parameters. But I never worked with JWS, so I have some doubts:
Is it possible to pass parameters to it? I read about some JSP files that you can configure to do that, but I'm still unsure.
Theoretically, it should start automatically from a browser link, am I right? I tried this site:
https://docs.oracle.com/javase/tutorial/deployment/webstart/running.html
and it didn't work that way. I had to mark "always open files of that type" on Google Chrome. Is there a way for automatize it?
Thanks again!!
From what I know there are at least two things that allow you to stick with Java.
Webstart
Install4
Webstart is provided by Oracle and allows you to download Java program from the web and execute them. Update mechanisms exist, so you can always provide a current version.
Install4J (or any other installer for Java applications that offers an update mechanism) provides an installer which enables your customer to install an application which afterwards will be kept up to date by the integrated update mechanism. But Install4J comes at a price, there might be freeware / open source alternatives. Install4J and its alternatives are often discussed here on SO, you might want to check here.
I think the FileAPI of HTML5 is limited and can not access arbitrary files because a sandbox prevents this. You might check SO again for details about that.
I'm afraid that many users still don't know what Java Web Start, so they may get confused by the small, single .jnlp file. So is it possible to wrap it as a very normal application, i.e. Windows .exe(or OSX .app) with pretty icon?
"The shortcut element can be used to indicate an application's preferences for desktop integration." The desktop element in particular allows platform-specific integration in a way that users expect.
I wrote a script to fix-up the file association for executable .jar files. You could just modify my script and that would give your users a way to register the .jnlp extension if it wasn't yet registered on their system.
NOTE: In the case where you have a user who hasn't installed Java on their system, they wouldn't have this file association, and you could use this script to associate a "bundled jre" with .jnlp extensions without the user needing to install Java.
Basically JAVA runs on a virtual machine, but cross-compilers can be used to re-compile your java code , creating an .exe or .app file
if javafx is an option, linked article describes nice ways how to deploy the same application both as .exe and .jnlp
http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm#A1324980
I want to distribute a swing app to my client. In that application two property file are there, which should be visible to client so that they can edit, I can not give it as runnable jar. Also I want something like apache-tomcat zip file which once you extract it will arrange folder structure also will give property file to edit and on next run it reads that property. Also apache-tomcat starts with startup.bat or startup.sh like that I also want.
Use Java Web Start to install and update the application.
User editable properties
Put them in (a properties file in) the Jar
When you go to check for the properties, do so using the PersistenceService. If they do not exist, read them from the text file in the Jar, and put them there. Here is a demo. of the service.
When the user wants to see/edit the properties, show them via a JOptionPane.
Desktop integration
JWS offers desktop shortcuts and menu items to launch apps., when supported by the platform, as well as an API to install and remove them (see the IntegrationService). Much slicker than batch files!
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.
A good tutorial : http://www.hascode.com/2012/05/creating-updatable-java-applications-using-getdown-and-the-getdown-maven-plugin/
Project website : http://code.google.com/p/getdown/
If I understand you correctly you want a tool to make distribution package for your application. That generates folder structure and unpacks application and data files to this structure.
There are many free and commercial setup builders. I think you would prefer multi-platform builder, so look for java setup builder.
Check this thread, this question was discussed there.
I have a program, written in Java, which originally used its directory in Program Files to write files accessible to all users of this program. This required our users to run as administrator all the time. In an effort to alleviate that, we decided to move files which needed to be written during regular usage to the ProgramData folder using the %ALLUSERSPROFILE% environment variable. Using a subfolder in this directory for our application works great if it is designated as writable during the installation process, which works fine using NSIS.
The problem comes with upgrading existing users. The Java File API provides setWritable but this does not appear to work after testing on development machines. It looks as though the new file API with Java 7 would solve this problem, but with no release date on the horizon I would rather not wait.
It seems the simplest solution would be to use JNA to call the appropriate Windows API call to set this directory writable. Since upgrading the software necessitates admin rights, similar to installing, it should let this change go through fine. However, I'm unsure where to start, having never used JNA before or the Windows API. Suggestions as to which Windows library to load and what functions to call would be appreciated, especially if someone has encountered a similar problem before.
Well, I'm glad you gave some background...You could use JNA, but the easier way would be to execute a call to the command-line utility cacls. It's included by default in Windows XP installations, I believe, so it should do the trick for you. Try Runtime.getRuntime().exec("C:\\Windows\\System32\\cacls.exe"+options)
Check out the documentation here -> http://technet.microsoft.com/en-us/library/bb490872.aspx
I use the follow line:
Runtime.getRuntime().exec( "C:\\Windows\\System32\\icacls.exe \"%ProgramData%\my application" /grant *S-1-5-32-545:(OI)(CI)(W,M)" );
S-1-5-32-545 is the SID for BUILTIN\Users because the name work only on English systems. https://support.microsoft.com/de-de/kb/163846
This give the BUILTIN\Users write access to all files in the given directory independent which user has create it.
I took the advice I've been given here to look at IzPack to create a JNLP based one click installation for computer illiterate clients who are using a Java desktop application I've created.
Java Web Start Driven Installation
However, I can't seem to find my way around it.
I don't know where to begin and seems the online tutorials are basic "look at the examples" which are themselves pre compiled and not sourced.
I want to create a simple form - be it in JSP or the JNLP install app (preferably JSP and the JNLP should get arguments from the JSP that launches it).
Then when the users click Install, the program installs to the default directory of userappdata with no questions (except for the UAC).
But IzPack seems to be forcing me to use panels and stuff... Not sure I want all of that.
Or maybe....
Hmmm, writing this just gave me an idea, but I'd still like some feedback.
Thanks.
Another approach perhaps?
If all what you need is to allow the user invoke a JAR, then consider using JSmooth to wrap it in an exe file. The exe file knows how to invoke java correctly and prompt the user to download if not present.
We also have used one-jar to wrap multiple jars in a single jar for exactly this purpose.