Launching a Java program via double click [closed] - java

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have a Java program that I have been working on. I would like to show it to my girlfriend, who would have no clue as to how to work with Java, and make it easy for her to do so. I understand the first step is to compile it to .class 's from the command line, but after that I am clueless.
I would be interested in finding out how to do this both for Windows and Mac OS (I am on a Mac, along with my girlfriend, but my school uses Windows computers).
I have been on Oracle and seen their demos, they download as .jnlp, is that a step in the right direction?
And specifically, I am looking for a "file" of some sort that is simply downloaded and launched, no terminal involved (maybe a file with a command line within?).

Launching a Java program via double click
..seen .. demos, they download as .jnlp, is that a step in the right direction?
The title and that quote typically represent two different ways to launch Java desktop apps.
"download as .jnlp" That is the 'deluxe' version, known as Java Web Start. It is a little trickier for the developer (you) but very easy for the user (your friend).
"Launching a Java program via double click" is more commonly associated with an executable Jar. (Although JWS also supports the 'double click' - but with menus and shortcuts.)
Either strategy will work on OS X, Windows or *nix, but the first has JRE versioning (making sure the end user has a JRE, and it is recent enough to run the code) assisted by scripts, and many other 'bells and whistles'.
Java Web Start
JWS apps. typically deployed from a web page or server accessible to the user machine, so your friend 'surfs on over' to the link you sent her to 'Download here'.
The moment she arrives at your web page, the deployJava.js will check her PC has a suitable minimum version of Java to run the app. If not, she will be guided through a process to get it.
When the JRE is confirmed (which happens invisibly for those with a later JRE) the script writes a link in the web page that by default is a button.
The user clicks the button and the JWS client (part of Java) will read the JNLP and begin to install the app.
If the app., requires permissions extended beyond the default sand-box, the user will be prompted as to whether to allow the code to run. See Appearance of Java Security dialog for more examples like:
If the user chooses Run ..
The app. will be loaded and appear on-screen (possibly along with desktop shortcuts and start menu being added).
To launch it the second and subsequent times, the user double clicks the desktop shortcut or activates the menu item. This is how Starzoom (which has an icon defined in the JNLP) appears in Windows 7.
Executable Jar
Another lesser alternative is an executable-jar.
It uses a manifest.mf in the Jar that specifies the main class.
While being a lesser experience for the end user, it is also simpler for the developer - a trade off that might come in handy for limited distribution.
Requires a suitable version JRE installed.
The user obtains the Jar from whatever source (USB, Bluetooth, web site etc.) and saves it anywhere on their machine that is convenient.
To launch it, the user double clicks the Jar.

You could create a bat script (Windows, I don't use OSX, but i think it's shell script for that) with the Java command you use to execute your Java program.
Or you could put you java class into a JAR file

Try NetBeans, make a project in there, and build your codes with it. It automatically produce jar file that can be execute via double click almost in any platform.

Related

Run an application made on java(FX) on a webpage

