I'm really tired of computers not having the necessary Java version I need, or I don't have admin privileges to install it. I've seen tons of windows tutorials, but I'm on a Mac. So can someone tell me how to put Java 7/8 on a flash drive, and how to create a script to run a jar file with the version on my drive I have selected? Thanks! I'm on Mac OS X 10.10
Based on your comment to another answer
I have a computer I can do it on with admin privileges
It sounds like you just want to have the JVM/JDK on some portable media that you can run from after you plug it into another computer. This should be simple assuming you only plan on using it on comparable systems. For example, you won't reliably (or at all) be able to install Mac x64 java binaries on a flash drive and try to run it on a Windows machine.
So assuming you only intend to run it on comparable machines, it's as simple as copying the directory structure from the root of the Java install directory. On my Mac OsX 10.9.5 it's /Library/Java/Home. Once you have it on the drive, you just plug it into another Mac. It should automount and you open up a terminal to the root of that mount. cd into the $JAVACOPY/bin (where $JAVACOPY is the directory structure you copied) and you can run ./java -version to verify you are running it.
If all is well after doing that, you can launch any JAR file from that flash drive mount directory with
cd /Volumes/flashMount/Java/Home/;
./bin/java -jar /Users/myuserid/myJar.jar
Keep in mind that Java doesn't strictly require any of the formal install process that systems like Mac and Windows surround it with. All of the fluff involved with "installing" java is about setting up the system to use whichever Java version is installed without the user having to know or care. But you can have as many versions of java as you want in the file system without "installing" them and they should all function just fine (ignoring classpath collisions for certain libraries.)
Related
I imagine some Java gurus with experience delivering Java apps on Windows desktops will be able to ace this one. I've always been a Mac/Linux Java developer so this is uncharted territory for me :-/.
I have to write a Java 8 Swing application and install it on a Windows 10 (64-bit) machine. My gameplan is to package the app as an executable JAR and wrap it with Launch4J, so that it looks like a native Windows EXE (.exe file). However its a little bit more complication than that when it comes to the distribution:
There will be the JAR/EXE as mentioned above, lets call it myapp.exe (built from myapp.jar)
The app will output logs to a (local?) directory, myapp.log
The app will load a config file at runtime, myapp.properties
The distribution should also contain the User's Guide, MyApp User Guide.html
Let's assume a Java 8 JRE/JDK is already installed on the machine, so we don't need to worry about installing Java itself.
The installation process must be simple and include:
Removing the old version (and all of its other artifacts such as the log file, config/properties file, user guide, etc) off the machine completely
Installing the new version at either the Windows 10 default location, or allowing the user to specify a different location
Additionally, if at all possible, I'd like the installation process to include:
A requirements check for things like minimum memory and disk space, OS version info/compatibility (i.e. make sure its being installed on Windows 10, etc.)
Provide an easy-to-use wizard such as an MSI that the user can click though
Optionally install shortcuts to the user's Desktop
Given all this, I'm wondering what my options are in the modern Windows 10/Java/Launch4J landscape. Are there tools that will help me script together MSIs quickly, or do I have to write my own in, say, C#/.NET and have that be a separate binary/project? If MSIs aren't an option, what options exist that might hit all my bullets above?
I realize I could just distribute the whole thing as a ZIP, and have the installation process look something like:
Save the ZIP to some place on the user's machine, say, the Desktop
Move the previous app and its artifacts to the trash, manually
Unzip the new ZIP
However that feels janky and I'm looking for something more professional. Any solutions here?
JDK 8 is bundled with a tool called javapackager (formerly javafxpackager) which is part of JavaFX. However, you can use it package java swing application without using JavaFX. This tool can generate an installer file (exe or msi) which contains the application and the Java runtime as well.
Here is an example:
javapackager -deploy -native exe -Bruntime="C:\Program Files\Java\jdk1.8.0_66\jre" -Bicon=app_icon.ico -BsystemWide=true -BshortcutHint=true -outdir packages -outfile appFile -srcdir dist -srcfiles MyApp.jar;COPYING.txt -appclass somePackage.MainClass -BlicenseFile=COPYING.txt -name appName -title "The application name"
For more information, see adding icon to bundle using javapackager
There is also a new tool called jpackage which is based on javapackager. It is proposed to be released with the next JDK release, JDK 14. Note that javapackager was removed from JDK since version 11 as part of the removal of JavaFX.
See A Brief Example Using the Early Access jpackage Utility
Tools: Some deployment tools information:
Multi-Platform Installers
List of the major MSI installer tools
WiX quick start tips (the open source, free tool with a heavy learning curve)
"Hello WiX - step-by-step in Visual Studio"
"Hello World" - WiX style
Advanced Installer: As stated in a comment above you can use Advanced Installer to install Java applications on Windows and Mac (no Linux support).
Videos: Here are some videos from Advanced Installer (commercial tool) on Java installations:
Hello Java Installer: 1 minute video that shows the basics of installing a Java application
List of Java-related videos: https://www.youtube.com/user/AdvancedInstaller/search?query=java+jre
Tutorial (to read): Package your Java application for Windows and for Mac OS. Java landing page.
Digression: Not Java as such - do have a skim. Auto-updating applications using various deployment technologies: What is the best practice to auto upgrade MSI based application?
Links:
Make Installer of java Application
Installer for Java Web Application
How to create windows installer
How to create a MSI Windows installer for a Java program?
Old: How can I convert my Java program to an .exe file?
I am trying to start this MOOC here: http://mooc.fi/courses/2013/programming-part-1/, and it instructs me to install Netbean. I have downloaded JDK as instructed on the website, and then tried to install Netbean, but the installer would not open. What happens is the computer appears as if it is loading (blue circle on Windows 8), but never actually opens the installer.
I have an intel i5-4210Y CPU at 1.50GHz, 8gb of RAM, and 64 bit OS. I have 743mb remaining on my C drive.
Any help would be greatly appreciated.
A easy way to "Install" Netbeans if you are having issues with the installer is to use the zip.
It can easily be found here:
https://netbeans.org/downloads/zip.html
Depending on what you want to do you will select the package you want. Im guessing since you're taking an online course in java, then you are not a professional programmer, so you wont need JavaEE. I think your best bet is to download "netbeans-8.1-201510222201-javaee.zip" and extract it to a place you can find it, maybe your desktop, or Program Files if you are an admin. Your executable will be in the BIN folder after you extract netbeans. You will see netbeans.exe, netbeans (this is a linux sh file, you don't need it), and netbeans64.exe.
Depending on what system you have, run the appropriate application.
netbeans.exe for x86 windows
netbeans for linux
netbeans64.exe for x64 windows.
I want to create an Windows installer for a Java application, though the native executables already exist and hence it simplifies to installing any kind of files. This question is similar to this one, but with following restrictions:
the Windows installer must be a native one, it must require an installed or bundled JRE
the installer creation must be platform independent, so it can be run on Windows, Linux or OS X (e.g. Java/ANT-based installer creation)
Currently, depending on our specific product, we are using WiX and InnoSetup, but both require the build process to be running on Windows. I want to avoid using Windows or Wine, but search a tool which already does it on all platforms.
Have you tried Wine compatability for Wix & InnoSetup? Also you can make scripts that start virtual machines to do stuff like this automatically. I have a Linux system that makes Windows XP/Windows 7 installation files using a combination of Wine and VirtualBox scripting.
I have a SWT based Java application that works on Windows, Mac OS and Linux. I develop it on my Windows machine and have a tester with Linux and a tester with a Mac. Currently my process creates a runnable .jar file for each platform on my Windows machine (which references the platform specific .jar and lib files from Eclipse.org). I have a working installer for Windows - also produced by the build on the windows machine. I want to create a standard Mac OS installer for my Mac users. The right way to do that appears to be to create a .app bundle and distribute it via a dmg file. This has not being going well. I have a working Java app that uses SWT and can be run from the command line, on all platforms. I have a way of building a .dmg on Windows. But so far all my attempts to get a .app bundle to work have failed.
I started by following this tutorial: http://www.eclipse.org/swt/macosx/
But when running my application I get an error saying that applications for the Power PC are not supported. That is using the same binaries that work from the command line using java -jar so the problem must be in the the way I am bundling. The sample Hello app from the page also fails to work but with a different error message.
I have been searching all day and found this promising talk: http://www.parleys.com/#st=5&id=2891&sl=72
In that talk the speaker says there will be a way to create a Mac OS .app bundle on any platform using a standard java launcher. But I cannot find any such thing released yet.
I found this post that also looks promising: http://www.intransitione.com/blog/take-java-to-app-store/
But this recipe says it will not work except by building on a Mac OS machine.
What I want to do is create a .app bundle for Mac OS X on my windows machine along with the Windows install and the Linux install. It would be preferable to also include a jre as part of the app bundle (which I already have working for Windows and Linux). I hope someone can point me in the right direction.
Have you seen this?
The .app is just a directory with a special structure a few special files. Once you have it created, you'll only need to update the JAR each time you build, which can be found here: MyApp.app/Contents/Resources/Java/MyJar.jar.
There will also be a few Java-specific properties in My.app/Contents/Info.plist, but you probably won't need to change these from how you initially set them up.
I have a Java program, let's say it's called MyApp.jar
To run it on Linux, I just write a shell script called myapp.sh, which simply runs java -jar MyApp.jar and double click on it. Everything works well.
On Windows 7, I cannot assume that the java command will be in everyone's path (if that's what you call it on Windows), so I have to have a workaround and do something like create a batch script with this in it: "C:\Program Files (x86)\Java\jre6\bin\java.exe" -jar MyApp.jar, which is obviously a Bad Solution... and it doesn't work on XP or Vista. It works on most Windows 7 machines though.
My application ships as a .zip file, the user extracts it to a folder MyApp, and then ideally will double click on something to invoke the program. So far it has a .sh script for Linux users to double click on, and a batch script for Windows 7 users (it works in most cases). It creates and consumes files in its own directory (MyApp).
What is the best way to invoke this program in a cross platform way?
Thanks!
As mentioned by biziclop, Java Web Start is commonly used to install/launch/update Java desktop apps.
As far as the JRE goes, it is usually sufficient to use the deployJava.js linked from that page above to ensure minimum necessary JRE is installed, and the elements in the JNLP file to specify any JRE micro-versions that are supported for the app.
Application launch
JWS can install desktop shortcuts and menu items when supported by the OS. Those can be specified in the launch file, or added/removed at run-time using services of the JNLP API.
If you can't deliver Java with your application, it might be a good solution to use JAVA_HOME to start it. It is set on, well... not all but many systems.
Definitly you should not use C:\Program Files (x86)... it is much better to use the environment variable %ProgramFiles%
Java application require a java runtime environment with a certain version to be installed on the target system.
The most convenient way, to my opinion, is to ship all libraries and documentation in a single archive and add start scripts for windows and *nix systems.
You could ship a JRE with your application too but then you'd have to support builds for different platforms...