Search code examples
liferay-6webjars

How do I use webjars in a Liferay portlet


I have been trying to include shufflejs in a Liferay (6.2) portlet.

  1. I have added the following dependency to my pom.xml file:

    <dependency>
      <groupId>org.webjars.bower</groupId>
      <artifactId>shufflejs</artifactId>
      <version>4.0.0</version>
      <scope>compile</scope>
    </dependency>
    
  2. I have confirmed that on my tomcat server, the webapps/my-portlet/WEB-INF/lib/shufflejs-4.0.0.jar is present and contains, within it, the META-INF/resources/webjars/shufflejs/4.0.0/dist/shuffle.js
  3. I have included the following line in my liferay-portlet.xml file:

    <header-portlet-javascript>
      /webjars/shufflejs/4.0.0/dist/shuffle.js
    </header-portlet-javascript>
    
  4. When I load my portlet's page with my browser, I get everything except I get a '404 Not Found' error for http://localhost:20080/my-portlet/webjars/shufflejs/4.0.0/dist/shuffle.js?browserId=other&minifierType=js&languageId=en_US&b=6210&t=1465296591338

What am I missing?

Thank you


Solution

  • I found the cause of my troubles. I have deployed my portlet and run the portal in Eclipse with JRebel. When I deploy/run my portlet standalone without JRebel, this resource is found. Moreover, I am able to then bring the portal down and then bring it back up in Eclipse/JRebel - now the resource can be found.

    I have encountered similar problems when running with Eclipse/JRebel before (see Liferay: perform an action when a -LocalServiceUtil is available). All in all Eclipse/JRebel is great, but sometimes a little wonkiness occurs when deploying portlets.