i am currently writing a game on javaFX and i have plans to post it in the website i run in the future (end exploit the Ads while at it). The problem is that after searching around a little it seems there is no way to run a java application on a browser.
Allowing people to run it through the browser would really help sharing the program.
My question is: is there today(2018) any way to run a java application through the web? Though i like java, no browser support seems like a really, really bad idea.
Oh, i also heard of Java Web Start. Although it looks like it is just avoiding the problem (not running in the browser) it seems like a good way to share an application. The problem is that it seems it is (Will be?) deprecated? I am helpless, it is like java isn't even trying anymore...
PS: If it makes any difference my game would be a 2D game with 3rd person view. It will also require some server stuff since players will create "arenas" that others can challenge. I would say my game wouldn't be "simple".
Java Web Start does the job very well—if you are willing to pay for a code signing certificate. (They’re a lot more expensive than regular SSL certificates.) The idea is that a user clicks on a hyperlink on your page, which causes the user’s Java installation to launch your application (possibly after installing it). This requires users to have Java installed beforehand.
If you don’t have the resources or desire to go with a code signing certificate, you can look at https://docs.oracle.com/javase/9/deploy/self-contained-application-packaging.htm. It allows you to create native installation packages for JavaFX applications. The disadvantage: You need each platform to create an installer for it. Meaning, you need Windows to create a Windows installer, OS X to create an OS X installation image, and Linux to create a Linux package. Some may also require signing using native tools.
Java 9 includes the jmod and jlink tools, which are capable of creating a file tree with an executable shell script or .bat file. A major advantage is that you can build such a tree for any platform, regardless of your own platform, if you unpackage the foreign platform’s JDK on your machine. Another advantage is that the user doesn’t need to have Java installed at all. A disadvantage is that the script requires a terminal, unless running on Linux.
Of course, you can just go the manual route and distribute a zip file which contains your .jar file(s), a shell script you’ve written, and a .bat file you’ve written. It’s not elegant, but it’s better than nothing. But it may trip up some non-technical users.
There exist a number of tools which create a native executable from .jar files, but I am not familiar with them (and I prefer to avoid third party tools unless they are truly necessary).
Whatever approach you choose, the answer is the same: You distribute something on your web page which the user downloads and runs. Aside from the download process, the browser is not involved.
What you can’t do is have users run your application inside the browser. That is deprecated, with good reason: It’s a disaster for the browser performance, for the Java runtime, for security, and for the user experience. And Firefox has all but banned plugins, so you’d be locking out a substantial percentage of users.

Executing installers programmatically

I am working on a project for my users to generate HTML pages, JS files, CSS files etc... through dragging and dropping visual elements and by going through a series of wizzards. The goal I am trying to achieve is to create an application in which users selects a runtime, for example tomcat or nodeJS and then be able to create content for that specific runtime in the manner described above. Part of this application would be the preparing of your runtime, and by that I mean installing tomcat or nodeJS for you. so the big question here would be, how do I run installers through program code ? (java 7/8 mainly)
what I have tried:
Using a strategy design pattern to determine the host platform and run a series of command in the terminal to execute an installer, problem here is that some installers start a wizzard and require further user input. and in some cases the host platform would require elevated permission. Is there perhaps a solution where one adds arguments to the terminal commands to skip an installation wizzard ?
Any help on this subject would be greatly appreciated.
Answer of Fildor was most usefull.

Write to C:\Program Files from Java program

I have written a Java application that includes a self updater. The self updater loads new program versions from a web server and replaces the application files. While this works perfectly if the application is installed e.g. in the users home directory, it fails on windows machines if it's installed in the C:\Program Files folder. This is because the JVM is executed under the user’s account which has no write access to the program directory.
If a native program, e.g. an installer, tries to write to the program folder, usually a popup appears asking the user to permit the write operation. This doesn’t happen for java applications. Why?
Is there any way to achieve that a write operation of a Java program to a restricted folder brings up the security popup so that the user can permit access to that folder?
Thanks for your responses. According to the answers I see the following options:
Java Web Start
For me this is not an option for end users. I think that no one can expect from an ordinary end user to know what Java Web Start is, what it’s good for and how it’s used e.g. I doubt that an ordinary Windows user knows how to uninstall a Java Web Start application.
Use an exe-launcher with manifest to launch the Java application
As far as I understand this solution the exe-launcher would request extended execution right at application start. This is not exactly what I want, cause for my use case it would be sufficient to get extended rights if an update is available and not on every application start.
Perform the update operation by calling a native executable
One could call a native executable to let it perform the update operation. In this way the application would only request extended rights if an update is available. This sounds not bad but includes some native coding for Windows and doesn’t work on other platforms.
Install a launcher in program folder and the application in user home
One can place a launcher in the program folder that calls the application that is installed in the user’s home directory. In this way it would be possible to update the application in the user’s home folder.
I use InnoSetup for installing my application on Windows and as far as I can see it a split installation is hard to achieve with this installer and probably with other too.
Install the complete application in the user’s home directory
Because the user has write access to his home directory there is no problem at all. For me this looks like the best option cause of its simplicity.
If you are using inno setup compiler to generate your launcher, then you can change your app directory permission.
For example, if you need full control and want to update files under AppName/data folder
[Dirs]
Name: "{app}";
Name: "{app}\data"; Permissions: everyone-full
[Files]
Source: data\*; DestDir: {app}\data\; Flags: ignoreversion recursesubdirs createallsubdirs; Permissions: everyone-full
Unfortunately the increased permissions need to be requested when you first start the program, you cannot promote to them later. Programs that look like they do that are actually restarting themselves with the higher privs behind the scenes.
I had a problem like this a few years ago with a Java app and in the end I installed the application to the user data folder instead of program files as otherwise the auto-updating was a nightmare. You can still add it to the start menu so to a user it looks exactly like any other program.

