• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem not loading a properties file

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody
I am developing an application which reads a file known as key.properties .
When i run the application on tomcat6 and jboss 4.2.3 it's working fine
But when I run the application on jboss 5.1.0 it's not working.
It is saying that keys .properties doen't exist but it is present in the class path..

I am having a servlet WebTest which calls a keysutil class for other operations
my error is

15:40:39,698 ERROR [STDERR] java.io.FileNotFoundException: class path resource [keys.properties] cannot be resolved to absolute file path because it does not reside in the file system: vfsfile:/C:/jboss-5.1.0.GA/jboss-5.1.0.GA/server/default/deploy/estw.war/WEB-INF/classes/keys.properties


********************************************************************
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public final class WebTest extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
/*
* System.out.println(getClass().getResource("/"));
* System.out.println(getClass().getResource("/").getPath());
* System.out.println(getClass().getResource("/").getFile());
* System.out.println(request.getRequestURI());
* System.out.println(request.getRealPath("/"));
* System.out.println(request.getPathInfo());
* System.out.println(getClass().getResource("").getPath()); String name
* = this.getClass().getName().replace('.', '/');
* System.out.println(this.getClass().getResource("/").toString());
*/
System.out.println("calling path method");

KeysUtil util = new KeysUtil();
try {
createDefaultFolder("xyz");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("ending path method");
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
String path = new java.io.File(".").getCanonicalPath();
System.out.println("************************");
System.out.println(path);
writer.println("<html><head><title>Simple Web Application</title></head>");
writer.println("<body><h1>A Simple Web Application</h1>");
writer.println("Here's some text...<br>...and a bit more text");
writer.println("</body></html>");
}

private void createDefaultFolder(String vendorName) throws Exception {
KeysUtil util = new KeysUtil();
util.createDefaultKeyFolder(vendorName);
}

}


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;

public class KeysUtil {
private File classBaseDirectory;
private Properties keyProps = null;

public KeysUtil() {
this.classBaseDirectory = returnClassPath();
}

private File returnClassPath() {
System.out.println("In returnClassPath method");
String tempPath = getClass().getResource("/").getPath();//this is returning / only
if (tempPath != null && tempPath.length() != 0) {
tempPath = cleanFilePath(tempPath);
}
return new File(tempPath);
}

public static String cleanFilePath(String filepath) {
return filepath.replaceAll("%20", " ");
}

public boolean checkDefaultFilesExists() throws Exception {
ClassPathResource res = null;
File defaultKeyPropertyFile = null;
res = new ClassPathResource("keys.properties");//here i am calling key.properties
if (res.exists()) {
defaultKeyPropertyFile = res.getFile();//here defaultKeyPropertyFile is coming to null
System.out.println(defaultKeyPropertyFile);
setKeyProps(loadPropertyFile(defaultKeyPropertyFile));
if (keyProps != null) {
String keyFile = keyProps.getProperty("keystore.filename");
System.out.println("keyFile" + keyFile);
if (keyFile != null) {
res = new ClassPathResource(keyFile);
if (res.exists()) {
return true;
}
}
}
}
return false;
}

public void createDefaultKeyFolder(String vendorName) throws Exception {
if (checkDefaultFilesExists()) {
String path = createVendorFolder(replaceSpace(vendorName));
File vendorFolder = new File(path);
if (vendorFolder.exists()) {
File defaultFolder = new File(vendorFolder, "Default_Keys");
if (!defaultFolder.exists()) {
defaultFolder.mkdir();
// allowGroupAccessToFolder(defaultFolder.getName());
}
// transferDefaultKeyFiles(defaultFolder.getAbsolutePath());
}
}
}

private Properties loadPropertyFile(File file) {
Properties keyProps = new Properties();
InputStream keyStream;

if (file != null && file.exists()) {
try {
keyStream = new FileInputStream(file);
keyProps.load(keyStream);
keyStream.close();
} catch (FileNotFoundException e) {
System.out.println("Key property file not found");
} catch (IOException e) {
e.printStackTrace();
}
}
return keyProps;
}

public void setKeyProps(Properties keyProps) {
this.keyProps = keyProps;
System.out.println("In setKeyProps method ...value of keyProps is "
+ keyProps);
}

public String replaceSpace(String file) {
return file.replaceAll(" ", "_");
}

public String createVendorFolder(String vendorName) throws Exception {
File tempBaseDirectory = null;
this.classBaseDirectory = returnClassPath();
if (this.classBaseDirectory.exists()) {
File classFolder = new File(this.classBaseDirectory.getPath());
String vendor = replaceSpace(vendorName);
tempBaseDirectory = new File(classFolder, vendor);
if (!tempBaseDirectory.exists()) {
tempBaseDirectory.mkdir();
// allowGroupAccessToFolder(tempBaseDirectory.getName());
} else {
System.out.println("tempBaseDirectory already created");
}
} else {
System.out.println("classBaseDirectory does not exist.");
}
return tempBaseDirectory.getAbsolutePath();
}
}



this code is working fine with jboss4.2.3 and tomcat 6

But it's not working in jboss 5.1.0


here is my keys.properties
keystore.password=
keystore.key.alias=
keystore.filename=replace_with_real_private_key.p12


her is my web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Some dummy name</servlet-name>
<servlet-class>WebTest</servlet-class>

</servlet>

<servlet-mapping>
<servlet-name>Some dummy name</servlet-name>
<url-pattern>/start-web-test</url-pattern>
</servlet-mapping>

</web-app>

it can now be easily set up in any local.
help wud be nice ...thanks in advance
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So are you saying that the property file is present at this location
C:/jboss-5.1.0.GA/jboss-5.1.0.GA/server/default/deploy/estw.war/WEB-INF/classes/keys.properties

and Spring is still not picking it up?
 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes the spring is not able to pick it up....It's working for tomcat 6 and jboss 4.2.3 ...but not for jboss 5.1.0...basically i am doing url deployment i.e editing profile .xml and giving a url to the deploy artifact..
spring documentation says that classpathresourse doesn't work if element you are trying to search exists in jar or war...but i am not giving any war file to jboss..i am doing url deployment..that means it should work because it is in exploded form....Also it should not work for jboss4.2.3 but it is working there....I am doing url deployment in case of jboss 4.2.3 also...any suggestions...Thanks in advance
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems like Jboss 5 has a problem --> http://forum.springsource.org/showthread.php?76234-Jboss-5-vfsfile-protocol-problem.

cannot be resolved to absolute file path because it does not reside in the file system Jboss is what I searched for in google.
 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok...he has this problem because classpathresource doesn't work with jar files i.e if you are searching the file in a jar or war file using classpathresource of spring it cannot be found...spring documentation says that...but if you do exploded deployment it should be able to find it right...the reason I say it because in case of jboss 4.2.3 it's working in exploded war....do you have ant idea how can i do exploded deployment using jboss 5.1.0 ..of course one way would be through admin console of jboss ...but any other way....like editing an xml in jboss....any idea?
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic