Skip to main content

FlixelRuntimeUtil

View source

class

org.flixelgdx.util.FlixelRuntimeUtil

public final class FlixelRuntimeUtil

Utility class for handling operation related to the runtime environment, including OS detection, extracting runtime information, obtaining information from exceptions, and other related tasks.

Behavior that depends on the JVM, classpath, or JAR layout is supplied by a pluggable RuntimeProbe. Desktop JVM builds register FlixelJvmRuntimeProbe from flixelgdx-jvm at startup. TeaVM and other targets keep the built-in default probe, which reports RunEnvironment.UNKNOWN for FlixelRuntimeUtil.detectEnvironment() (no JarFile, no classpath heuristics).

Methods

setRuntimeProbe(RuntimeProbe)

public static void setRuntimeProbe(RuntimeProbe probe)

Installs the probe used for FlixelRuntimeUtil.isRunningFromJar(), FlixelRuntimeUtil.isRunningInIDE(), FlixelRuntimeUtil.getWorkingDirectory(), and FlixelRuntimeUtil.getDefaultLogsFolderPath(). Pass null to restore the default TeaVM-safe implementation.

Parameters:

NameDescription
probeThe implementation, or null for the default.

getRuntimeProbe()

public static RuntimeProbe getRuntimeProbe()

Returns the active runtime probe, or the default implementation when none was installed.

Returns: The effective probe, never null.


isRunningFromJar()

public static boolean isRunningFromJar()

Returns true when the application is running from a packaged distribution JAR.

When using the JVM probe from flixelgdx-jvm, Gradle builds each module (e.g. flixelgdx-core) into its own module JAR inside build/libs/ and puts that on the classpath during IDE runs. Checking only whether the code-source path ends with .jar therefore incorrectly returns true in the IDE. Instead, the probe opens the JAR that contains this class and inspects its manifest for a Main-Class attribute. The only JAR in this project that carries that attribute is the fat distribution JAR produced by the lwjgl3:jar task. Individual module JARs do not have it.

Returns: true if running from the distribution JAR, false otherwise.


isRunningInIDE()

public static boolean isRunningInIDE()

Returns true when the application is running inside an IDE (IntelliJ, Eclipse, Cursor, VS Code, etc.), and false when running from the distribution JAR or plain classpath.

Returns: true if running in an IDE, false otherwise.


detectEnvironment()

public static RunEnvironment detectEnvironment()

Detects the current runtime environment.

Uses RuntimeProbe.detectEnvironment(). The default probe (TeaVM and other non-JVM targets without a registered JVM probe) returns RunEnvironment.UNKNOWN.

Returns: The detected environment.


getWorkingDirectory()

public static String getWorkingDirectory()

Returns the working directory of the game (code source location: class output dir or JAR path).

Returns: The working directory of the game. If an error occurs, null is returned.


getDefaultLogsFolderPath()

public static String getDefaultLogsFolderPath()

Returns the default directory path where log files should be stored, depending on the runtime.

  • When running in an IDE: the project root directory (inferred from classpath when needed), so logs go to <project-root>/logs/.
  • When running from a JAR: the directory containing the JAR, so logs go to <jar-dir>/logs/.
  • Otherwise (e.g. classpath): the current working directory, so logs go to <user.dir>/logs/.

Returns: The absolute path to the logs folder (with no trailing separator), or null if it cannot be determined.


getLibraryRoot()

public static String getLibraryRoot()

Returns the root package name of the library. This is done just in case (for whatever reason it may be) the root package changes.

The package is derived from the fully qualified class name rather than Class.getPackageName(), which is not available on TeaVM.

Returns: The root package name of the library.


getExceptionLocation(Throwable)

public static String getExceptionLocation(Throwable exception)

Obtains a string representation of where an exception was thrown from, including the class, method, file, and line number.

Parameters:

NameDescription
exceptionThe exception to obtain the location from.

Returns: A string representation of where the exception was thrown from.


getFullExceptionMessage(Throwable)

public static String getFullExceptionMessage(Throwable exception)

Obtains a full detailed message from an exception, including its type, location, and stack trace.

Parameters:

NameDescription
exceptionThe exception to obtain the message from.

Returns: A full detailed message from the exception.


RuntimeProbe

interface

org.flixelgdx.util.FlixelRuntimeUtil.RuntimeProbe

public static interface RuntimeProbe

Supplies environment detection for the current platform. Desktop JVM games should install an implementation from flixelgdx-jvm (see FlixelJvmRuntimeProbe) at startup.

Methods

isRunningFromJar()

public boolean isRunningFromJar()

isRunningInIDE()

public boolean isRunningInIDE()

getWorkingDirectory()

public String getWorkingDirectory()

getDefaultLogsFolderPath()

public String getDefaultLogsFolderPath()

detectEnvironment()

public default RunEnvironment detectEnvironment()

Returns IDE, JAR, or classpath when the probe can classify the JVM layout; otherwise RunEnvironment.UNKNOWN (default implementation for non-desktop probes).

Returns: The detected environment for this probe.


RunEnvironment

enum

org.flixelgdx.util.FlixelRuntimeUtil.RunEnvironment

public static final enum RunEnvironment

High-level runtime classification for logging and tooling. FlixelRuntimeUtil.UNKNOWN is used when the platform does not support JVM-style detection (default RuntimeProbe).

Fields

IDE

public static final RunEnvironment IDE

JAR

public static final RunEnvironment JAR

CLASSPATH

public static final RunEnvironment CLASSPATH

UNKNOWN

public static final RunEnvironment UNKNOWN

Methods

values()

public static RunEnvironment[] values()

valueOf(String)

public static RunEnvironment valueOf(String name)