I have an installer application I am building in javafx but I can't figure out how to get the operating system it is running on so I can place files in the right locations for each system and so I can customize the interface for each. If anyone has any ideas or knows of a website that I can go to for help that would be great. I already tried oracle I could not find anything on ther but if you find a specific page please let me know. Thanks.

Dani AI

Generated

As correctly pointed out, JavaFX can call regular Java APIs, so determining the host OS from inside a JavaFX app is done by reading the JVM environment and applying a small normalization step. Treat the raw OS string as a heuristic: convert it to lower case, trim it, and check for short substrings (for example, look for "win" → Windows, "mac"/"darwin" → macOS, "nux"/"nix" → Linux/Unix, "sunos" → Solaris). Also consider the architecture and version strings when you need 32/64-bit or feature-specific behavior.

Decide early whether your installer will be per-user or system-wide. Per-user installs (under the user's home or application-data area) avoid elevation and are simpler to implement and test. System-wide installs target Program Files, /Applications, /opt or /usr/local and require elevated privileges (UAC on Windows, root on Unix-like systems). On Linux it is usually better to provide native packages (deb/rpm) rather than writing arbitrarily into /usr.

Use the platform-neutral file APIs rather than string concatenation so separators, permissions and atomic moves are handled correctly. Create parent directories before writing, check write permissions, and use safe copy-with-replace operations when downloading files. For downloads open a buffered stream from the HTTP resource, write to a temp file, verify integrity, then atomically move to the final location. Add logging and clear fallback behavior (e.g., fall back to a user-local install if a system-wide path is not writable).

A couple of cautions: sandboxed or web-deployed JavaFX apps may be prevented from reading system info or writing files unless signed or granted permissions; unsigned code will be limited. For real installer UX and privilege handling, consider producing native installers for each platform (Windows installer, macOS .dmg/.pkg, Linux packages) or a bundled native package that includes the runtime. This avoids many platform quirks and permission surprises that installers commonly encounter.

Recommended Answers

All 2 Replies

Nobody else has answered so, despite the fact that I've never actually done this myself, there's nothing to lose by having a go!
The doc says that JavaFX can use Java classes, so in theory you should just be able to call the Java System.getProperty(p); // where p is "os.name", "os.version" etc. Even if you can't. for some reason access System directly like that you should be able to create a tiny Java class of your own that just wraps those calls, and use that from JavaFX
If this is rubbish, please just ignore it.

ps Just looked a bit further and it looks like you just have to import java.lang.System; and you're good to go.

pps: public class javafx.lang.FX also seems to support public static java.lang.String getProperty(java.lang.String key)

That did it. I did not know that you could use regular java classes inside JavaFX since it is a scripting language. If you don't mind can you tell me how to )download files from the web, create folders on the system and place the downloaded files into the folder) in my other thread (How do I build an installer in JavaFX?). Any help you can offer would be great thanks.


Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.