0

I'm using code from here to change my desktop background to a set picture. This code works perfectly in Eclipse, but when I package the application to a runnable jar, it doesn't do anything. Running

java -jar DesktopChanger.jar

from the command line doesn't result in any errors. It just prints out a job completed message (sysout) and ends, but the wallpaper didn't change.

I imported the jna libraries jna-platform-4.1.0.jar and jna-4.1.0.jar from here. The only difference between my code and the other question is a sysout, a messageDialog to say the job finished, and the location of the picture:

String path = "src/background/changer/picture.jpg";

Finally, in Eclipse I right click on the project

  • hit "Export"
  • select "Runnable JAR File"
  • select "Package required libraries into generated JAR"
  • and finish.

I've even messed with the Manifest.mf file since Eclipse sets "Main-Class:" to it's own main, using "Rsrc-Main-Class" for the actual one. So I deleted "Rsrc-Main-Class" and put my main into "Main-Class" but again nothing works.

Do I also need to package the native code or dll files?

Community
  • 1
  • 1
Sivan
  • 3
  • 4
  • Try moving the picture to a location not in your jar file. That's got to be the issue, as it won't be able to access that location. Try (for example) `c:\\picture.jpg`. – Pokechu22 Sep 16 '14 at 18:34
  • Wow, that worked! Thank you. However, if I want to include the picture inside the jar, is there no workaround to get the native code to access it? – Sivan Sep 16 '14 at 18:57

1 Answers1

1

Your issue is the path of the image. The path you used is inside of your jar file, and as such windows can't locate it. Thus, it just ignores the request.

Change it to something like this:

String path = "C:\\picture.jpg";

and put the picture in that location.

Pokechu22
  • 4,984
  • 9
  • 37
  • 62