0

I am generating my jar file with Intellij Idea, and it works. However, I extracted the jar to see why it was mysteriously bigger in size then expected. I found the resources directory, containing all my images, as expected, but... for some reason, outside the resources directory, in the 'main' folder when you first open the extracted jar, are all the images again.. duplicated. This does not reflect my project structure or anything, the only place I have images are in resources. Anyone know what's going on, and how to stop this?

Project Structure:

enter image description here

enter image description here

Totem
  • 7,189
  • 5
  • 39
  • 66

1 Answers1

1

Check the jar artifact configuration, make sure it's not set to package the contents of the resources directory inside the jar (just the compiler output entry would be enough since it will contain the resources already).

If it's not the case, check the output directory of your project. The files from the resources directory should be present inside the root of the output directory. If there is resources subdirectory, delete it and rebuild the project, ensure it doesn't appear in the output again.

In case the resources subdirectory appears in the module output after rebuild, verify the module roots configuration. It could be that the directory above resources is configured as resources (or sources) itself.

If you can't figure out the problem, please share a complete sample project illustrating it and I'll point you to the exact configuration you should change.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • How could I tell if the artifact configuration is set to package the contents of resources into the jar? Only two things are in the 'output layout' tab, MyProject.jar and below it, 'MyProject' compile output. – Totem Feb 12 '17 at 00:05
  • Then you should check the compiler output as described in the answer. – CrazyCoder Feb 12 '17 at 00:11
  • Ok, that seems to be set that way by default for some reason.. should the Source root be something else, or should I just undo that? – Totem Feb 12 '17 at 00:22
  • Source root should be only your `src` directory, not anything above it. You should mark as Source only the root directory for your Java files (the default package directory, on your screenshot it's `src`). – CrazyCoder Feb 12 '17 at 00:24
  • Ok done.. It's caused all sorts of import problems (for instance, Monopoly.aVariable stopped working, and alt-enter to import it properly turned it into src.Monopoly.aVariable.. and the 'src' part is now showing an error as unrecognised.. so I'm not sure how to import from a class in the same folder now) but I'll try and figure it out.. – Totem Feb 12 '17 at 00:28
  • You need to add a package and Refactor | Move your classes into this new package under src directory because Java doesn't support importing from the default package: http://stackoverflow.com/questions/2193226/how-to-import-a-class-from-default-package – CrazyCoder Feb 12 '17 at 01:33