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 3318434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:42:19+00:00 2026-05-17T22:42:19+00:00

I have a project where I generate lots of code against many XSD. To

  • 0

I have a project where I generate lots of code against many XSD. To keep things separate each set of XSD are bundled together within a project. I have multiple project that will see XSD in resources and generate code against them.

My problem is when I try to access the XSD that are stored in the jar files I cannot get the code to access the XSD from a perticular jar. Instead it will access the first XSD that matches the criterion regardless of the jar.

Here is the code I use to list the ressources, All the jars have the same structure meaning the XSDs are always stored in the xsd folder at the root of the jar file. The code below lists the XSD in the folder.

URL dirURL = clazz.getClassLoader().getResource(path);
  System.out.println(dirURL.toURI());
  if (dirURL != null && dirURL.getProtocol().equals("file")) {
   /* A file path: easy enough */
   System.out.println(dirURL.toURI());
  return new File(dirURL.toURI()).list();
  }

  if (dirURL == null) {
   /* 
    * In case of a jar file, we can't actually find a directory.
    * Have to assume the same jar as clazz.
    */
   String me = clazz.getName().replace(".", "/") + ".class";
   dirURL = clazz.getClassLoader().getResource(me);
   System.out.println(dirURL.toURI());
   System.out.println(me);
  }

  if (dirURL.getProtocol().equals("jar")) {
   /* A JAR path */
   String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file
   System.out.println(jarPath);
   JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
   Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
   Set<String> result = new HashSet<String>(); //avoid duplicates in case it is a subdirectory
   String name = null;
   while (entries.hasMoreElements()) {
    name = entries.nextElement().getName();
    if (name.startsWith(path)) { //filter according to the path
     String entry = name.substring(path.length());
     int checkSubdir = entry.indexOf("/");
     if (checkSubdir >= 0) {
      // if it is a subdirectory, we just return the directory name
      entry = entry.substring(0, checkSubdir);
     }
     result.add(entry);
    }
   }
   return result.toArray(new String[result.size()]);
  • 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-05-17T22:42:20+00:00Added an answer on May 17, 2026 at 10:42 pm

    I usually make it a rule to add a resource directory into each JAR with resources that are unique to that JAR held under it. For example (in the Maven structure)

    module1/src/main/resources/module1/example.xsd
    module2/src/main/resources/module2/example.xsd
    

    The XSDs are then referenced using

    InputStream module1XSD= SomeClass.class.getResourceAsStream("/module1/example.xsd");
    InputStream module2XSD= SomeClass.class.getResourceAsStream("/module2/example.xsd");
    

    so long as the JARs for module1 and module2 have been placed on the classpath of the application containing SomeClass.

    Spring contexts would reference these as

    classpath:module1/example.xsd,
    classpath:module2/example.xsd
    

    This does mean that you’ll have to be able to move the location of XSDs in the JARs that you generate. Maybe even regenerating them through a build script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a solution with lots of projects. Each project is configured to generate
I have a project that uses log4cxx, boost, etc. libraries whose headers generate lots
I have a project which uses php's mt_rand() to generate different random integers but
I have an old EJB (2.1) project that uses xdoclet (1.2.3) to generate the
On a datawarehouse project with SSIS/SSAS, I have to generate my own time dimension
suppose i have a project with lots of todos, some unintentionally left there, some
I have a project where I need to generate a PDF file. Within this
I have a project which needs to generate PDF documents. I am using iTextSharp.
Because I have a big project I must generate the UML for this. Writing
I have a Silverlight project with lots of source files. Now I want to

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.