Turns out that that the WebappResourceLoader does not fix the problem.

When you deploy an application to Android, you must run all the .class files through the dalvik converter. This changes the java bytecodes from stack-based to register based and puts them in a flat file. In turn, it also strips out any non-class files, such as textual config files. Velocity looks for a default velocity.properties file within it's jar, which does not exist.

Is there any way to force Velocity to look at a different default velocity.properties? I have attempted this below, but failed. Any help is appreciated!
Thanks,
Jim

====
Properties p = new Properties();
       InputStream iStream = null;
       try {
       iStream = new FileInputStream(context
           .getRealPath(Configuration.VELOCITY_PROPERTIES_FOLDER)
           + "/velocity.properties");
       } catch (FileNotFoundException e2) {
       Log.debug("Error loading velocity properties file: "
           + context.getRealPath(Configuration.VELOCITY_PROPERTIES_FOLDER)
           + "/velocity.properties");
       success = false;
       e2.printStackTrace();
       }

       try {
       p.load(iStream);
       } catch (IOException e1) {
       Log.debug("Error loading velocity.properties");
       e1.printStackTrace();
       }
p.setProperty(Velocity.RESOURCE_LOADER, "webapp");
       p.setProperty("webapp.resource.loader.class",
           "org.apache.velocity.tools.view.WebappResourceLoader");
p.setProperty("webapp.resource.loader.path", Configuration.VIEWS_LOC); Velocity.setApplicationAttribute("javax.servlet.ServletContext", context);

Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, "ConciergeVelocityLogger"); try {
       Velocity.init(p);
       } catch (Exception e) {
       Log.debug("Error initializing Velocity: " + e.getMessage());
       e.printStackTrace();
       success = false;
       }
====
yields

====
D/Jetty   (  710): Error initializing Velocity: null
W/System.err(  710): java.lang.NullPointerException
W/System.err(  710):    at java.io.Reader.<init>(Reader.java:72)
W/System.err( 710): at java.io.InputStreamReader.<init>(InputStreamReader.java:96) W/System.err( 710): at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543) W/System.err( 710): at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519) W/System.err( 710): at org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:397) W/System.err( 710): at org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:570) W/System.err( 710): at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:249) W/System.err( 710): at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589) W/System.err( 710): at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229) W/System.err( 710): at org.apache.velocity.app.Velocity.init(Velocity.java:107) W/System.err( 710): at org.concierge.lib.Configurator.initialize(Configurator.java:64) W/System.err( 710): at org.concierge.lib.DispatchServlet.doGet(DispatchServlet.java:25) W/System.err( 710): at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) W/System.err( 710): at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) W/System.err( 710): at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502) W/System.err( 710): at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:389) W/System.err( 710): at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) W/System.err( 710): at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) W/System.err( 710): at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) W/System.err( 710): at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417) W/System.err( 710): at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) W/System.err( 710): at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) W/System.err( 710): at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
W/System.err(  710):    at org.mortbay.jetty.Server.handle(Server.java:320)
W/System.err( 710): at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535) W/System.err( 710): at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:865) W/System.err( 710): at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539) W/System.err( 710): at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) W/System.err( 710): at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) W/System.err( 710): at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) W/System.err( 710): at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
====

Nathan Bubna wrote:
Have you tried using the WebappResourceLoader from the VelocityTools
project? The FileResourceLoader is difficult to use and not very
portable in webapp environments.  It also won't work at all in
unexploded WAR deployments.

On Mon, Jul 20, 2009 at 9:48 PM, Jim Cortez<j...@jimcortez.com> wrote:
Hello all,
  I am working on a small MVC framework that runs on top of iJetty (a Jetty
port fot the Android platform). I am having trouble during initialization of
Velocity. Take a peek at the following code:

====
Log.info("Setting Template Directory: "+Configuration.VIEWS_LOC);
File viewsFolder = new File(Configuration.VIEWS_LOC);
if(!viewsFolder.exists() || !viewsFolder.canRead()){
  success=false;
  Log.warn("Folder "+Configuration.VIEWS_LOC+" does not exist, or
unreachable!");
} else {
  Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,
Configuration.VIEWS_LOC);
  Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM,
"ConciergeVelocityLogger");
  try {
      Velocity.init();
  } catch (Exception e) {
      Log.warn("Error initializing Velocity: "+e.getMessage());
      e.printStackTrace();
      success = false;
  }
}
====

That code should show that the templates directory both exists and is
readable. Here is the output of the error log:

====
I/Jetty   (  709): Setting Template Directory:
/sdcard/jetty/webapps/concierge/WEB-INF/views
W/Jetty   (  709): Error initializing Velocity: null
W/System.err(  709): java.lang.NullPointerException
W/System.err(  709):    at java.io.Reader.<init>(Reader.java:72)
W/System.err(  709):    at
java.io.InputStreamReader.<init>(InputStreamReader.java:96)
W/System.err(  709):    at
org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543)
W/System.err(  709):    at
org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519)
W/System.err(  709):    at
org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:397)
W/System.err(  709):    at
org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:570)
W/System.err(  709):    at
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:249)
W/System.err(  709):    at
org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:114)
W/System.err(  709):    at
org.apache.velocity.app.Velocity.init(Velocity.java:79)
W/System.err(  709):    at
org.concierge.lib.Configurator.initialize(Configurator.java:34)
W/System.err(  709):    at
org.concierge.lib.DispatchServlet.doGet(DispatchServlet.java:25)
W/System.err(  709):    at
javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
W/System.err(  709):    at
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
W/System.err(  709):    at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
W/System.err(  709):    at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:389)
W/System.err(  709):    at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
W/System.err(  709):    at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
W/System.err(  709):    at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
W/System.err(  709):    at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
W/System.err(  709):    at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
W/System.err(  709):    at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
W/System.err(  709):    at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
W/System.err(  709):    at org.mortbay.jetty.Server.handle(Server.java:320)
W/System.err(  709):    at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
W/System.err(  709):    at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:865)
W/System.err(  709):    at
org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
W/System.err(  709):    at
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
W/System.err(  709):    at
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
W/System.err(  709):    at
org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
W/System.err(  709):    at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
====

I can only assume that there is a problem reading in the template directory.
The custom logger I created merely redirects the output to a stdout log.
Does anyone have any idea how to solve this little problem? I am using
Velocity 1.6.2, iJetty 2.1, and Android 1.5.

Thank you,
Jim Cortez

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org


Reply via email to