I am trying to create a txt file under /conf but got this error:
Exception occurred: This tree does not exist
Here is the simplified version of my code - ignoring the file content:
Session session = resourceResolver.adaptTo(Session.class);
Node confNode = session.getNode("/conf");
Node fileNode = confNode.addNode("helloworld.txt", "nt:file");
session.save();
Am I missing anything? /conf path exists in CRXDE so I am not sure why it says the tree does not exist. I have also make sure the SystemUser.yaml has the write and read permission under /conf
Solved! Go to Solution.
Views
Replies
Total Likes
hi @aemUser2345 ,
There is no "/conf" node in the repository, so you cannot add a child node to it.
trying with this condition. then you can proceed with your code.
if (!session.nodeExists("/conf")) {
Node confRoot = session.getRootNode().addNode("conf");
session.save();
}
hi @aemUser2345 ,
There is no "/conf" node in the repository, so you cannot add a child node to it.
trying with this condition. then you can proceed with your code.
if (!session.nodeExists("/conf")) {
Node confRoot = session.getRootNode().addNode("conf");
session.save();
}
Hi @aemUser2345
Make sure you create jcr:content node as well
javax.jcr.nodetype.ConstraintViolationException: OakConstraint0025: /conf/helloworld.txt[[nt:file]]: Mandatory child node jcr:content not found in a new node
Hi @aemUser2345 ,
You need to add jcr:content also as suggest by @arunpatidar .
Update the code as below
Session session = resourceResolver.adaptTo(Session.class);
Node confNode = session.getNode("/conf");
Node fileNode = confNode.addNode("helloworld.txt", "nt:file");
Node jcrContent = fileNode.addNode("jcr:content", "nt:unstructured");
session.save();
Regards
Shiv
Views
Likes
Replies