Export Project with Images

Asked

Viewed 436 times

0

So I made a game on Eclipse and I’m trying to export it to a jar file only that unsuccessfully. The export works, but the images don’t go together at all... Here’s an example of how I’m instantiating the images:

private Image imagem;
ImageIcon a = new ImageIcon("caminho");
imagem = a.getImage();

Yes, the images are inside the SRC folder.

  • Are the images inside the project? If not, it won’t matter together anyway.

  • Yes they are inside the src folder

  • Adds a print of your project hierarchy in the eclipse in the question.

  • Note that the IDE does not recognize the folder as an application package, create a package(package) and re-create the photos for it, and try to re-compile the jar.

  • But the images are inside a package (package images, that’s not a folder)

  • Look at the image you posted and compare package with other. Eclipse highlights a package co. The brown color. Readicione the package, it is very likely that the problem is what I have already mentioned.

Show 1 more comment

1 answer

0

This error might be related to how you are exporting your jar. Or maybe how you are setting the path to your image. This means that your images are being exported to the jar, but are no longer on the path you have set in development.

I recently went through the same problem. See how I solved:

1 - First you create a folder in the project root directory:

inserir a descrição da imagem aqui

2 - Then you can define a constant that keeps the base path of your project. Using the System.getProperty("user.dir") variable, you transfer the responsibility to the jvm to pass the path to your project directory. Whether you are in development or production.

inserir a descrição da imagem aqui

  • user.dir will return the path of its user folder on windows system only. His intention, as I understand it, is to compile the images together with the jar, not search them in the user folder.

  • user.dir = User Working directory user.home = User home directory The vairavel that refers to the user folder is "user.home". You can browse here. https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

  • Yes, but from what I understand, the goal is to compile the jar with the images, and the problem is not quite that of the answer. I believe the ide is not recognizing the img pasga as a project package, but rather as an external folder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.