0

I've read this and this.

I've done a mvc TicTacToe with Eclipse IDE for Java Developers, Version: 2021-12 M3 (4.22.0 M3). It's a java project (not maven) and it's using JavaSE-17 libs as JRE System Library (installed latest jdk). I'm using swing libs, action listeners, action events ecc ecc. Standard libs you find in your java installation.

Right click on project folder --> Export... --> Runnable jar file --> Extract required libraries into generated JAR

and my program works as expected, like when I run the main class inside Eclipse.

Right click on project folder --> Export... --> Runnable jar file --> Package required libraries into JAR

and my program starts but doesn't work as expected: looks like my AI part doesn't work, some of my little animations don't work too (animations of this kind, this one is working tho) and my new game button has a strange behaviour (it keeps looking pressed until I move the mouse cursor away from its button area).

Now: I've looked inside both jars and the only differences are:

  1. the package one contains a "org" folder the working one hasn't: enter image description here

  2. the MANIFEST.MF file inside the META-INF folder is slighty different. In the package one is:

       Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
       Rsrc-Class-Path: ./
       Rsrc-Main-Class: Main
       Class-Path: .
    

in the working one is:

Manifest-Version: 1.0
Main-Class: Main
Class-Path: .

As far as I'm understading, I'm not using external libs. This is my eclipse project folder:enter image description here

and this is my build path: enter image description here

I don't know what I'm missing... I've included both folders (src and pics... the latter is just a folder with images I correctly see in both exports)

My question: why the jar produced by exporting with Package required libraries into JAR it's not properly working in my case?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Goet
  • 57
  • 1
  • 1
  • 8
  • How is the code loading these resources? – Andrew Thompson Feb 04 '22 at 06:29
  • If you mean the pic folder, by getClass().getResource(Pics.MYPIC) with Pics being a class full of a bunch of static fields like this: public static final String WIN = "/win.png"; – Goet Feb 05 '22 at 22:14
  • How is `/win.png` used to load the image? BTW - If using `getResource`, the leading `/` implies a path from the root of the Jar, so the correct path might be `/pics/win.png`. – Andrew Thompson Feb 05 '22 at 22:56
  • What you mean by "how `/win.png` used to load the image?" I mean: `/win.png` is just the path of the pic file inside my project folder (see last pic of my post: since I've included the "pics" folder in my build path I should be able to refer to each pic in that folder like this: `/picName.png` ). The assignment is for the most part something like this: `JLabel myJLabel = new JLabel(new ImageIcon(getClass().getResource(Pics.MYPIC)));` I indeed correctly displays pics in both scenarios... I mean, the problem should not be the way my program loads pics – Goet Feb 06 '22 at 00:00

0 Answers0