Hello,
I would make a full setup for my java application but I have no idea how can i make it, and I would make a class installer like in .net because I want some tasks running during the installation.
Thanks for your help.

Dani AI

Generated

Short answer: you can do this two ways — let the installer collect user choices and run Java code at install-time (a true “one‑time installer” like in .NET), or implement a small “first‑run” initializer inside your app that runs once the first time the app starts. , and were all pointing at the same tradeoff: installer vs in‑app. Below are practical, low‑friction options and a tiny, copy‑ready pattern for the in‑app approach.

Example in‑app pattern (prompt once, persist choices, run setup once). The snippet chooses a sensible config directory per OS, creates it, writes a Properties file and runs one‑time setup if the config is missing:

import java.nio.file.*;
import java.util.Properties;
import java.io.*;

class FirstRun {
  static Path configFile(String app) {
    String os = System.getProperty("os.name").toLowerCase();
    if (os.contains("win")) return Paths.get(System.getenv("APPDATA"), app, "config.properties");
    if (os.contains("mac")) return Paths.get(System.getProperty("user.home"), "Library", "Application Support", app, "config.properties");
    String xdg = System.getenv("XDG_CONFIG_HOME");
    return (xdg!=null?Paths.get(xdg):Paths.get(System.getProperty("user.home"), ".config")).resolve(app).resolve("config.properties");
  }

  static void ensureFirstRun(String app) throws IOException {
    Path cfg = configFile(app);
    if (Files.notExists(cfg)) {
      Files.createDirectories(cfg.getParent());
      Properties p = new Properties();
      // ask user for paths (GUI or console) and put into p
      try (OutputStream out = Files.newOutputStream(cfg)) { p.store(out, ""); }
      // run the one-time tasks here
    }
  }
}

Use platform conventions for config locations (XDG on Linux, %APPDATA% on Windows, ~/Library/Application Support on macOS) and consider java.util.prefs if you prefer a platform‑backed API. (specifications.freedesktop.org)

If you want a true native installer that runs Java code during install (collect paths, create shortcuts, set permissions), use a packaging tool rather than hand‑rolling everything. Modern options: jpackage (built into recent JDKs) plus jlink for a bundled runtime, commercial/free installers like install4j or IzPack, or wrap+installer flows (Launch4j + Inno/NSIS). These tools let you present UI, capture user input and run custom Java actions at install time. Test both interactive and silent installs and remember platform signing/permission requirements. (openjdk.org)

Quick cautions: make install tasks idempotent (safe to re-run), don’t hardcode paths, test upgrades/uninstall paths, and prefer the in‑app initializer for small utilities or jpackage/installer flows for production desktop apps. (openjdk.org)

Recommended Answers

All 9 Replies

I'd clarify that a little. Are you intending to setup your app, or are you intending to setup their Linux, Apple, Windows and other computers with the JAVA runtime as needed plus your app?

Let me share I've found JAVARA to help me dust off old JAVA, install the new and a bit more. But at no time have I stepped over that line where I am installing runtimes for the end user. Maybe today's users need that?

Yes I'm intending to setup my app.

Typically, you'd just have a method in the main class that does that stuff, or in a class where you launch it from the main class. A single entry in a properties file can then be used to determine whether that initialisation method runs or not.

I found how can i make a setup but my primary question is how can make a Class Installer like in .net that run only 1 time during the installation.


Aha, I think I get your question now. You want your app not to be a setup app but "the entire app" so you have a method you want to run once.

I have apps that on startup do checking to see if it's all good to go like a pre-flight check. Your method would not just blindly set things up but test for what you need configured. In psuedo code.
if this isn't there, create this.
if that isn't set, set that.


But I want to get from the user some information (like, where you want save your data, and where you want to save your application).
So it is any idea to do that, or I want to do this tasks by coding (hard coded), like what you said (if this isn't there, create this.
if that isn't set, set that.)

If you get that information from the user then you have to store that in a configuration file (or equivalent) somewhere so you can find it next time the program is run.
So your startup code can look something like:

p s v main(etc) {
   get config file
   if file exists start running normally
   else run the one-time installation code

Okay, Thank you all for your interest.

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.