aspose file tools*
The moose likes Struts and the fly likes Struts Plugins Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Plugins" Watch "Struts Plugins" New topic
Author

Struts Plugins

Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Posts: 22
I am trying to create a plugin in struts 1.3 (I am a newbie to struts) but am getting following error

------>The Plugin is starting<---------
java.io.FileNotFoundException: .\WebContent\WEB-INF\props.txt (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at ch04.WroxPlugin.init(WroxPlugin.java:29)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:871)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:359)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3099)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:404)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1309)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Thread.java:619)
Jun 16, 2009 6:44:31 PM org.apache.catalina.loader.WebappClassLoader modified
INFO: Additional JARs have been added
------>Plugin Stopped<---------

here is my code

<CODE>
package ch04;

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

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

public class WroxPlugin implements PlugIn {

public static final String PROPERTIES = "PROPERTIES";

public void init(ActionServlet servlet, ModuleConfig config)
throws ServletException {

System.err.println("------>The Plugin is starting<---------");
Properties properties = new Properties();

try {
File file = new File("./WebContent/WEB-INF/props.txt");

FileInputStream fis = new FileInputStream(file);

properties.load(fis);

ServletContext context = servlet.getServletContext();
context.setAttribute(PROPERTIES, properties);
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
throw new ServletException(ioe.getMessage());
}
}

public void destroy(){
System.err.println("------>Plugin Stopped<---------");
}
}

</CODE>

my file is situated at Webcontent/Web-Inf/props.txt

Any help will be hugely appreciated


Regards,
Ashish Nandan
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags.Those are different directories. That aside, if you're attempting to access a file relative to the application context you need to get the real path and build your filename from that.
 
 
subject: Struts Plugins