Announcement Announcement Module
Collapse
No announcement yet.
PatternMatchingResourcePatternResolver, and jar resources Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PatternMatchingResourcePatternResolver, and jar resources

    Hello,

    I was merrily using ClassPathResource, until a fellow developer who uses the jar that my code ends up as alerted me to the fact that it doesn't read from jars. So, I switched over to PatternMatchingResourcePatternResolver. My code is:

    PathMatchingResourcePatternResolver res = new PathMatchingResourcePatternResolver();
    Resource cpr = res.getResource("classpath*:cnwk/deploy/dao/ibatisSQLMapsConfig.xml");
    SqlMapClient smc = SqlMapClientBuilder.buildSqlMapClient(new FileReader(cpr.getFile()));

    Unfortunately, the res.getResource fails (I had it reading fine when my classpatch pointed to the classes directory that the xml files end up in, but not when the jar provided the classpath). I've tried a variety of different formats:

    classpath*:cnwk/deploy/dao/ibatisSQLMapsConfig.xml
    classpath:cnwk/deploy/dao/ibatisSQLMapsConfig.xml
    classpath*:/cnwk/deploy/dao/ibatisSQLMapsConfig.xml
    classpath:/cnwk/deploy/dao/ibatisSQLMapsConfig.xml
    cnwk/deploy/dao/ibatisSQLMapsConfig.xml
    /cnwk/deploy/dao/ibatisSQLMapsConfig.xml

    None work.

    jar -tvf includes:

    884 Thu Oct 13 17:25:28 PDT 2005 cnwk/deploy/dao/ibatisSQLMapsConfig.xml

    I have even had some exceptions that found the jar:

    java.io.FileNotFoundException: class path resource [cnwk/deploy/dao/ibatisSQLMapsConfig.xml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/firminr/projects/cnwkdeploy/dist/cnwk-deploy-2.3.2.jar!/cnwk/deploy/dao/ibatisSQLMapsConfig.xml

    So, what am I missing? Did I just ignore a huge swathe of the docs?

    Thanks

  • #2
    Fixed. Sometimes typing it out is as good as a 2nd brain.

    PathMatchingResourcePatternResolver res = new PathMatchingResourcePatternResolver();
    Resource cpr = res.getResource("classpath:cnwk/deploy/dao/ibatisSQLMapsConfig.xml");
    SqlMapClient smc = SqlMapClientBuilder.buildSqlMapClient(new InputStreamReader(cpr.getInputStream()));

    Comment


    • #3
      Hi. I have the same problem. I get the same error when I run the jar file, although in eclipse is working fine. How to solve it? I am using the ClassPathXMLApplicationContent.

      public Main() {
      new ClassPathXmlApplicationContext(new String[] { "classpath:*/document.xml" });

      }

      Comment

      Working...
      X