Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use 3rd party libraries in glassfish?

I need to connect to a MongoDB instance from my EJB3 application, running on glassfish 3.0.1. The Mongo project provides a set of drivers, and I'm able to use them in a standalone Java application.

How would I use them in a Java EE application? Or maybe better phrasing: how would I make a 3rd party library available to my application when it runs in an EJB container?

At the moment, I'm getting a java.lang.NoClassDefFoundError when deploying a bean that tries to import from the library:

[#|2010-03-24T11:42:15.164+0100|SEVERE|glassfishv3.0|global|_ThreadID=28;_ThreadName=Thread-1;|Class [ com/mongodb/DBObject ] not found. Error while loading [ class mvs.core.LocationCacheService ]|#]
[#|2010-03-24T11:42:15.164+0100|WARNING|glassfishv3.0|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|Error in annotation processing: java.lang.NoClassDefFoundError: com/mongodb/DBObject|#]

[#|2010-03-24T11:42:15.259+0100|SEVERE|glassfishv3.0|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=28;_ThreadName=Thread-1;|Exception while loading the app
org.glassfish.deployment.common.DeploymentException: java.lang.NoClassDefFoundError: com/mongodb/DBObject
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:171)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:125)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:224)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338)

I tried adding it to the NetBeans project (Properties -> Libraries -> Compile -> Add Jar, enable 'Package'), and I also tried manually copying the jar file to $GF_HOME/glassfish/domains/domain1/lib (where the mysql-connector already resides).

Do I need to 'register' the library with the container? Reference it via Annotation? Extend the classpath of the container to include the library?

like image 392
Hank Avatar asked Mar 24 '10 11:03

Hank


People also ask

How do you add a GlassFish library?

Right click on your project and select "Java Build Path" then go to Libraries tab and click on the button "Add library". Select server runtime and if you have add a glassfish server on your IDE, you can select it.

Is GlassFish free for commercial use?

GlassFish is free software and was initially dual-licensed under two free software licences: the Common Development and Distribution License (CDDL) and the GNU General Public License (GPL) with the Classpath exception.

What is payara GlassFish?

Payara Server is an open-source application server derived from GlassFish Server Open Source Edition. It was created in 2014 by C2B2 Consulting as a drop in replacement for GlassFish after Oracle announced it was discontinuing commercial support for GlassFish.

What JDK does GlassFish support?

Required JDK Version Installation of Oracle GlassFish Server 3.0. 1 requires JDK release 6. The minimum (and certified) version of the JDK software that is required for GlassFish Server depends on the operating system: For all supported operating systems using the Java JDK, the minimum required version is 1.6.


1 Answers

  1. Go to your Glassfish doamin directory.

  2. Then go to lib folder.

  3. Place the libraries there.

  4. Restart the glassfish and run.

(Ex) C:\glassfish3\glassfish\domains\domain1\lib

like image 148
Sangeeth Avatar answered Sep 28 '22 17:09

Sangeeth