0

I am observing the following problem. I create a java application and put all files (runnable jar file + jar to exe + other files and folders into a folder "adim" and place it in D drive (D:\adim). When I run the application it finds the license.lic file from adim folder works perfectly fine.

But when I change the folder "adim" with "Adim With Derby" this application shows an error that "it cannot find the license.lic file".

The worst is that when I make a installShield package and install it on "Program files(x86)" [c:\Program Files(x86)\ADIM] above mentioned problem appears(license file not found). Note: the os is windows 7 professional 64bits

Can anyone help what is wrong and what is its solution?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
dar189901
  • 11
  • 1
  • 4
  • 3
    Do you have a hardcoded path in your application? – Sotirios Delimanolis Jun 13 '13 at 18:25
  • @SotiriosDelimanolis I agree with above comment, also is there environment variable that your program might be looking for in order to read the file (if the file name is not hard coded some where). another place I suggest look for is database...field ..maybe the file name is set there. good luck – grepit Jun 13 '13 at 18:29
  • there is no hard coded path in the application. Application works fine in any folder without space in the name of the folder. – dar189901 Jun 13 '13 at 18:35
  • @dar189901: How are you using the handling the paths? Are you manually manipulating them as strings? Can you show the code that is causing the error? – unholysampler Jun 13 '13 at 18:38
  • To access license file I use the following procedure File license = new File(Utils.getClassPath()+"license/license.lic"); where the getClassPath() is following public static String getClassPath() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL url = classLoader.getResource(""); URI uri = null; try { uri = url.toURI(); } catch (URISyntaxException e) { e.printStackTrace(); } String path = uri.toString(); if (uri.toString().startsWith("file:/")) { path = path.substring(6, path.length()); } return path; } – dar189901 Jun 13 '13 at 18:51
  • Don't include code in comments, it is unreadable. Instead [edit](http://stackoverflow.com/posts/17094357/edit) it into the question. *"what is its solution."* Probably to access these things as an [tag:embedded-resource] (i.e. put them in a Jar). – Andrew Thompson Jun 13 '13 at 19:32

1 Answers1

0

You need to properly escape your file names use backslash before special characters

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • I could not understand your comments. I never need escape name when folder name is free from space. For example when I use name "adim", "AdimWithDerby" or use just "a" as folder names, application works fine. But when I introduce space in the folder name like "Adim With Derby" then I observer this problem. – dar189901 Jun 13 '13 at 18:38
  • @dar189901 How are you running your application? Where is the path used in the application? – Sotirios Delimanolis Jun 13 '13 at 18:39
  • I create a runnable jar file then convert it into exe file. And put all related files and folder in the same folder. It works fine only problem is with the spaces in the folder name. – dar189901 Jun 13 '13 at 18:46
  • @dar189901 try to cd My folder and it won't work. you would need to cd "My folder" So I suspect something inside your code not paying attention to the path. Post the piece of code in your question and it is more likely you get a solution to your problem. If the issue is in 3rd party code, you might need to contact their support – stwissel Jun 14 '13 at 02:51
  • Thanks for everyone. The problem was that I get the class path in the format of URL (e.g. file:C:\Program Files (x86)\adim) and convert it into string which becomes "C:\Program%20Files%20(x86)\adim". This in string format is not recognized as "c:\Program Files x(x86)\adim"(as windows consider %20 not space but some characters which are part of the path. That is why path is not recognizable. So I used the standard URL format and it solves the problem. Again thanks everyone for your contribution. – dar189901 Jun 14 '13 at 10:52
  • That's what is called 'escape' a file name ;-) – stwissel Jun 14 '13 at 11:49
  • Sorry I don't know about that. Thanks for the explanation it updates my knowledge. Thanks again – dar189901 Jun 14 '13 at 13:39