Hey guys
I was hoping someone could help me here. I had to make a Tetris game using eclipse for my intro to Java programming class. I got it all done, but i would like to play the game without having to run it through eclipse. For example if i wanted to send the game to a friend, i wouldnt want him to have to download eclipse before he can play it. so is there a way that i can have a short cut to it on my desktop and just by a double click i could play it? I would appreciate it if someone could give some step by step instructions on how to do it.

Dani AI

Generated

Good call by — the simplest way to make your Tetris runnable outside Eclipse is to export a runnable JAR and make sure your resources and libraries are packaged correctly. Below are practical, concrete steps and common fixes so a friend can double‑click a desktop icon and play.

Export from Eclipse

  • Create or confirm a Run configuration that uses your Tetris main class.
  • File > Export > Java > Runnable JAR file.
  • Choose the Run configuration, set an output path, and for Library handling pick “Extract required libraries into generated JAR” (or “Package required libraries”).
  • Make sure images/sounds are on the classpath (put them in src/resources or the same package as code) and are loaded with classpath calls (see below), not with plain File paths.

Manifest example

Main-Class: com.yourpackage.TetrisMain

(Important: manifest must end with a blank line.)

Running & shortcut

  • From command line: java -jar Tetris.jar (use javaw on Windows to suppress a console).
  • To create a Windows shortcut target, point it at javaw with -jar:
    "C:\Program Files\Java\jre1.8.0_xxx\bin\javaw.exe" -jar "C:\path\Tetris.jar"
  • A simple batch wrapper can also launch the jar from the game folder.

Resource loading tip

  • Inside a JAR, use classpath resource loading:
    InputStream in = getClass().getResourceAsStream("/images/block.png");
    BufferedImage img = ImageIO.read(in);

    If you used new File("images/...") it will fail once packed.

Troubleshooting quick list

  • “Could not find or load main class” → wrong Main-Class in manifest or wrong package name/case.
  • NoClassDefFoundError → required libraries not included; re-export with libraries extracted or build a fat JAR (Maven Shade/Gradle shadow).
  • Double‑click does nothing → .jar not associated with Java or Java not installed; use javaw in a shortcut or bundle a runtime.

For polished distribution, consider wrappers (Launch4j/JSmooth) or jlink/jpackage to bundle a JRE, but for a class project a runnable JAR plus a short “how to run” note is usually enough.

Recommended Answers

All 2 Replies

jar file

Thanks quuba

It was lot simpler than i thought. All the research I have done,dealt with messing around with command prompt and all kinds of nonsense.

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.