r3dux.org

A number-pimping side project from the valleys in *NEW* upside-down flavour.

  • Home
  • ABOUT
  • OLD SITE
  • SEARCH
  • FEEDBACK

How to: Get Minecraft working in Linux

r3dux | September 27, 2012

Minecraft Wallpaper

Attempt a quickfix?

If you’re trying to run Minecraft in Linux and it’s failing with errors like:

wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)

or

Could not find the main class: net.minecraft.Launcher.Frame

Then the chances are you can fix it up by performing the following actions:

  • Set your LD_LIBRARY_PATH variable with:
    export LD_LIBRARY_PATH="the-correct-path-to-your-JRE-java-binary-which-is-NOT-usr/bin"
  • (if needs be) Get rid of OpenJDK and install the official Sun/Oracle Java binaries if required.

Know how do all that? Awesome – carry on! Not so sure? Read on! ;-D

Setting the correct JRE location

First up, check if you have Java installed by typing java -version, if it comes up with something like the below, then you’re got Java installed, now we just need to find out where:

java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

If you didn’t get anything similar to the above you might want to install the official Oracle Java implementation, which I put together a brief step-by-step for here.

Assuming you have some variety of the Java Virtual Machine (JVM) install, check if your LD_LIBRARY_PATH environment variable is set with:

printenv | grep LIBRARY

If it comes up empty, then we need to find out where Java’s installed and set it correctly. To get the correct path for where your particular Java install is located, you might be tempted to try running which java:

$ which java
/usr/bin/java

However, this is a little bit of a fib, as Java is part of the alternatives setup where we can have multiple versions installed at once – which means that /usr/bin/java is really a symbolic link to the true java location. To find where it’s really pointing we can either ask update-alternatives how it’s configured like so (and pick a version different version if we want to):

$ update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
 
  Selection    Path                               Priority   Status
------------------------------------------------------------
  0            /usr/bin/gij-4.6                    1046      auto mode
  1            /usr/bin/gij-4.6                    1046      manual mode
* 2            /usr/lib/jvm/jdk1.7.0_07/bin/java   1         manual mode
 
Press enter to keep the current choice[*], or type selection number: 2

Or we can look closely at the /usr/bin/java symlink:

$ ls -alh /usr/bin/java
lrwxrwxrwx 1 root root 22 Aug 15 05:03 /usr/bin/java -> /etc/alternatives/java

Which if we then look closely at /etc/alternatives/java then points at:

ls -alh /etc/alternatives/java
lrwxrwxrwx 1 root root 33 Aug 15 16:37 /etc/alternatives/java -> /usr/lib/jvm/jdk1.7.0_07/bin/java

Same thing as what the alternatives config’s pointing at ;-)

Now that we have the correct path, we can set it in the following manner (remember to substitute your particular Java location into the below lines!):

For 64-bit Linux:

export LD_LIBRARY_PATH="/usr/lib/jvm/jdk1.7.0_07/jre/lib/amd64"

For 32-bit Linux:

export LD_LIBRARY_PATH="/usr/lib/jvm/jdk1.7.0_07/jre/lib/i386"

With that done, you should be able to see that it’s set by running:

printenv | grep LIBRARY

Which should give you something like:

$ printenv | grep LIBRARY
LD_LIBRARY_PATH=/usr/lib/jvm/jdk1.7.0_07/jre/lib/amd64

Finally, we should be fit to launch Minecraft like this (assuming the minecraft.jar file is in your home folder):

java -Xmx1024M -Xms512M -cp ~/minecraft.jar net.minecraft.LauncherFrame

Or, without setting the memory and classpath variables, like this:

java -jar ~/minecraft.jar

Be aware that the LD_LIBRARY path will only be set for the current session of the current shell, so you’ll have to re-set it a lot. A quick and easy way to do this is to just knock together a quick launcher script as below (substituting your paths in) and throw it in /usr/local/bin:

minecraft.sh

#!/bin/bash
export LD_LIBRARY_PATH="/usr/lib/jvm/jdk1.7.0_07/jre/lib/amd64"
java -Xmx1024M -Xms512M -cp ~/Games/Minecraft/minecraft.jar net.minecraft.LauncherFrame

Final Notes

Not being able to set a persistent LD_LIBRARY_PATH is a pain, because it won’t take if set in the ~/.profile or ~/.bash_profile or ~/.bash_rc config files (I’m not so sure about ~/.pam_environment) – which you can read about here: https://help.ubuntu.com/community/EnvironmentVariables.

