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

  • SEARCH
  • Home
  • 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 9205473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:57:29+00:00 2026-06-17T23:57:29+00:00

I have a case where I am loading a string template group from a

  • 0

I have a case where I am loading a string template group from a file contained in a jar.
This works fine using the following mechanism:

final String urlName = new StringBuilder()
            .append("jar:file:").append(templateJar.getAbsolutePath()).append("!")
            .append(templateFileName).toString();
final URL url;
try {
        url = new URL(urlName);
} catch (MalformedURLException ex) {
        throw new GeneratorException("bad manifest url", ex);
}
final STGroup stg = new STGroupFile(url, "US-ASCII", '<', '>');

The difficulty comes in when the template file contains an

...
import "../../dataTypeMaps.stg"
...

String template fails with the following:

can't load group file jar:file:/home/phreed/.m2/repository/edu/vanderbilt/isis/druid/druid-template/2.0.0/druid-template-2.0.0.jar!/template/src/main/java/sponsor/orm/ContractCreator.stg
Caused by: java.lang.IllegalArgumentException: No such group file: ../../dataTypeMaps.stg
    at org.stringtemplate.v4.STGroupFile.<init>(STGroupFile.java:69)
    at org.stringtemplate.v4.STGroup.importTemplates(STGroup.java:570)
    at org.stringtemplate.v4.compiler.GroupParser.group(GroupParser.java:199)
    at org.stringtemplate.v4.STGroup.loadGroupFile(STGroup.java:619)
    at org.stringtemplate.v4.STGroupFile.load(STGroupFile.java:139)
    at org.stringtemplate.v4.STGroupFile.load(STGroupFile.java:128)
    at org.stringtemplate.v4.STGroup.lookupTemplate(STGroup.java:237)
    at org.stringtemplate.v4.STGroup.getInstanceOf(STGroup.java:172)
    at edu.vanderbilt.isis.druid.generator.Generator.build(Generator.java:215)
    at edu.vanderbilt.isis.druid.generator.DruidMojo.execute(DruidMojo.java:193)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

Is it possible to set things up with the jar so that the import will work?
The above approach works fine when there is no jar involved.

  • 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-17T23:57:30+00:00Added an answer on June 17, 2026 at 11:57 pm

    The simple answer is that the path to the imported file is wrong

    ...
    import "dataTypeMaps.stg"
    ...
    

    The import will cause the file to be looked for starting at the root of the jar.
    The above import would amount to the file being placed at…

    final String urlName = new StringBuilder()
            .append("jar:file:").append(templateJar.getAbsolutePath()).append("!")
            .append("dataTypeMaps.stg").toString();
    

    Why the behavior is different than when the template group file is on the native file system I do not know.
    In order to get this to work I changed the classpath to include the jar file.
    As this was done in the context of a Maven plugin, the plugin needs to change the classpath dynamically. This was done with the following code…

     public void setTemplateJarName(String templateJarName) throws GeneratorException {
        this.templateJarName = templateJarName;
        final Thread ct = Thread.currentThread();
        final ClassLoader pcl = ct.getContextClassLoader();
        URL[] nurl;
        try {
            nurl = new URL[]{ new URL("file://"+templateJarName) };
        } catch (MalformedURLException ex) {
            throw new GeneratorException("could not load template jar", ex);
        }
        final URLClassLoader ucl = new URLClassLoader(nurl, pcl);
        ct.setContextClassLoader(ucl);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200
I have a case where I need to load bitmap from a resource dll
I have the following recursive function: fun tester (f:'a -> 'b, tl:(string * 'a
I Have a Silverlight WPF app that shows tabs of data in this case
I have a simple text file containing some CSV with the following structure: @Parent1_Field1,
I have an odd case where adding a record is causing unwanted loading of
I have the following object model: class ObjectA{ public string Description {get;set;} } class
I have an ANSI 835 (text) file. For simplicity's sake it looks like this:
This is a question that extends from the originally posted here: Link to loading-xaml
Test case below. Output: custom loading of: pkg.TestRun ran. wish this would run in

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.