4

I am using JAXB to convert between classes and XML and save and read to an XML document. I am working in Eclipse Oxygen.1a Release (4.7.1a) and I have included the jaxb-api-2.3.0.jar file to the project from here: https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api/2.3.0 It looks like my implementation of the JAXB-API in Eclipse has not been done correctly. I am not sure how to do that. I just included the jar file hoping it will work.

Now my code throws an expectation Implementation of JAXB-API has not been found on module path or classpath.

/**
 * Saves the current person data to the specified file.
 * 
 * @param file
 */
public void savePersonDataToFile(File file) {
    try {
        JAXBContext context = JAXBContext
                .newInstance(PersonListWrapper.class);
        Marshaller m = (Marshaller) context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        // Wrapping our person data.
        PersonListWrapper wrapper = new PersonListWrapper();
        wrapper.setPersons(personData);

        // Marshalling and saving XML to the file.
        ((Marshaller) m).marshal(wrapper, file);

        // Save the file path to the registry.
        setPersonFilePath(file);
    } catch (Exception e) { // catches ANY exception
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error");
        alert.setHeaderText("Could not save data");
        //alert.setContentText("Could not save data to file:\n" + file.getPath());
        alert.setContentText(e.getMessage());

        alert.showAndWait();
    }
}

I must be missing configurations.

0 Answers0