There’s a fix which involves disabling ssh-agent in this bug report (see post #21 here), but really for the sake of a two line launcher script I think it’s best to just leave it be.

Happy mining and crafting! =D

Comments
9 Comments »
Categories
Gaming, How-To, Linux
Tags
Java, LD_LIBRARY_PATH, Linux, Minecraft
Comments rss Comments rss
Trackback Trackback

How To: Install the official Oracle JRE/JDK in Linux

r3dux | September 26, 2012

Installing the official Sun/Oracle Java implementations used to be as easy as installing sun-java6-* and uninstalling all the OpenJDK and IcedTea (Java plugins based on OpenJDK) packages you could find – but you can’t get the offical “Sun” packages anymore, instead you have to go get the binaries from Oracle (who bought Sun Microsystems). You can take a swiz at the possible Java implementations here if you like.

Anyways, to get and install the official JRE or JDK (I’ll assume that most people aren’t going to be developing in Java so only want the Runtime Environment and not the full Development Kit):

  1. Head on over to: http://www.oracle.com/technetwork/java/javase/downloads/index.html and download tar.gz version of the latest JRE, which at the time of writing is 1.7 update 7 (i.e. 1.7.0_07, the Linux 64-bit version of which is called jre-7u7-linux-x64.tar.gz),
  2. Extract the downloaded archive through any way you see fit. I’ll assume you downloaded it to your Downloads folder and extracted it there for the following commands,
  3. Create a new folder for it wherever your distro likes to put Java installs, for example:
    sudo mkdir /usr/lib/jvm/jre1.7.0_07
  4. Move your extracted JRE to that location using:
    sudo mv ~/Downloads/jre7_u7/* /usr/lib/jvm/jre1.7.0_07/"
  5. Update your alternatives to prefer the new version of java by running (one line at a time):
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.7.0_07/bin/java" 1
    sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jre1.7.0_07/bin/javaws" 1

    If you’re installing the JDK you’ll prolly want to set the javac (Java Compiler) binary to the new version too using:

    sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jre1.7.0_07/bin/javac" 1

    The number at the end of the line is the priority of this binary out of any other java/javac/javaws binaries alternatives knows about, and goes from 1 (most important – try to use first) to 100 (least important – use only as a last resort)

  6. If you want to set, or make sure the update-alternatives commands took, you can also run (again, one line at a time):
    sudo update-alternatives --config java
    sudo update-alternatives --config javaws
    sudo update-alternatives --config javac     <-- only if you installed the JDK
  7. Finally, to check it all really took, issue:
    java -version

    and you should see some output showing that the newest version of Java is in effect, like this:

    java version "1.7.0_07"
    Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
    Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

Done & dusted.

Comments
1 Comment »
Categories
How-To, Linux
Tags
install, Java, JDK, JRE, Official, Oracle, Sun, update-alternatives
Comments rss Comments rss
Trackback Trackback

Me vs. Software vs. The World, or How to transition from Alpha to Beta

r3dux | October 16, 2011

Race Day

Concept (left) meets Reality (right)

Things like this are hard to write – but today has been one of the best days of my life.

I’ve spent the last two weeks writing a receipt system for a bookmakers, so they can rock up to a race meet (horses), place a big board of odds, and take and give a lot of money. I was asked to write the software to keep track of it all, and I did – by working 12 hour days and finishing on a final 22 hour coding session to get it all up and running a whole 15 minutes before leaving for “delivery”.

I wrote it in a language foreign to me (Java) so it can run on anything, I hadn’t tested it very well, and I didn’t know if it would work in the real world until it got to the point of taking multiple crisp $100 bills off gruff, semi-drunken people at the race track.

To back up a second, the game here is “doubles” – you pick a horse to win in one race, and another horse to win in any other race, and you get the multiplied odds if both horses win – for example, Race 1 Horse 2 has 10 to 1 odds, Race 3 Horse 4 has 20 to 1 odds, so you get (10 x 20) 200 to 1 odds, and if you then place $10 on that combination and both those horses win you’re in for a $2,010 return. Sounds simple enough to keep track of, right? And on paper it is – but the devil is always in the details.

So I worked on the details, and it got the the point where money was changing hands. Real money. And lots of it. All going through my software. So if things failed now, it would be… bad.

But nothing did: Every race to perfection. Every bet to the (Australian rounded) nickel. Every composite object to the correct [serialized/deserialized] binary stream, every fat-fingered illegal input handled gracefully. 0 crashes. 0 errors. 0 fuck-ups.

I won’t deny it: for how last-minute, and with how little testing got done, I got lucky – but that doesn’t change the fact that everything worked perfectly: first-time.

I knocked it out of the park.

Awesome =D

Comments
3 Comments »
Categories
Coding, Life
Tags
Bookmakers, Development, Java, Races
Comments rss Comments rss
Trackback Trackback

How-To: Initialise arrays of objects in Java

r3dux | October 7, 2011

You might think, like I did, that if you create an array of objects in Java then the constructor is automatically called on each object as part of the array creation process. But you’d be wrong.

Creating an array merely creates the object references – you have to instantiate each “inner” object in the array as a separate step if you want to be able to, ya know, do stuff… I think this is because in Java an array is an object – like, quite literally a single object that can be passed around like a single thing.

An example, perhaps?

Person Class

public class Person
{
	private int number = -1; // Each person gets a default number of -1 on creation
 
	// Default constructor
	public Person()
	{
		// The number property is left as -1 as per the default value specified above
	}
 
	// One parameter constructor which overwrites the default number value with a specified value
	public Person(int theNumber)
	{
		number = theNumber;
	}
 
	public void displayNumber()
	{
		System.out.println("My person number is: " + number);
	}
}

PersonTestDrive Class

public class PersonTestDrive
{
	final static public int MAX_PEOPLE = 3;
 
	public static void main(String[] args)
	{
		// Create an array of people. You're not creating any new People objects here - you're creating a new Array object
		Person[] people = new Person[MAX_PEOPLE];
 
		// *** INCORRECT : The Person objects in the people array don't exist yet! They're only references at this point! ***
		// for (Person tempPerson : people)
		// {
		// 	tempPerson.displayNumber(); // This doesn't give "-1" for each person, it gives a NullPointerException!
		// }
 
		// *** CORRECT : Instantiate each Person object in the array before accessing them! ***
		for (int loop = 0; loop < MAX_PEOPLE; loop++)
		{
			people[loop] = new Person(loop+1); // Create the Person object, setting the number property in this case
 
			people[loop].displayNumber();      // Now it'll output "My person number is: 1" etc. as expected
		}
	}
}

Comments
5 Comments »
Categories
Coding, How-To
Tags
Array, Constructor, Exception, Initialise, Java
Comments rss Comments rss
Trackback Trackback

How-To: Get human-friendly dates in Java using the Calendar class

r3dux | October 4, 2011

ISO-8601 has a PosseAs part of the groundwork for some upcoming Java shenanigans I’ve finished off reading/skimming Head First Java – and it’s a truly excellent book. I wish it covered Connector/J & MySQL, but I can find that knowledge elsewhere so it’s not that big of a deal.

As part of today’s prep I ended up writing something I didn’t think I’d have to – a function to get a nice, human-readable date as a String. I don’t like having to write things like this because surely getting a nice, human-readable version of what’s essentially a timestamp (if the Date class wasn’t deprecated) has been solved. By which I mean that it’s done – let’s never, ever solve that same problem again. But the issue is that if you don’t know where to look for the solution, then it can take you longer to find it than to solve the problem again, and I think that’s what’s happened to me today when I didn’t feel like learning and using the joda-time API to do something I felt core Java should be capable of.

Before we get to the source code I’d just like to direct a quick word to to the Java API Calendar class developers to say:

  • I don’t care who you worship – the first day of the week is Monday, please see ISO-8601, and
  • Chopping and changing between zero-based constants and one-based constants sucks massive d*cks.

Anyways, the getFriendlyDate function gets a day/month/year from a Calendar object and converts it into something a human being might like to read, like this…

$ java FriendlyDate
 
The only-friendly-to-robots date is : java.util.GregorianCalendar[time=1317711607960,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+10:00",offset=36000000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2011,MONTH=9,WEEK_OF_YEAR=40,WEEK_OF_MONTH=1,DAY_OF_MONTH=4,DAY_OF_YEAR=277,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=0,SECOND=7,MILLISECOND=960,ZONE_OFFSET=36000000,DST_OFFSET=0]
 
The more-like-a-timestamp date is   : Tue Oct 04 17:00:07 GMT+10:00 2011
 
The verbose friendly date is        : Tuesday the 4th of October 2011
 
The non-verbose friendly date is    : Tuesday, 4th October 2011

And the source code to perform this scandalous transformation is:

Update 13-Oct-2011: Just realised that the 1st, 2nd, 3rd etc. stuff is broken because I’m checking the last digit in the day of month and using that, so if it ends with 3 I give the suffix “rd” making it “3rd”, which is fine until you get to the 13th, which comes out as “13rd”… I don’t have time to fix it up right now, but I will in the near future. Or do a total re-write using the mighty Shetboy’s formatting advice (see comments).

import java.util.Calendar;
 
public class FriendlyDate
{
	public static void main(String[] args)
	{
		 // Get the current date and time in a Calendar object
		Calendar now = Calendar.getInstance();
 
		System.out.println("The only-friendly-to-robots date is : " + now.toString() );
		System.out.println();	
 
		System.out.println("The more-like-a-timestamp date is   : " + now.getTime() );
		System.out.println();
 
		String verboseFriendlyDate = getFriendlyDate(now, true);
		System.out.println("The verbose friendly date is        : " + verboseFriendlyDate);
		System.out.println();
 
		String friendlyDate = getFriendlyDate(now);
		System.out.println("The non-verbose friendly date is    : " + friendlyDate);
	}
 
	// Overloaded function to cut down on calling arguments, no default parameters in Java =/
	public static String getFriendlyDate(Calendar theDate)
	{
		return getFriendlyDate(theDate, false);
	}
 
	// Function to get a human readable version of a Calendar object
	// If verbose is true we slightly expand the date wording
	public static String getFriendlyDate(Calendar theDate, boolean verbose)
	{
		int year       = theDate.get(Calendar.YEAR);
		int month      = theDate.get(Calendar.MONTH);
		int dayOfMonth = theDate.get(Calendar.DAY_OF_MONTH);
		int dayOfWeek  = theDate.get(Calendar.DAY_OF_WEEK);
 
		// Get the day of the week as a String.
		// Note: The Calendar DAY_OF_WEEK property is NOT zero-based, and Sunday is the first day of week.
		String friendly = "";
		switch (dayOfWeek)
		{
			case 1:
				friendly = "Sunday";
				break;
			case 2:
				friendly = "Monday";
				break;
			case 3:
				friendly = "Tuesday";
				break;
			case 4:
				friendly = "Wednesday";
				break;
			case 5:
				friendly = "Thursday";
				break;
			case 6:
				friendly = "Friday";
				break;
			case 7:
				friendly = "Saturday";
				break;
			default:
				friendly = "BadDayValue";
				break;
		}
 
		// Add padding and the prefix to the day of month
		if (verbose == true)
		{
			friendly += " the " + dayOfMonth;
		}
		else
		{
			friendly += ", " + dayOfMonth;
		}
 
		String dayString = String.valueOf(dayOfMonth);   // Convert dayOfMonth to String using valueOf
 
		// Suffix is "th" for day of day of month values ending in 0, 4, 5, 6, 7, 8, and 9
		if (dayString.endsWith("0") || dayString.endsWith("4") || dayString.endsWith("5") || dayString.endsWith("6") ||
                    dayString.endsWith("7") || dayString.endsWith("8") || dayString.endsWith("9"))
		{
			friendly += "th ";
		}
 
		// Suffix is "st" for day of month values ending in 1
		if (dayString.endsWith("1"))
		{
			friendly += "st ";
		}
 
		// Suffix is "nd" for day of month values ending in 2
		if (dayString.endsWith("2"))
		{
			friendly += "nd ";
		}
 
		// Suffix is "rd" for day of month values ending in 3
		if (dayString.endsWith("3"))
		{
			friendly += "rd ";
		}
 
		// Add more padding if we've been asked to be verbose
		if (verbose == true)
		{
			friendly += "of ";
		}
 
 
		// Get a friendly version of the month.
		// Note: The Calendar MONTH property is zero-based to increase the chance of developers making mistakes.
		switch (month)
		{
			case 0:
				friendly += "January";
				break;
			case 1:
				friendly += "February";
				break;
			case 2:
				friendly += "March";
				break;
			case 3:
				friendly += "April";
				break;
			case 4:
				friendly += "May";
				break;
			case 5:
				friendly += "June";
				break;
			case 6:
				friendly += "July";
				break;
			case 7:
				friendly += "August";
				break;
			case 8:
				friendly += "September";
				break;
			case 9:
				friendly += "October";
				break;
			case 10:
				friendly += "November";
				break;
			case 11:
				friendly += "December";
				break;
			default:
				friendly += "BadMonthValue";
				break;
		}
 
		// Tack on the year and we're done. Phew!
		friendly += " " + year;		
 
		return friendly;
 
	} // End of getFriendlyDate function
 
} // End of FriendlyDate class

Cheers!

Comments
13 Comments »
Categories
Coding, How-To
Tags
Calendar, DATE, DATETIME, Friendly, Human, Java, Readable, TIMESTAMP
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Translate

Categories

Archives

Tags

3D ActionScript ActionScript 3.0 Adobe AI Ballarat Bash C++ Class Convert CS4 Effect Error Film Flash FPS GLFW Glitch GLSL Hack How-To install Java Kinect Linux Live Mash-Up Microsoft Motion mount OpenGL Particle Problem PS3 Remix Retro script Slides Sound Ubuntu Video VirtualBox Wii Windows XBox

Gamercard

OpenR3dux

Misc.

Flattr this

RSS Feed

r3dux twitter feed



“If at first you don't succeed, try & try again. Then give up. There's no point being an idiot.”

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox