Problem - I have an issue with two jars in my web application which I am developing using Eclipse IDE of Mars version and hosting it on apache tomcat 7.0 web server -
hibernate-jpa-2.1-api-1.0.0.final
com.ibm.ws.webservices.thinclient_7.0.0
Both of them have same package structure and and same class -
javax.persistence.CascadeType
This package and class is a ENUM type declaration which was being used from first jar. And I have recently added the second jar which is also mandatory as a dependency for a third party jar for authentication and authorization for my application. Once the second jar is added, I have got this issue where the package intended to be used from first jar is being picked up from the second jar.
The Enumeration value CascadeType.DETACH was being used from first jar file in the application and this ENUM value is not defined in its counterpart in the second jar. Hence this issue is being faced.
Things I have already tried and no result -
Tried to remove the above conflicting package from the second jar and added to the library. Then this jar was not being picked up at run time and I was getting noclassdeffound error for the class - com.ibm.ws.webservices.multiprotocol.GeneratedService even after this class is visible inside the second jar itself in classpath.
Instead of CascadeType.DETACH, I tried to use some other ENUM value of the second jar itself and let the compiler ignore first jar. Then was getting the noclassdeffound error for the class - com.ibm.ws.webservices.multiprotocol.GeneratedService which is still inside the second jar.
Out of suggestions I got from stack overflow itself, traversed to Right click on project -> build path -> configure build path -> Order and export to set priority for jars. But at this option, only priority can be set within library sets like WEBAPP libraries, JDK libraries or externally configured libraries but not within individual jars inside a set of libraries. But my both libraries were inside WEBAPP libraries set itself and hence could not set the priority of those jars using this option. As another trial, I removed the second jar from the WEBAPP libraries and configured as an external library instead and set its priority lower than WEBAPP libraries which contained my first jar. Still was getting the same issue- noclassdeffound error for the class - com.ibm.ws.webservices.multiprotocol.GeneratedService which is still inside the second jar.
Some suggestions from stack overflow were setting dependencies in maven pom xml. This will not be applicable to my application as I am not running it through maven but just running it on tomcat web server.
Please suggest a way forward to resolve this issue. Please note that this application is targeted for Websphere server at environment level. Tomcat server is being used at the local setup itself. Please suggest keeping this in mind. I also tried installing websphere server for local setup as well but could not do it as commercial servers are not allowed to be installed inside our organization.
Related
I am trying to use opencv 2.4.9. in a Java Servlet with NetBeans, i have two files - the first one is a Servlet java file Login.java which is called by index.html , and the second one is CamCap.java a java file with all the opencv imports but this file is in the same package, am calling a function of second java file from the first one. The two files run fine separately as java project but when I try to run the complete servlet project it throws this Error - (java.lang.NoClassDefFoundError: org/opencv/core/Core)
How to resolve this!!?
You need to make your OpenCV jar available to both the IDE as well as the application server. I believe you've already made it available to your IDE by adding it to your web project's classpath.
Now to satisfy the dependency when running on the application server too, just copy the jar to your web project's /WEB-INF/lib directory, build your war and deploy it again.
I suggest you to always copy your dependency to /WEB-INF/lib first, and then adding it to your project's classpath. This takes care of such errors and also makes sure that both the IDE and the application server are using the same version of the jar.
I am Java developer, recently working on Xpages project. we are using Notes 9.0.1. I created Java agent to send email and I want to use some third party jar, something like org.apache.commons.lang3 , end up this issue. how to add third party jar, like commons-lang3-3.4.jar, in my Xpages project?
I tried different ways
add jar under /jvm/lib/ext folder, restart DDE.the I can see it in
my project JRE system libray, but could not import in my Java code.
Maybe this is the way for server deployment.
add jar under /Code/Jars and then DDE generated with new name added in /Webcontent/WEB-INF/lib, but...
Add jar directly under /Webcontent/WEB-INF/lib, but not appeared /Code/Jars in Application view
add jar under the Java agent Archive folder, but...
None of them allows me import the package in my Java code.
Anything I did wrong, or is there any good way to add third party jar in XPages project.
Thanks
If you add a JAR to your project by importing it into /Code/JARs, it should be added so as to be accessible by your build path(2,3). The same is true of your /WebContent/WEB-INF/lib, but that may not be automatically defined in your version of DDE; for example, Domino Designer 9 has the design elements of /Code/Java and /Code/JARs, which didn't previously exist (these are separate folders/paths from /WebContent/WEB-INF/src or /WebContent/WEB-INF/lib, either can be in the build path). In either case, if your approach is to have the JAR in your NSF, make sure your build path has the path with your JARs. Separately you could add each JAR individually.
You can get to the Build Path via Project > Properties, then for the part of your build path concerning JARs, go to "libraries":
individual JARs in Project Build Path
JAR class path in Build Path (ex- /WebContent/WEB-INF/lib)
As for the path of using the /jvm/lib/ext folder approach, I've covered that in a blog post and it's important to remember to have the JARs in the appropriate relative path both on the server and in your Designer/local path (otherwise your local, DDE, may not pick up the change).(1)
For both, if you keep build automatically turned off, you'll want to make sure you perform another build to see the changes.
As for a Java Agent archive, this should just work and again I'm wondering whether your build automatically setting is enabled/disabled. The /jvm/ext/lib path ought to work for this as well (shown in my linked blog post).(4) *Note: as Paul Withers points out in the comments, importing a JAR to a Java Agent can introduce memory leak issues, making the /jvm/ext/lib/ path preferable.
I developer a web application using Java. When I deploy it to my application server (Jetty, Tomcat, JBoss, GlassFish, etc.) throws an error. I can see this error message in the stacktrace:
java.lang.ClassNotFoundException
Or
java.lang.NoClassDefFoundError
What does this mean and how can I fix it?
What does this mean?
First, let's see the meaning of java.lang.ClassNotFoundException:
Thrown when an application tries to load in a class through its string name using:
The forName method in class Class.
The findSystemClass method in class ClassLoader.
The loadClass method in class ClassLoader.
but no definition for the class with the specified name could be found.
Usually, this happens when trying to open a connection manually in this form:
String jdbcDriver = "...'; //name of your driver
Class.forName(jdbcDriver);
Or when you refer to a class that belongs to an external library and strangely this class cannot be loaded when the application server tries to deploy the application.
Let's see the meaning of java.lang.NoClassDefFoundError (emphasis mine):
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
The last part says it all: the class existed at compile time i.e. when I compiled the application through my IDE, but it is not available at runtime i.e. when the application is deployed.
how can I fix it?
In Java web applications, all third party libraries used by your application must go in WEB-INF/lib folder. Make sure that all the necessary libraries (jars) are placed there. You can check this easily:
- <webapp folder>
- WEB-INF
- lib
+ jar1
+ jar2
+ ...
- META-INF
- <rest of your folders>
This problem usually arises for JDBC connectivity jars (MySQL, Derby, MSSQL, Oracle, etc.) or web MVC frameworks libraries like JSF or Spring MVC.
Take into account that some third party libraries rely on other third party libraries, so you have to add all of them in WEB-INF/lib in order to make the application work. A good example of this is RichFaces 4 libraries, where you have to download and add the external libraries manually.
Note for Maven users: you should not experience these problems unless you have set the libraries as provided, test or system. If set to provided, you're responsible to add the libraries somewhere in the classpath. You can find more info about the dependency scopes here: Introduction to the Dependency Mechanism
In case the library must be shared among several applications that will be deployed on your application server e.g. MySQL connector for two applications, there's another alternative. Instead of deploying two war files each with their own MySQL connector library, place this library in the common library folder of the server application, this will enable the library to be in the classpath of all the deployed applications.
This folder vary from application server.
Tomcat 7/8: <tomcat_home>/lib
JBoss 7/Wildfly: <jboss_home>/standalone/lib
The class must exist under WEB-INF/classes or be inside a .jar file under WEB-INF/lib. Make sure it does.
Same problem happen with me.
Might be possible one of your libraries are using some classes internal which is not available
in your lib or maven dependency pom.xml.
Thats means you have analyze your error logs and identify these classes and then import all dependencies in maven or lib folder.
I have fixed this error by the same way.
because some of my libraries are using activation.jar and json.jar internally.
I am working on a portlet project and came across a problem with 2 classes with same name (including packages) in different .jar files. I have com.ibm.ws.webcontainer.jar as a default WebSphere library and jsf-impl.jar which is necessary for some JSF features.
The problem comes out when PortletFacesContextFactoryImpl class (another JSF class) tries to get access to com.sun.faces.util.Util.parameterNonNull(Object arg) method and I get NoSuchMethodError.
I tried setting classloader policy to PARENT_LAST, this doesn't help. I can't remove com.ibm.ws.webcontainer.jar from the server, but when I try to use Util class in my code, the only option is the class from it, not from jsf-impl.jar. jsf-impl.jar is included into Java Build Path.
How can this problem be solved since I cannot alter PortletFacesContextFactoryImpl source and move .jar with wrong class?
Parent Last should be your solution. WebSphere Portal deploys portlet application with Parent Last as default, but it does not hurt to double check it at the WebSphere Application Server Integrated Solutions Console (Admin Console) >
However, it also depends on your portlet application setup. I assume it is com.sun.faces.util.Util which is troubling you. On my system, this class is located in jsf-impl.jar and the Application Server Web Container. In order to get it to work, jsf-impl.jar needs to be placed in the WEB-INF/lib directory of your portlet application. To verify that, use the Class Loader View of WAS: Admin Console > Troubleshooting > Class loader viewer > WebSphere_Portal > Applications and then the your portlet application. It must start with PA. Switch to the table view and search for the class.
You also mentioned the Java Build Path. This is another topic and depends on your IDE - assumingly Eclipse. Check the Order and Export tab, jsf-impl.jar should be placed at the top, so that it overrules the server runtime classpath entries.
PARENT_LAST classpath setting will help you. However, for this setting to be done, your portlet muste be packaged as a EAR. If your portlet is packaged as a war and you configure the classpath settings manually, they get erased everytime you deploy the portlet.
We are in the process of upgrading from Jetty 9.0.6 to 9.1.1 and are working through the configuration changes to complete the transition. Our application has numerous web contexts deployed, all of which use a common set of libraries (apache commons, logging, specific db, etc) located in an external directory (i.e. - outside of the Jetty deployment).
In Jetty 9.0.6, we included a parameter on start-up which referenced the top level directory for these common libraries:
java -jar .\start.jar lib=M:\common\lib
In the cutover to Jetty 9.1.1 the flag has been changed to --lib. Using the --list-configs we've verified that the directory is in the classpath created by start.jar. However, when the application is started, we are getting numerous ClassNotFound issues. All of these errors are for classes contained in jar files that are located in the common library.
This makes me believe that the flag is for either un-jarred classes or a list of specific jar files. We've also tried using the M:\common\lib* and m:\common\lib*.jar to no avail.
I've searched for any reports of a similar issue, but having found none am asking the question. Does anyone know how to pass all .jar files located in a directory to Jetty 9.1.1 on startup?
I've reported this issue on the Jetty site at the following URL:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=428097
Will continue to track further information about the configuration or the issue from there.
UPDATE:
- This issues has been resolved and merged into the Jetty 9.2 code base. For version 9.1.5 we created a custom module that specifies all the .jar files in the directory and that is working fine (although not ideal).
The commonlib.mod file looks like:
#
# commonlib Module
#
[lib]
M:\commonlib\commons-codec-1.4.jar
M:\commonlib\commons-fileupload-1.2.1.jar
M:\commonlib\commons-io-2.3.jar
M:\commonlib\commons-logging-1.1.1.jar
M:\commonlib\commons-net-2.2.jar
M:\commonlib\commons-pool-1.6.jar
Used the command line to add the commonlib module to the start.ini file (although a manual edit would work just fine too).