Reputation: 2387
I have the following code in my plugin's definition file:
def doWithWebDescriptor = { xml ->
// Implement additions to web.xml (optional), this event occurs before
xml.'welcome-file-list'[0] + {
'security-constraint'({
'web-resource-collection'({
'web-resource-name'('Java Melody Monitoring')
'url-pattern'('/monitoring')
})
'auth-constraint'({
'role-name'('melody')
})
})
'login-config'({
'auth-method'('BASIC')
'realm-name'('Restricted Area')
})
}
}
This adds "security-constraint" and "login-config" nodes to the web.xml file, however, I currently have it hard-coded to be added after the "welcome-file-list" node. What I can't figure out is how to simply tell it to add these nodes as the last nodes in the "web-app" root node.
Upvotes: 1
Views: 458
Reputation: 4657
While dmahapatro's answer will work, I believe that appendNode is the clearest way to go about it.
Something like this would work:
xml.appendNode {
'security-constraint'({
'web-resource-collection'({
'web-resource-name'('Java Melody Monitoring')
'url-pattern'('/monitoring')
})
'auth-constraint'({
'role-name'('melody')
})
})
'login-config'({
'auth-method'('BASIC')
'realm-name'('Restricted Area')
})
}
Upvotes: 0
Reputation: 50245
Grab children, append after last child.
xml.children()[-1] + {
'security-constraint'({
'web-resource-collection'({
'web-resource-name'('Java Melody Monitoring')
'url-pattern'('/monitoring')
})
'auth-constraint'({
'role-name'('melody')
})
})
'login-config'({
'auth-method'('BASIC')
'realm-name'('Restricted Area')
})
}
Upvotes: 3