0

I shifted my project from tomcat to eclipse. All files are working fine but the folder containing property files are not working.

What I did so far:

  1. Added folder in project -> build
  2. created a source folder in project/src root and moved all
  3. Set the classpath environment variables
  4. Changed path with //, first folder without / etc.

but nothing worked for me. Here is screen shot:

enter image description here

Please advise where I am making mistake? My OS is windows 8 but I have to deploy on CentOS IDE: eclipse neon 3.0

thanks in anticipation

Community
  • 1
  • 1
Devdas
  • 69
  • 1
  • 2
  • 10

3 Answers3

0

It will be just /lang/global/settings.properties without main

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • I just checked but same error. java.io.FileNotFoundException: \lang\global\settings.properties (The system cannot find the path specified – Devdas Jun 04 '17 at 15:44
  • In tomcat my project is working fine but in eclipse its killed me to correct the properties file path – Devdas Jun 04 '17 at 16:55
  • @Devdas just replaye FileInputStream with ConfigReader.class.getResourceAsStream(); – Antoniossss Jun 04 '17 at 18:01
  • InputStreamReader reader = new InputStreamReader(new FileInputStream(ConfigReader.class.getResourceAsStream(filename)),"UTF-8"); but its giving error. Not compiling – Devdas Jun 04 '17 at 18:36
  • @Devdas dude remove `FileInputStream`. – Antoniossss Jun 04 '17 at 18:38
  • InputStreamReader reader = new InputStreamReader(ConfigReader.class.getResourceAsStream(filename)),"UTF-8"); but still showing red cross sign on the left side of line – Devdas Jun 04 '17 at 18:53
  • I tried with full path (absolute path and its working) but why its not understanding eclipse folder structure? – Devdas Jun 04 '17 at 19:04
  • I told you to ommit the 'main` part already. I bet your filename still has it. – Antoniossss Jun 04 '17 at 19:08
0

You can try with this:

ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream stream = loader.getResourceAsStream("/lang/global/settings.properties");

If this doesn't works, you can check it out these links: mkyong, crunchify

elmigue017
  • 343
  • 2
  • 12
  • thanks for your reply. I am hitting my heading for the last 10 hours and googled a lot. I already tried this solution but the problem is my properties file are UTF. I mean containing Arabic, Perisan and English data. with InputStream utf not works that's why I used InputStreamReader instead – Devdas Jun 04 '17 at 16:04
0

Thanks all who tried to helped me. I appreciate their efforts.

After spending many hours I found the solution from this post

Copying solution here:

URL url = ConfigReader.class.getClassLoader().getResource("lang/global/settings.properties");
String filename = url.getPath();  

Thanks

Devdas
  • 69
  • 1
  • 2
  • 10