Using external jars in GWT projects (server-side) - gwt

I am trying to use an external jar in a Google Web Toolkit project.
The jar is for use only on the server side. For reference it is the jbcrypt jar packaged as org.mindrot.jbcrypt.
I have included the jar in my project's build path, and eclipse finds it and resolves the BCrypt class in my project.
When I try to use the service that relies on this jar (a login service that extends RemoteServiceServlet), I get a com.google.gwt.user.server.rpc.UnexpectedException which is caused by a NoClassDefFoundError for org.mindrot.jbcrypt.BCrypt.
Does the development server need the jar to be somewhere else? What should I do? Thanks.

Turns out, it goes in project/war/WEB-INF/lib

Related

How to give external jar dependency in Jboss Server?

Hai i am developing a web application my project need to refer lib(jar) file from server, So I do not want to keep my jar file in project i need to refer the path of the jar files available in server by this i can reduce my .war file size. How can i make this reference in Jboss Server.
the first step you have to add your lib in jboss server like a module, have a look at :
http://www.mastertheboss.com/jboss-server/jboss-as-7/how-to-install-a-module-on-jboss-as-7
Next if you use Maven for dependencies, add provided to your lib dependency, in that way while packaging the .war maven will keep the jar in your lib and it will be provided by the server.
this can also be helpful : https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Development_Guide/Add_an_Explicit_Module_Dependency_to_a_Deployment1.html
Have a look at the class loading documentation. That should give you the information you need.

Running servlet within Eclipse requires libs to be defined 3 times - am I doing something wrong?

Hullo - issue is this:
I wrote a servlet in Eclipse which requires mysql-connector-java-5.1.22-bin.jar
To compile I need to add the jar via the project's "Java Build Path"
To deploy I need to add the jar to the project's "Deployment Assembly"
To run the servlet within eclipse I need to add the jar to the servlet's Run Configuration -> Classpath
It's not the end of the world re-re-repeating myself like this, but it does seem odd.
Given that Eclipse gets a lot of other stuff correct I'm guessing / hoping that maybe I'm overlooking some feature to avoid this silliness (I cannot imagine a scenario where you'd benefit from entering this in 3 different spots ... but maybe I'm being uncreative here ...).
Insights appreciated :-)
The only thing you need to do is to drop the jar in WebContent/WEB-INF/lib.
You are developing a Java Web project, so the traditional place to put the required libs (JAR files etc) is under /WEB-INF/lib. And you do it only once.
In Eclipse, when you create Dynamic Web Project the appropriate project structure is generated for you (this is a development structure). In this case you place your JAR files in ProjectName/WebContent/WEB-INF/lib folder. And this folder is *automatically included in the project's build path.
Considering the fact that it is a Java Web project (you said you use servlets) you have to deploy your web app to some Application Server, like GlassFish, JBoss, WebLogic, WebSphere etc, or more simple Web Container like Apache Tomcat. If you do this thru Eclipse, then again your web project is automatically deployed.
NB!
There may be some additional details related to using libraries.
For instance, when it comes to using database drivers (MySql, PostgreSQL, Oracle etc) Tomcat advises the following while configuring JNDI Datasource (quote):
Before you proceed, don't forget to copy the JDBC Driver's jar into
$CATALINA_HOME/lib
In your case (MySQL) see the example here: MySQL DBCP Example
Also see my answer related to Webapp configuration file organization convention.
Hope this will help you.
P.S. Here is a step-by-step example: How do I access MySQL from a web application?

GWT: Using External Jar

I am trying to figure out how to use external jar in GWT project.
I referred http://www.vogella.com/articles/GWTModules/article.html and it worked perfectly.
But the example explained using another project being included in the GWT project's build path instead of including the jar of that project.
I know this should not make a difference but when I created the jar of the external project (including sources) and used it in the client GWT gave me following error:
The import com.person cannot be resolved
What would be the problem?
For using external gwt library jar file in your gwt eclipse project you have to add that jar file in library tab from java build path:
If you want to use external jar and use that jar classes in your client side. you have to inherit module package entry in client gwt module.gwt.xml
Just example a. com.test.Module2.xml so you have do entry like
<inherits name='com.test.Module2'/>

java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool

I am tring to configure a dynamic web project using eclipse helos. I use tomcat 6. When I add the libraries to the WebContent/lib it works fine. But I want to a folder called lib in the project's root level(root/lib). When I put my library files to that folder it builds fine. Run fine to the login page. When I try to log in it gives
"java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool"
Please help me with this.
You're creating a web app and deploying it as a WAR file in a Java EE container. That means that your deployment must follow the WAR standards. Put your JARs in WEB-INF/lib. The container will find them there.
Tomcat 6 and 7 have changed things up so JDBC driver JARs need to go in the server /lib directory. The app server expects to find them with its class loader. Try putting the MySQL JDBC connector JAR in /lib and see if that helps.

Using external Jars on GWT server-side

Im new to GWT. Im using the eclipse plugin
and started tweaking google's 'hello, world!' project: greetServlet.
Im trying to build a webapp that will use XML (de)serializing.
I chose XStream library for the relative easiness.
my classpath includes the xstream.jar. I also manually copied the jar to the WEB-INF/lib folder
(Is this a mistake? is there a way in which eclipse will copy external jars by itself to the deployment folder?).
I added a single line to GreetingServiceImpl.greetServer
XStream xs = new XStream(); and this is where it fails.
It throws an exception on RPC call to greetServer.
Why? What's the matter?
Is this specific to XStream or am I mising some thing in adding an external jar?
If you are running in the development mode in eclipse, it could be that XStream is not supported by the Google Appengine whitelist.
http://code.google.com/intl/es-AR/appengine/docs/java/jrewhitelist.html
If this is your problem, you can run your application in a Tomcat.