Tomcat Web服务操作后,资源文件未显示更改

时间:2018-08-21 17:26:00

标签: web-services tomcat intellij-idea jaxb jersey

我有一些tomcat Web服务。在资源目录中,我有一个文件myresource.xml。我使用网络服务读取和写入该文件。

在为文件写入新内容之后,我可以立即读取它,这很好。但是资源目录中的文件myresource.xml不能反映该更改。如果我从IDEA重新启动Web服务,则更改仍然可用,但是例如当我重新启动计算机时,更改就消失了。

myresource.xml包含Entity对象的列表,该列表为Entities。要写入文件,我首先将其解组,在Entitiy中添加一个新的Entities对象,然后将其编组。

代码如下:

 public static Entities unmarshalEntities() throws JAXBException, IOException {
        URL dataUrl = XmlUtils.class.getResource("/myresource.xml");
        InputStream inputStream = dataUrl.openStream();
        JAXBContext jaxbContext = JAXBContext.newInstance(Entities.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        Entities entities = (Entities) jaxbUnmarshaller.unmarshal(inputStream);
        inputStream.close();
        return entities;
    }



public static void marshalEntities(Entities entities) throws IOException, JAXBException, URISyntaxException {
        JAXBContext jaxbContext = JAXBContext.newInstance(Entities.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        URL url = XmlUtils.class.getResource("/myresource.xml");
        File file = new File(url.toURI());
        OutputStream outputStream = new FileOutputStream(file);
        jaxbMarshaller.marshal(entities, outputStream);
        outputStream.flush();
        outputStream.close();
    }

我必须更改什么才能使更改保存到myresource.xml中?

0 个答案:

没有答案