Running Mafia on Windows

fronobulax

Developer
Staff member
There are several "wrong" ways to install and launch mafia. This post is my attempt to capture a right way. Ideally my comments will be verified and someone more interested in technical writing than I currently am, will make a simple set of instructions and post a sticky or edit the wiki or both.

My comments are based on Windows 10 although there is a lot of anecdotal evidence that nothing is dependent upon a specific Windows version.

There are three basic steps: Installing or Verifying Java; "Installing mafia"; and Running mafia.

Currently Java 17 is recommended for mafia. Running an older version will be a problem. Running a newer version may be a problem. If running mafia is a problem and the version is not 17 then at some point installing and using v17 will be suggested. Instructions for installing java are elsewhere and enough out of scope that a separate set of instructions is called for.

Mafia works best on Windows if the jar file is in a directory that the Windows user running mafia can write files in. A subdirectory in the users Documents file is recommended although knowledgeable users can use something else. C:\Users\frono\Documents\KoLmafia is an example. How to find and download a mafia jar file is also better handled as its own topic but whatever is done the jar file needs to be copied or moved into the directory where mafia can create or access settings. In this context "updating" mafia means getting the latest jar file, copying it to the mafia directory and deleting any older jar files that are there.

If the file associations for Java are correct then the preferred way to run is to navigate to the directory containing the jar file and then double click on it. Alternatively a command prompt can be opened with the current directory set to the directory containing the jar file and the command "java -jar <complete name of mafia jar file>" issued. Many people choose to make a batch file or shortcut to launch mafia. I have a shortcut to the directory containing mafia on my desktop and I open it then find the jar file and double click.

In the spirit of self help the following things should be considered.

If the Java installation is suspect then opening a command prompt and typing "java --version" is a good diagnostic. Any results other than something that indicates Java 17 or better is installed means that Java needs to be installed (or the installation needs to be fixed) or up/down graded.

If Java seems right but the login screen never appears then running mafia from the command prompt (java -jar <complete name of mafia jar file>) should capture error and status messages that may assist in diagnosing the problem.

I mafia seems to have a problem finding or creating files then it is possible that the launch technique is causing mafia to use the "wrong" directory or the user cannot write files in the mafia directory. If there is a reference to C:\Windows\System32 or similar there is definitely a problem with where the jar file is located or how mafia is launched.

Using Quick Access or Recent file lists to launch mafia is known not to work.

Making the mafia directory on the Desktop sometimes fails to work.

Running multiple instances of mafia with the same character is not supposed to work and a problem with the lock file should go away when all instances are shutdown. Sometimes mafia fails to shut down cleanly in which case all instances should be stopped and shut down and then the lock file manually deleted by the user.

If double clicking on the jar doesn't work or opens up something other than Java the file association can be reset by right clicking on the jar, selecting open with and navigating to the correct version of Java.exe.
 

MCroft

Developer
Staff member
I am not a Windows user, so I have very little to say, except that I do have a little bit...
  1. Thank you for collating all the information we have that may help someone.
  2. Java 17 or better is required. Java 17 is recommended, as it is a Long Term Support version that is "17 or better". Recently 21 became a released LTS version. As other apps start to use it, it will start showing up on end user machines. I have tested it, but only lightly, so I'm comfortable with the 17 recommendation. It should work fine for end-users, but eventually developers will want features that are only present in versions beyond 17 and we will move. Hopefully it will be less painful than moving to 11 from 8 was.
  3. This should probably have a discussion or a link to wherever the platform/version specific instructions for checking the version of Java that is launched by double-clicking a jar, which in not necessarily the same version that is launched from a Command Window. That seems to cause a lot of questions.
 

fronobulax

Developer
Staff member
The *nix "which" command is quite helpful.

For new enough versions of Windows the "where" command dies the same thing.

Code:
C:\Users\frono>where java
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk-17.0.4.1\bin\java.exe

AFAIK both resolve to the same thing so it doesn't matter how I launch, I should get the same thing. But in a world where you can have 32 or 64 bit Java, JRE or SDK Java and various combinations and versions I'm not sure how to reliably tell what is what.

I will say that the Copyright Notices page of KoLmafia lists the Java version mafia so if mafia actually runs it will solve the problem, but if mafia won't run that information would be available to tell you why :)
 

xKiv

Active member
so it doesn't matter how I launch, I should get the same thing.

File asssociations (what runs when you doubleclick a file) are a completely separate thing. There might be other launch ways with their own configuration of what gets run.
 

fronobulax

Developer
Staff member
I tried a couple of experiments where the ROOT directory was Windows\System32 and that was not writable by the user running KoLmafia. There were several exceptions thrown.

data\content-types.properties could not be found because it wasn't written. Static initialization code looks for it and creates it if needed. Rhino supports JavaScript in KoLmafia. There is a Rhino bug with a workaround that requires the file to be present before Rhino is initialized so static initialization is probably necessary although deferring it to a time when the data directory has been created might be possible.

settings\GLOBAL_prefs.txt could not be found. This was because the settings directory could not be written. The first instance was due to the static initialization of the ScriptMRUList which updates a preference.

After the static initializations settings\GLOBAL_prefs.txt is again looked for. Several files KoLmafia tries to place in relay/ and images/ also generate exceptions.

None of the file not found exceptions are caught or displayed anywhere but in the console, if mafia is being run from the console. An aggressive approach would be to make either of the static initialization failures fatal. A less aggressive approach would be to make the static initializations part of the start up and then check for the directories (or the ability to create them) before KoLmafia really gets going. The most user friendly approach, at least for GUI users would be to internally log any of these start up exceptions and present them for acknowledgement before making the Login screen available.
 
Top