Search code examples
websphere-libertyibm-wdt

Why aren't all resources being published using WebSphere Liberty Tools for Eclipse?


I'm experiencing an issue with running a WebSphere Liberty server from within Eclipse. I'm using Eclipse 2019-09 R (4.13.0), WAS Liberty with Java EE 8 Web Profile (V19.0.0.11), and WebSphere Liberty Server Liberty Tools Eclipse plugin (19.0.900.v20190912_1541). I'm intending to run a Maven web project on the above Liberty server, to no avail.

I downloaded the Liberty runtime to a directory and configured a server within Eclipse to use this runtime. I then added the web project as a resource to the server. The server seems to start up fine, however, when trying to access a resource, I see several java.lang.NoClassDefFoundError exceptions. When using the WebSphere Liberty Server Liberty Tools plugin, instead of publishing the WAR file to the Liberty server, it simply publishes an XML file pointing to the resources and the dependencies that would make up the WAR file. The XML is in the usr/servers/<server_name>/apps directory and has a name like app-name.war.xml. The contents of the XML file are pretty sparse:

<?xml version="1.0" encoding="UTF-8"?>
<archive>
    <dir sourceOnDisk="/path/to/web/project/WebContent" targetInArchive="/"/>
    <dir sourceOnDisk="/path/to/web/project/target/classes" targetInArchive="/WEB-INF/classes"/>
    <dir sourceOnDisk="/path/to/web/project/target/test-classes" targetInArchive="/WEB-INF/classes"/>
</archive>

It seems pretty obvious looking at the above why the server is throwing exceptions because it can't find all any resources. Previous, older versions of Eclipse, the plugin, and Liberty were configured the same way, but the war.xml file contained a reference to all the dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<archive>
    <archive targetInArchive="/WEB-INF/lib/lib1.jar">
        <dir sourceOnDisk="/path/to/workspace/lib1/target/classes" targetInArchive="/"/>
    </archive>
    <archive targetInArchive="/WEB-INF/lib/lib2.jar">
        <dir sourceOnDisk="/path/to/workspace/lib2/target/classes" targetInArchive="/"/>
    </archive>
    ...
    <dir sourceOnDisk="/path/to/web/project/target/m2e-wtp/web-resources" targetInArchive="/"/>
    <dir sourceOnDisk="/path/to/web/project/src/main/webapp" targetInArchive="/"/>
    <dir sourceOnDisk="/path/to/web/project/target/classes" targetInArchive="/WEB-INF/classes"/>
    <dir sourceOnDisk="/path/to/web/project/src/main/resources" targetInArchive="/WEB-INF/classes"/>
    <file sourceOnDisk="~/.m2/repository/some-lib1.jar" targetInArchive="/WEB-INF/lib/some-lib1.jar"/>
    <file sourceOnDisk="~/.m2/repository/some-lib2.jar" targetInArchive="/WEB-INF/lib/some-lib2.jar"/>
    ...
</archive>

Does anyone have any idea as to why in this newer version of Liberty and the Liberty Tools plugin I'm not getting all the dependencies published? Thanks for your help.


Solution

  • How did you import your project into Eclipse? I created a simple Maven war project and imported it into Eclipse using the Existing Maven Projects import wizard. I then ran it on a server that I had created and it included the dependency jar that was needed:

    <?xml version="1.0" encoding="UTF-8"?>
    <archive>
        <dir sourceOnDisk="C:\home\work\maven\ServletJsonSample\target\m2e-wtp\web-resources" targetInArchive="/"/>
        <dir sourceOnDisk="C:\home\work\maven\ServletJsonSample\src\main\webapp" targetInArchive="/"/>
        <dir sourceOnDisk="C:\home\work\maven\ServletJsonSample\target\classes" targetInArchive="/WEB-INF/classes"/>
        <file sourceOnDisk="C:\Users\xxx\.m2\repository\org\json\json\20190722\json-20190722.jar" targetInArchive="/WEB-INF/lib/json-20190722.jar"/>
    </archive>
    

    You can also try disabling loose applications by double clicking on the server in the servers view to open the server editor, uncheck Run applications directly from the workspace, and save your changes. Or you may have it enabled in your pom.xml, in which case remove the line: <looseApplication>true</looseApplication>.