Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:49:42+00:00 2026-06-12T03:49:42+00:00

Does anyone know if it is possible to get templates from different paths with

  • 0

Does anyone know if it is possible to get templates from different paths with velocity? After initialization Velocity refuses to change the “file.resource.loader.path”.

This is my code:

public Generator(){         
    Properties p = new Properties();
        p.setProperty("resource.loader", "file");
        p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
        p.setProperty("file.resource.loader.path", "");

    Velocity.init(p);
}

The templates can be located in different locations ( the user can select one with a file dialog ). So I have this code upon fetching the template out of velocity

private Template fetch (String templatePath) {
    out_println("Initializing Velocity core...");
    int end = templatePath.lastIndexOf(File.separator); 

    Properties p = new Properties();
        p.setProperty("file.resource.loader.path", templatePath.substring(0, end));
    Velocity.init(p);

    return Velocity.getTemplate(templatePath.substring(end+1));
}

This is not working. It seems that once Velocity is initialized it can’t be reset with different properties. Any suggestions on how to solve this problem?

Possible Program flow:

  1. User selects group that needs to be filled into the template
  2. User selects a template to use (can be located anywhere on the hdd)
  3. User presses generate
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:49:43+00:00Added an answer on June 12, 2026 at 3:49 am

    Velocity can be used in two ways: the singleton model or the separate instance model. You are currently using the singleton model in which only one instance of the Velocity engine in the JVM is allowed.

    Instead, you should use the separate instance model which allows you to create multiple instances of Velocity in the same JVM in order to support different template directories.

    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "path/to/templates");
    ve.init();
    Template t = ve.getTemplate("foo.vm");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if it's possible to get variables from the AndroidManifest.xml for ant
does anyone know how to (if possible) get the owner of the tag on
Does anyone know if it's possible to get the full processor name (as shown
Does anyone know why is it not possible to get the virtualpath when you
Does anyone know whether it is possible to refer to another section from the
Does anyone know if its possible to get the Static Maps (image maps) for
Does anyone know if its possible to get a list of place recommendations and
Does anyone know if it is possible to get the total number of lines
Does anyone know if it is possible to get the cpu usage for a
Does anyone know how/if it's possible to get AMD APP Profiler working on C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.