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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:46:49+00:00 2026-05-20T11:46:49+00:00

I have a maven library project with some classes to deal xml messages. Whenever

  • 0

I have a maven library project with some classes to deal xml messages. Whenever I receive one of those messages I validate it using an xml schema file I have written. The code that does the validation for me looks like this:

public static Document parseXML(final String xml) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
    builder.setFeature("http://apache.org/xml/features/validation/schema", true);
    URL location = CMPMessage.getClass().getResource(XML_SCHEMA_LOCATION);
    if (null == location) {
        throw new IOException("Unable to load schema definition file.");
    }
    builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
            "http://www.mycompany.de/MyProtocol " + location);
    return builder.build(new StringReader(xml));
}

and XML_SCHEMA_LOCATION is like this:

private static final String XML_SCHEMA_LOCATION = "/ConvertMessageProtocol.xsd";

The .xsd file is in src/main/resources and, thanks to maven, everything works perfect: The .xsd file gets included in the .jar when tell maven to make a package.
I made a simple test project to check whether the .xsd file will actually be found. The source looks like this:

import java.io.IOException;
import org.jdom.JDOMException;
import de.mycomp.MyMessage;


public class Main {
    public static void main(final String[] args) {
        try {
            MyMessage.parseXML(args[0]);
        }
        catch (JDOMException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

And yes, the xml will be validated using the schema file.

Now here it comes: I want to use my little library in a servlet (running in tomcat), but there, the .xsd file can not be found 🙁

Of course, I could store the .xsd file somewhere else like directly on the companys server and retrieve it via http, but I think including it in the .jar is the better solution to make sure that the libs and the schemas version fit.

Do you have any ideas what is wrong here?

Thanks in advance:

Jim

  • 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-20T11:46:49+00:00Added an answer on May 20, 2026 at 11:46 am

    assign

    private static final String XML_SCHEMA_LOCATION = getPath("/ConvertMessageProtocol.xsd");
    
    public static String getPath(String path){
      return UtilityClass.class.getResource(path).toString();
    }
    

    The problem is your servlet app is looking for file at / where there is no file.

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

Sidebar

Related Questions

I have a small command line utility project that I'm using Maven to manage.
I have a Maven project that uses the jaxb2-maven-plugin to compile some xsd files.
I have a maven POM file for a web service. For one of the
I have a maven project with the following packages (for illustration only): Root: src/main/java
I have a multi-module maven project with an installer sub-project. The installer will be
I have a simple application using netbeans for developing and maven for building et
Is it possible to have a different set of dependencies in a maven pom.xml
Suppose I have the following directory layout in a Maven project: src/ |-- main
I have a Java project in Netbeans. It runs fine with Maven. So I
I am converting a project to use Ant/maven-ant-tasks. I have a local repository 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.