1

I have a very strange problem, that I can't figure out, the thing is that my aplication runs perfectly on the IDE (Eclipse), but not when exported, when I run the jar (double click) the aplication start but some functionality is missing (loading from a template file, but this does not happend when loading from a normal file), when I try to run it from console (java - jar my.jar) in order to see any error message it turns out that my aplication works perfectly fine! :S ...

Some more info:

My app is running over windows 7

I start the task manager, and I noticed that when I start my aplication using double click its under the name java.exe *32, and when I do it from command line its under the name java.exe (without "*32"), as far as I know I programmed nothing related to a 32 or 64 bits functionallity.

"Solved"

Well I was not able to solve it the way I wanted, as far as I was able to find, i found that there were a problem between the 2 java versions I was running x32 & x64, I deleted the 32 bit version and it start working as a charm, but I'm still not sure about what happend, I give my thanks to @Sajal Dutta one of its comments help me to understand part of the problem, thanks to all of you anyway, I'll keep searching until I find the problem...

tshepang
  • 12,111
  • 21
  • 91
  • 136
Ordiel
  • 2,442
  • 3
  • 36
  • 52
  • What does "some functionality is missing (loading from a template file, but this does not happend when loading from a normal file)" mean? – supersam654 Aug 16 '13 at 13:25
  • You see, I created a file, a serialized file, which represents my template, and another exactly identical but a variable, but my software do not open when I try to load a template (the serialized file without a field) but it does when I try to open a file (with all the fields) – Ordiel Aug 16 '13 at 13:57
  • When "some functionality is missing" do you get any errors? If yes then please add the error(s) and the code that produces it in your question – c.s. Aug 16 '13 at 14:05
  • no, it just "freeze", in detail, I select the template I want to use, and it starts loading (I dispose all my windows when loading the template info) but it just never display the info of the template (just like if it keep reading the template), the weird thing is that IT DOES WORK when I'm working in the IDE and also when I run my jar from console... – Ordiel Aug 16 '13 at 14:10
  • I can't see any error, because when I run my app from console, it works, and when I don't... well, I don't have any console to see it XD – Ordiel Aug 16 '13 at 14:11
  • Then add the loading code please. We need to start from somewhere don't we? Otherwise nobody gets the picture as you have probably realised from the answers you have received until now – c.s. Aug 16 '13 at 15:38

3 Answers3

0

When you create a jar from Eclipse, your assets don't get copied over to jar or location is not preserved. Open the jar and check if you have your templates in the right location or you have it at all.

To have the exported jar include your assets/resources-

  1. Right click on your project in Eclipse. Then New -> Source Folder.
  2. Name the source folder anything. e.g. template_src.
  3. Copy or drag the entire directory of your template to template_src. Then make the jar.
Sajal Dutta
  • 18,272
  • 11
  • 52
  • 74
  • I see your point, but I think I didn't express my self in an appropriate way, when I say template is because my App is a document based aplication, the template files shouldn't be jared – Ordiel Aug 16 '13 at 14:00
  • @Ordiel Maybe it's a path issue when you double click. Can you put a log of the location it's trying to load the template from, not the location you are asking it to load from..rather the location it's trying to look into. – Sajal Dutta Aug 16 '13 at 14:16
  • ok.... but... why would it work in the other 2 situations, (IDE, console), is there any difference on the behavior and handling of the paths when running with double click?... – Ordiel Aug 16 '13 at 14:21
  • 1
    @Ordiel This might help- http://stackoverflow.com/questions/17603961/double-click-vs-java-jar-myjar-jar – Sajal Dutta Aug 16 '13 at 14:27
0

Since it works via the command line but not when double-clicking the jar, it is likely that the working directory is different (and that you're loading the template with a relative path). When you run an executable jar by double-clicking, on some operating systems, the working directory is the home directory whereas when you run from the command line, it's the directory you're currently in.

Chris
  • 22,923
  • 4
  • 56
  • 50
0

The "files" in the jar are not handled by File, but are resources;

URL url = getClass().getResource("...");
InputStream in = getClass().getResourceAsStream("...");

Then, the file paths inside a jar, or on a non-Windows platform are case-sensitive.

"Template_A.xml"

is not

"template_a.xml"

Also you might inspect the jar with 7zip or WinZip.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138