How can I add new webresource to a servlet

I had some problems of add my css and js file to the volicity,this is my code:
the vm file:

the xml file:

the java code:

public class Login extends HttpServlet {
	private static final Logger log = LoggerFactory.getLogger(Login.class);
	private TemplateRenderer templateRenderer;
	private ProjectService projectService;
	private PageBuilderService pageBuilderService;
	private WebResourceManager webResourceManager;

	public Login(ProjectService projectService, TemplateRenderer templateRenderer,
			PageBuilderService pageBuilderService,WebResourceManager webResourceManager) {
		this.projectService = projectService;
		this.templateRenderer = templateRenderer;
		this.pageBuilderService = pageBuilderService;
		this.webResourceManager =webResourceManager;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("myClass=" + templateRenderer);
		System.out.println("projectService=" + projectService);
		// resp.setContentType("text/html");
		// resp.getWriter().write("<html><body>Hello World</body></html>");
		Map<String, Object> context = new HashMap<>();
		context.put("webResourceManager", webResourceManager);
		templateRenderer.render("templates/nubia-login/input.vm",context, resp.getWriter());

the result:

the webresource doesn’t seems to be loaded.Anyone can help me to solved the problem,Thanks a lot!
I learn the code form
Thank you!

Another way to load your webresource in your vm file is to use the following line:


instead of your $webResourceManager.requireResourceForContext("NubiaLogin").

com.jingao.NubiaLogin is your plugin key and NubiaLogin-resources is the key of your web-resource.


Thank you very much jeffrey.peeters!
But it still not work for my code.Do you have any example code or link?
Thanks a lot!

it might be that your plugin key is wrong. You can check to see what your plugin key is in your pom.xml file. This is done by adding groupId and the artifactId fields together. In my case it looks like this:


which would make tig.jira.extension.tigChecklistExtension as my plugin key

Thank you jeffrey.peeters!
This is my pom.xml file info,The key is correct:

Through the code webResourceManager.getRequiredResources() can get the Resource path


fianlly I use dynamic js code at the vm file to solve my problem,the code like:

and add the code at servlet like:
public void getLoginCss(Map<String, Object> context) {
Pattern pattern = Pattern.compile("<link.*NubiaLogin-resources");
Matcher matcher = pattern.matcher(webResourceManager.getRequiredResources());
String cssurl = null;
if (matcher.find()) {
cssurl =;
pattern = Pattern.compile(“href=.*css”);
matcher = pattern.matcher(cssurl);
if (matcher.find()) {
cssurl =;
System.out.println(“cssurl=” + cssurl);
context.put(“cssurl”, cssurl.replace(“href=”", “”));


I still do not know why used $webResourceManager.requireResource(“com.jingao.NubiaLogin:NubiaLogin-resources”) does not work.

Have someone a solution for this?
I’m unable to load a webresource when rendering a velocity template from a servlet.

Don’t use the WebResourceManager. Its deprecated, you should use the PageBuilderService instead. I don’t know why everyone here suggest to use the WebResourceManager…

Take a look here: