I have a very annoying problem with Glassfish and PostgreSQL. I have an EAR which contains a WAR and several other EJBs. I am using PostgreSQL. The annoying thing is that sometimes (this sometimes is the most disturbing thing because I have no clue what could go wrong) I get a ClassNotFoundException: java.lang.ClassNotFoundException: org.postgresql.core.Parser
Sometimes (!!!), the problem is solved if I clean and build the whole EAR, sometimes I have to restart the Glassfish, too.
I sometimes get NoClassDefFoundError, too.
Could anybody tell me how to include, package or do anything with the JAR which contains the missing class?
Thank you,
Norbert
Where do you put the jar: directly inside the EAR? Or in the WAR inside the EAR? For JDBC drivers, I think the recommendation is to always put them in the container's shared area and never in an application. (When I used JBoss a couple of years ago, we always put JDBC drivers into server/lib and had trouble if they were included in EARs as well, especially if the versions got out of sync)
Related
I have been struggling for many hours on trying to deploy a simple HelloWorld webservice written in java on a windows 7 (later ill need on linux) pc.
Most of the examples I found (from general places, and others questetions on stackoverflow) didn't work or used deprecated versions of jersey and other librarys.
My goal, is to write a webservice in java, where coding it should be easy and so does deploying it. It doesn't need to suuport anything special regarding the amount of request running and performance (my requirements are minimum)
Frommy research, I have come to believe the use of jersey with embeded netty web service should anser what I was looking for (if someone knows better, I would also like to hear about it, tough it isn't my main problem in this questetion but might just be an alternative solution)
I have came across this eaxmple:
jersey2-jetty-example
It gives you a working project with the dependencies needed from maven to run jersey and jetty embedded server (which can be run as a standalone jar which is exactly the kind of easy deploy im looking for)
I cloned the example and got everything running. I had problems importing it to eclipse, so I used the following command on the example folder:
mvn -DoutputDirectory=./lib dependency:copy-dependencies
which will give you a copy of the lib folder of the deps from maven needed,
then I created a java project with this lib folder in the build path and same source code as the sample, and all worked good.
The problem occurs when I try to take this java project and export it as an runnable jar (with the source files included option !).
I can then use java -jar to run the service, but when I try to access it from the browser (same as used in when I run it from eclipse), it never works, im always getting error 404 for the same routes that worked a second ago when running from eclipse. I couldn't figure out whats the source of the problem or what eclipse does differently that makes it behave in a different fashion.
I have found the reason the jar didn't work while in eclipse it did work, it was because of a duplicate jar that I was importing the caused the problem. The jars I got from maven in the git sample had 2 duplicate jars called hamcrest-all and hamcrest-core. removing one of them from the project build path fixed the problem.
If someone can answer the other open ended questetion that I asked, which is if using jersey and jetty like this is the best solution for my requirments I will be happy to hear about it
The code below fails on the line: Class.forName("oracle.jdbc.driver.OracleDriver");
with the error:
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
The two printlns print: Wed_Jun_22_11:18:51_PDT_2005 false This makes me think the class exists and can be found. Also this exact same class works in an a non-servlet application.
I have rebooted everything multiple times and regenerated the application/servlet multiple times. All values have been hard coded to make it simple and short.
I'm using: Eclipse JavaEE 1.4.2 Tomcat 7 jdk1.7 Oracle 11g R2 Windows 7 64bit
I have already added the jar files in web-inf. but it is still giving the following error: java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver.
Any suggestions would be great.
It is a bit hard to tell what exactly going wrong without looking into your application and tomcat server. But there are a couple of hints for your issue.
NoClassDefFoundError always makes me think that there is class collision rather than missing jar file. Be ware of the difference between ClassNotFound and NoClassDefFoundError
tomcat loads class in a different way as what normal java app does. Normally, the class loaders in a stand along java app will follow delegate pattern, which means the child class loader will always delegate the class loading job to its parent class loader. But tomcat does not exactly follow this. So it will load(find source file, read byte code and create a instace of class Class) by itself.
So check your tomcat lib as well as all the web apps under the tomcat and see if there are multiple version of ojdbcXXX.jar
Go through C:\apache-tomcat-7.0.47\lib path(this path may be differ ->based on where you pasted the Tomcat server ) then past ojdbc14.jar if its not contain.
Then restart the server in eclipse then run your app on server
I'm trying to deploy an application to Tomcat 7 on a Windows server. I have a local copy set up and have tested with Eclipse without any trouble, but on the production server I get IncompatibleClassChangeError messages.
This had been a problem on the local server when there were problems with the classpath, but I configured the correct classpath in the server properties inside Eclipse and everything ran fine.
I'm new to Tomcat and from what I understand it should be reading jar files from my my WEB_INFO/classes directory, but when my jars are there the app doesn't want to load at all. When I move them to the $CATALINA_HOME/lib (I realize that's not where they should go) the app loads fine but reports the IncompatibleClassChangeError.
Why aren't my jars being read from WEB-INF/classes? Is there some configuration I should look at to fix this?
Webapp-specific JAR files should go in Webapp/WEB-INF/lib, not in Webapp/WEB-INF/classes. The Tomcat/lib should only be used for appserver specific libraries and optionally also JAR files which should be shared among the deployed webapplications.
There might be more into the IncompatibleClassChangeError, this can have an entirely different cause. But first try getting the JAR's in the right place. If in vain, then please update your question to include the detail message. This at least smells that you're putting JAR files of a different appserver make/version in the classpath.
I have been working on a demo project all day and everything went just fine.
Suddenly (and, as it seems, unrelated to any of my actions) my application fails with a NoClassDefFoundError somewhere in the CDI internals. Strangely it worked before but I just cannot get it to work again.
I am using a rather fresh NB 6.9.1 install without any modules. I launched my Java Web application simply by clean+build and then run menu items.
The non-default setup is this:
I added two JARs from the Jersey project to the Library folder of my project:
jersey-bundle-1.5-SNAPSHOT.jar
jersey-view-client-1.5-SNAPSHOT.jar
I removed the restlib libraries added by Glassfish.
I set class loader delegate to false in sun-web.xml:
as described by the Jersey docs.
That all worked fine up to a sudden point.
Can anyone provide a clue where I could at least start investigating?
The same thing (everything works until NoClassDefFoundError emerges) happened to me once in a while on other projects as well.
The solution is to remove .netbeans/6.9/var/cache and restart NetBeans. I suspect that the culprit is corrupted index for NetBeans' custom classloader.
Took me some time, but here is the best way I see to solve the problem: http://www.nordsc.com/blog/?p=574
I just upgraded to eclipse galileo from ganymede sr2 and now eclipse is doing a really bad job of building my EAR file during deployment. There are several utility jars that are supposed to be included that it is completely ignoring, and there is a single war file that it only includes in the EAR occasionally. Thus, when I deploy to glassfish I get errors like "File not found: blah.war" or if the war file is present, I get ClassNotFound errors.
Also, I'm trying to remove some EJB jars from the EAR but it still adds some of them back into the application.xml (it doesn't put them into the EAR as well, unfortunately).
I think eclipse is storing some extra metadata about the project somewhere outside of the EAR project and ignoring my changes to it, which is annoying. However, I don't know where this is or how to "flush" it away.
Has anyone run into something like this? Any idea how I could figure out what is really going on?
Thanks!
I have the same issue when redeploying, hopefully someone can shed some light on this, otherwise I'm going back to Ganymede...only way around it for me is to always delete the deployed EAR first then things are fine after that when I do a deploy...kind of stupid IMO.
Also getting bad memory leaks with galileo...system slows to a crawl after a few hours of usage, and lot more crashes vs Ganymede...sigh serves me right for jumping to a new version!
Looks like you can read more about this in BugZilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=283184
I think they'll have a fix in the next release of WTP.