Reputation: 1598
It seems simple but ...
I'm just starting to learn liberty profile.
I can't use shared library.
here's documentation: https://www.ibm.com/support/knowledgecenter/SSD28V_liberty/com.ibm.websphere.wlp.core.doc/ae/cwlp_sharedlibrary.html
so in server.xml I put (and restart server), for example:
<library>
<folder dir="C:/libs/gson/"></folder>
<!-- or even <file name="C:/libs/gson/gson-2.3.1.jar" /> -->
</library>
Anyway at runtime I receive: "java.lang.NoClassDefFoundError: com/google/gson/Gson"
On a servlet I just have the import and a simple use:
...
import com.google.gson.Gson;
...
@WebServlet("/")
public class HelloWorld extends HttpServlet {
...
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Serialization
Gson gson = new Gson();
...
What I'm missing?
Upvotes: 3
Views: 2281
Reputation: 42926
The part you are missing is that the application needs to be configured to reference the library. There are a few ways to do this:
Then, simply change your library ID to global
like this:
<library id="global">
<classloader commonLibraryRef="..."/>
as described in @njr's answerUpvotes: 6
Reputation: 3484
Adding a library element to server configuration doesn't automatically make it available to applications. You need to configure the application to have access to the library, for example,
<application location="myapp.war">
<classloader commonLibraryRef="gsonLib"/>
</application>
<library id="gsonLib">
<file name="C:/libs/gson/gson-2.3.1.jar" />
</library>
Upvotes: 8