Compiling from Source: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
Mcroft (talk | contribs)
Mcroft (talk | contribs)
Line 2: Line 2:


==Windows==
==Windows==
# Download and install Java Development Kit 1.8 or newer, available from [https://www.oracle.com/java/technologies/javase-downloads.html Oracle] or [https://adoptopenjdk.net AdoptOpenJDK]
# Download Tools
# Download and install Subversion, from [https://subversion.apache.org/packages.html apache.org]
## Download and install Java Development Kit 1.8 or newer, available from [https://www.oracle.com/java/technologies/javase-downloads.html Oracle] or [https://adoptopenjdk.net AdoptOpenJDK]
# Download and install Tortoise SVN (or of course, another SVN program)from [https://tortoisesvn.net/downloads.html tortoisesvn]
## Download and install Subversion, from [https://subversion.apache.org/packages.html apache.org]
# Download and install WinAnt, available here: http://code.google.com/p/winant/
## Download and install Tortoise SVN (or of course, another SVN program)from [https://tortoisesvn.net/downloads.html tortoisesvn]
# Connect to the SVN server and download the source code for the Mafia Project. Using Tortoise SVN, you have to right-click on your desktop, select "SVN Checkout", and put the URL of the repository as "svn://svn.code.sf.net/p/kolmafia/code/". Leave all other settings as they are, and click OK.
## Download and install ANT, from [https://ant.apache.org/bindownload.cgi apache.org]
# Copy C:/Program Files/WinAnt/bin/ant.bat to your Desktop/kolmafia/ folder. If you have set up WinAnt correctly (and it's hard not to - there aren't many options) then double clicking on this file should compile the program.
# Configure Windows Enivronment
## Windows 10
### Go to settings
### type 'enviro' in the search
### click on the 'edit environment variables' suggestion
### add or edit ANT_HOME, JAVA_HOME, and PATH variables<br>''PATH should include ANT_HOME/bin and JAVA_HOME''</br>If ANT or JAVA installers have already set these variables, they can be updated or left alone.
# Get Source and Build
## Connect to the SVN server and download the source code for the Mafia Project. Using Tortoise SVN, you have to right-click on your desktop, select "SVN Checkout", and put the URL of the repository as "svn://svn.code.sf.net/p/kolmafia/code/". Leave all other settings as they are, and click OK.
## Copy %ANT_HOME%/bin/ant.bat to your Desktop/kolmafia/ folder. If you have set up ANT correctly (and it's hard not to - there aren't many options) then double clicking on this file should compile the program.
# Compiling creates a "build" and "dist" folder. The end program is in dist/Kolmafia.jar.
# Compiling creates a "build" and "dist" folder. The end program is in dist/Kolmafia.jar.
===Troubleshooting===
===Troubleshooting===

Revision as of 04:21, 4 December 2020

To contribute to the Mafia project, you'll need to be able to install the Java Development Kit, connect to the SVN and be comfortable writing Java Code. Instructions for the first two are included below:

Windows

  1. Download Tools
    1. Download and install Java Development Kit 1.8 or newer, available from Oracle or AdoptOpenJDK
    2. Download and install Subversion, from apache.org
    3. Download and install Tortoise SVN (or of course, another SVN program)from tortoisesvn
    4. Download and install ANT, from apache.org
  2. Configure Windows Enivronment
    1. Windows 10
      1. Go to settings
      2. type 'enviro' in the search
      3. click on the 'edit environment variables' suggestion
      4. add or edit ANT_HOME, JAVA_HOME, and PATH variables
        PATH should include ANT_HOME/bin and JAVA_HOME
        If ANT or JAVA installers have already set these variables, they can be updated or left alone.
  3. Get Source and Build
    1. Connect to the SVN server and download the source code for the Mafia Project. Using Tortoise SVN, you have to right-click on your desktop, select "SVN Checkout", and put the URL of the repository as "svn://svn.code.sf.net/p/kolmafia/code/". Leave all other settings as they are, and click OK.
    2. Copy %ANT_HOME%/bin/ant.bat to your Desktop/kolmafia/ folder. If you have set up ANT correctly (and it's hard not to - there aren't many options) then double clicking on this file should compile the program.
  4. Compiling creates a "build" and "dist" folder. The end program is in dist/Kolmafia.jar.

Troubleshooting

Double-Clicking ant.bat

Due to how bat files work when you double-click them, ant.bat will auto-close before you can read its output.

  1. ant assumes that builds are done from a command shell. You'll need to run from the command shell to execute any ant target other than the default, such as ant.bat update exec or ant.bat daily
    ant -projecthelp
    will list all main targets
  2. An easy workaround is to add a "pause" near the bottom of the file before it has a chance to auto-close on you.
    When you run it again, you'll be able to read its output and it will exit after you Press any key to continue...
  3. Alternatively, you can create a wrapper batch file that calls the existing ant.bat file and adds a pause after executing it. This method allows you to set different ant targets and also prevents updates to ant from overwriting your modifications.

Example of a very simple MyWrapper.bat file

# This is a wrapper batch file
# First it runs ant
call ant.bat daily
# Then it pauses
pause

tools.jar not found

If you get an error message about "tools.jar" not being found, this means you're trying to build with the JRE (which doesn't contain this file) rather than the JDK (which contains it).
To fix this, right click on my computer -> properties -> advanced system settings -> Environment Variables... then make sure your PATH contains a reference to the location of your JDK directory.

Linux

  1. Install Sun Java Development Kit ( debian: apt-get install sun-java6-jdk )
  2. Install Subversion ( debian: apt-get install svn )
  3. Install Ant ( debian: apt-get install ant )
  4. Connect to the SVN server and download the source code for the Mafia Project. ( svn checkout svn://svn.code.sf.net/p/kolmafia/code/ kolmafia )
  5. Verify tou are using sun-java with ( debian: update-alternatives --all )
  6. I had to change $JAVA_HOME to compile ( export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.12 )
  7. Compile kolmafia with Ant ( debian: cd kolmafia && ant debian )
  8. Install kolmafia ( debian: cd dist && dpkg -i kolmafia*.deb )

MacOSX

  1. Install required packages
    MacOS X packages for Java, subversion, and ANT may also be installed via a package manager like Homebrew or MacPorts. The instructions are written for a direct installation of the packages.
    1. Install Java Development Kit version 1.8 or newer from Oracle or OpenJDK
    2. Install Subversion 1.10 or newer from apache.org
    3. Install Ant 1.9 or newer from apache.org
  2. Configure development environment
    Most of these steps can be included in .profile or the equivalent for your terminal of choice.
    1. In the terminal set JAVA_HOME to the java home directory.
      /usr/libexec/java_home -V will list all known values for java_home.
      If you have multiple copies of java, choose the version you want to use.
    2. In the terminal set ANT_HOME to the location of ANT. e.g. /opt/ant
    3. In the terminal make sure that Ant and subversion are in your ${PATH} variable. e.g.PATH=${PATH}:/usr/local/opt/subversion/bin:/usr/local/ant/bin
  3. Open a new terminal window and navigate to the directory to which you wish to create kolmafia (e.g. cd ~/Projects, or some similar directory)
  4. Connect to the SVN server and download the source code for the KoLmafia Project.
    svn checkout svn://svn.code.sf.net/p/kolmafia/code/ kolmafia
  5. Compile KoLmafia with Ant (cd kolmafia && ant daily)
  6. execute KoLmafia with the command java -jar dist/KoLmafia-*.jar