Java SE Error in cmd [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I downloaded Java SE Development Kit 7u7 and then I tried to make a simple program in Notepad to see if it works.I wrote the program , saved it in notepad.
(Note: As I was saving I noticed that in the Save as type the java extension wasn't there, so I just added .java at the end of the name of my program)
For this java I tried using cmd but as far as I have understood, it doesn't find it. As error it says the first world of my first file i try to use "is not recognized as an internal or external command, operable program or batch file". Could there be a problem with my PC , the java or does this have to do with the fact that I used Notepad instead of Notepad++ wich I have heard is better than the simpler one?
Maybe Notepad saved your file as YourProgram.java.txt.
You need to enable "View extensions" to see the real extensions. Here a step-by-step guide how to enable: http://windows.microsoft.com/en-US/windows-vista/Show-or-hide-file-name-extensions.
Open Folder Options by clicking the Start button, clicking Control Panel, clicking Appearance and Personalization, and then clicking Folder Options.
Click the View tab, and then, under Advanced settings, do one of the following:
To display file extensions, clear the Hide extensions for known file types check box, and then click OK.
Java source code files are not executable. You must compile it first using javac (this will produce a MyClass.class file) and then run using java MyClass. This is just the very basic information, there's actually a lot more to it, but I hope this will give you a starting point. You really should consult an online tutorial on the subject and definitely start working with a Java IDE such as Eclipse right away. Developing with Notepad is in fact much more involved, especially for a beginner, than with Eclipse.
Second, you have quite probably saved a file named MyClass.java.txt. Notepad adds the extension according to the chosen file type implicitly.
Check this video, it's about set up the java(JDK) path in windows 7!
and as advice for you, use Eclipse IDE or whatever you like to use!

associating a custom file extension with java app in windows

I would like to "link" few file extensions to my java application under windows. When user double clicks file with "linked" extension, I would like to open my app and I need to know path to file that launched app.
If you deploy the app. using Java Web Start, an interest in file-types can be declared in the launch file. See the demo. of the file services, which..
..prompts the user to associate file extension .zzz (simply a file type unlikely to clash with existing file associations) of content type text/sleepytime. ..
When the user double clicks a .zzz file, it should open in the app. Actually, the word 'prompts' there is not the whole story. If you launch the sand-boxed version you will be prompted as to associating the file-type. The trusted version does not prompt.
To add more user-control to the process, look to the IntegrationService that was introduced in 1.6.0_18 (I don't have a demo. of that one yet). You might run it at start-up, after checking with the user.
this would have to be done during installation. how are you planning on letting your user install your application?
you have to realize at this stage that you just made things a whole lot more complicated. registering file extensions means meddling with the registry. what happens if the user doesn't want your application anymore? or moves the file that launches your application?
you'll have to pick an installation creator. here's a so question about that: https://stackoverflow.com/questions/3767/what-is-the-best-choice-for-building-windows-installers
and then you'll have to learn that installer creator's language. here's how what you're asking for is done in nsis. remember that the script takes care of questions like "if the user uninstalls my application, and i didn't change the file associations at install time, should i then remove these file associations on uninstall?" so it's a bit long. here it is anyways: http://nsis.sourceforge.net/File_Association
maybe it can be done in an easier way in another installer creator.
however, in this example, you give the register function of nsis the start command for your application, and then it adds %1 to it in the start command of the windows file association. so you should give it the start command
javaw -cp installpath\yourcode.jar package.name.MainClassName
and then things should work out. this will take some experimenting of course, and you will have to be quite sure about how to start your application from the command line.
good luck!

Categories