java.lang.ClassNotFoundException: com.ibm.broker.config.proxy.BarFile - java

Added 2 jar files for IBM integration in Java. Getting this exception:
error at :: BarFile b = BarFile.loadBarFile("C:\\Users\\Uni\\Desktop\\outputt\\Dev_BAR.bar");
root cause:::::::::
java.lang.ClassNotFoundException: com.ibm.broker.config.proxy.BarFile
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
com.cts.XmlExtract.extract(XmlExtract.java:25)
com.cts.BrokerServlet.doGet(BrokerServlet.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

When developing a java project using an IDE (perhaps IBM's RAD or Eclipse) it is important to remember that there are two classpath that you care about:
The classpath when you are writing the code. This is the Compile Classpath.
The classpath when you are running the code on a server. This is the Runtime Classpath.
The error you are receiving is happening because the Runtime Classpath does not contain one (or both) of the jars that you are attempting to add to your project.
You can add a jar to the Runtime Classpath using one of the following techniques:
Add the jar to the WEB-INF/libs directory in your web app project. This technique guarantees that the jar will be distributed with your WAR file, but also guarantees that the jar will not be shared by other projects that may want to use the jar.
If you are building an EAR, add the jar to the EAR file. It's been a while since I built an ear, so I dont remember the exact directory name (I think you just at it to the root of the EAR). This allows WAR files that are in the EAR to share the jar.
Add the jar to a shared location in your tomcat. $CATALINA_HOME/lib seems like a good spot. This allows all web apps in that instance of tomcat to share the jar.
Other. Other servers provide other means to share a jar.

Related

while loading excel data into database using servlets ( java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook) [duplicate]

How should I add JAR libraries to a WAR project in Eclipse without facing java.lang.ClassNotFoundException or java.lang.NoClassDefFoundError?
The CLASSPATH environment variable does not seem to work. In some cases we add JAR files to the Build Path property of Eclipse project to make the code compile. We sometimes need to put JAR files inside /WEB-INF/lib folder of the Java EE web application to make the code to run on classes inside that JAR.
I do not exactly understand why CLASSPATH does not work and in which cases we should add JARs to Build Path and when exactly those JARs should be placed in /WEB-INF/lib.
The CLASSPATH environment variable is only used by the java.exe command and even then only when the command is invoked without any of the -cp, -classpath, -jar arguments. The CLASSPATH environment variable is ignored by IDEs like Eclipse, Netbeans and IDEA. See also java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable.
The Build Path is only for libraries which are required to get the project's code to compile. Manually placing JAR in /WEB-INF/lib, or setting the Deployment Assembly, or letting an external build system like Maven place the <dependency> as JAR in /WEB-INF/lib of produced WAR during the build, is only for libraries which are required to get the code to deploy and run on the target environment too. Do note that you're not supposed to create subfolders in /WEB-INF/lib. The JARs have to be placed in the root.
Some libraries are already provided by the target JEE server or servletcontainer, such as JSP, Servlet, EL, etc. So you do not need put JARs of those libraries in /WEB-INF/lib. Moreover, it would only cause classloading trouble. It's sufficient to (indirectly) specify them in Build Path only. In Eclipse, you normally do that by setting the Targeted Runtime accordingly. It will automatically end up in Build Path. You do not need to manually add them to Build Path. See also How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
Other libraries, usually 3rd party ones like Apache Commons, JDBC drivers and JEE libraries which are not provided by the target servletcontainer (e.g. Tomcat doesn't support many JEE libraries out the box such as JSF, JSTL, CDI, JPA, EJB, etc), need to end up in /WEB-INF/lib. You can just copy and paste the physical JAR files in there. You do not necessarily need to specify it in Build Path. Only perhaps when you already have it as User Library, but you should then use Deployment assembly setting for this instead. See also ClassNotFoundException when using User Libraries in Eclipse build path.
In case you're using Maven, then you need to make absolutely sure that you mark libraries as <scope>provided</scope> if those are already provided by the target runtime, such as JEE, Servlet, EL, etc in case you deploy to WildFly, TomEE, etc. This way they won't end up in /WEB-INF/lib of produced WAR (and potentially cause conflicts with server-bundled libraries), but they will end up in Eclipse's Build Path (and get the project's code to compile). See also How to properly install and configure JSF libraries via Maven?
Those JARs in the build path are referenced for the build (compile) process only. If you export your Web Application they are not included in the final WAR (give it a try).
If you need the JARs at runtime you must place them in WEB-INF/lib or the server classpath. Placing your JARs in the server classpath does only make sense if several WARs share a common code base and have the need to access shared objects (e.g. a Singleton).
If you are using Maven:
Open the project properties, and under Deployment Assembly click Add...
Then select Java Build Path Entries and select Maven Dependencies
Resolved by setting permissions.
Had related issue using PySpark and Oracle jdbc. The error does not state that the file cannot be accessed, just that the class cannot be loaded.
So if anyone still struggles, check the permissions. Some might find it obvious tho'.
I want to give the answer for the folowing link question ClassNotFoundException oracle.jdbc.driver.OracleDriver only in servlet, using Eclipse
Ans: In Myeclipse go to Server-->left click on Myeclipse Tomcat7-->Configure Server Connector-->(Expand)Myeclipse Tomcat7--> Paths-->Prepend to classpath-->Add jar (add oracle14 jar)-->ok

java.lang.ClassNotFoundException: javazoom.spi.mpeg.sampled.file.MpegAudioFileReader [duplicate]

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.

Jersey Startup Issue : java.lang.NoSuchMethodError: com.google.common.collect.Sets.newIdentityHashSet()

I am using Jersey 2.5.1. I have my .war file packaged inside my .ear file. In the WEB-INF\lib folder of the .war module I have guava-14.0.1.jar. jersey-common-2.5.1.jar has dependency on guava.
Outside, in the ear/lib folder I have another guava jar --> guava-17.0 which is required by my project.
Both the jars have the method newIdentityHashSet(), but still I face the following error:
java.lang.NoSuchMethodError: com.google.common.collect.Sets.newIdentityHashSet()Ljava/util/Set;
at org.glassfish.jersey.model.internal.CommonConfig.(CommonConfig.java:220)
at org.glassfish.jersey.server.ResourceConfig$State.(ResourceConfig.java:110)
at org.glassfish.jersey.server.ResourceConfig.(ResourceConfig.java:351)
at org.glassfish.jersey.servlet.WebComponent.createResourceConfig(WebComponent.java:444)
at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:302)
Truncated. see log file for complete stacktrace
I have tried removing one of the guava jars, but the error is same. I have tried keeping same version in both the places. But didn't work.
I am deploying in Weblogic 12C.
Any help on this will be great.
It is not good idea to have duplicated jar files into the same ear/war file. Because errors of this type will appear. The best practice is to have only one version by library.
With that being said, you can check where is trying to load the class that don't have that method:
One way to check from which jar file are loaded specific classes, is setting the parameter: -verbose:class to the JRE.
This will give you a hint on this classloading issue.
Also WLS has bundled Classloader Analysis Tool (CAT) that helps you to identify duplicated jar files (conflicts, etc.)

web app and dependency jars moved to Tomcat 6 lib directory, logback can't find config file

I have an Java 6 application installed on Tomcat 6. The application jar file and dependency jar files live in my webapps/myapp/WEB-INF/lib directory, while my logback config file lives in webapps/myapp/WEB-INF/classes.
The app is the only app that runs in a tomcat instance, and we run around a hundred instances at a time. The server admin team decided that the app and dependency libs are redundant and moved them to tomcat/lib.
First they moved just the myapp.jar to tomcat/lib. This resulted in a exception:
java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
This is a bit weird as, if anything, i would expect it to fail trying to load my app. Instead it appears that loading the app from a jar in tomcat/lib has changed the path of the classloader. I thought that the web app directory, and of course the WEB-INF/web.xml, would "anchor" the classloader to the application directory. This doesn't seem to be the case.
When that didn't work, the admin team moved all the rest of the dependency libs to the tomcat/lib directory. Now the app starts up, finds it's configuration properties files, etc., but does not locate the logback.xml file (in WEB-INF/classes/logback.xml). Again, this suggests that something has significantly changed in the class loader environment.
The most important consequence is that if I place a new dependency in my WEB-INF/lib directory it is no longer seen by my application. And of course it would be nice to see my logging config file again without having to move it to tomcat/lib as well.
Any ideas on what is going on with my configuration?
If your server runs on Linux, there is an alternative setup that could prevent those classloader issues and (maybe) make your server admin happy. You could put the common jars in some directory (not under tomcat/lib) and then create symlinks to these jars under each webapp's WEB-INF/lib directory.
I have used this setup for years and it has worked well for me. You can create a shell script that scans the common jars directory and creates symlinks for each webapp, and you can setup this script to run automatically when Tomcat starts (e.g. by calling it from Tomcat's startup script).
I just solved a similar problem with my own project. For starters, make sure the logback.xml file is actually in the resulting .war file, and where your application is expecting it to be. If you are on a Mac then check out Jarzilla for inspecting the contents of WARs and JARs without having to extract them. This turned out to be the problem in my case.
Also, if you are having dependency issues then you may want to look into a project build manager like Apache Maven or Gradle or even Apache Ant.
Hope this helps!

ant: Need help packaging an EJB and its dependencies into an EAR

My goal is pretty simple: to use ant to build an EAR which contains 1 EJB and 1 jar containing all of the dependencies. This jar, called common.jar for the sake of example has vendor jar files in it as well as other xml files that the EJB depends on and will need to be able to see during runtime....
So far I have everything packaged correctly as an EAR like this:
EARFILE.ear
-EJBFILE.jar
/META-INF
-MANIFEST.MF
-common.jar
/META-INF
-MANIFEST.MF
/lib
-(all vendor jars inside here)
-(All the xml config files are inside the root of the common.jar)
Inside the MANIFEST.MF for the EJBFILE.jar is...
Class-path: ../../common.jar
Inside the MANIFEST.MF for the common.jar is...
Class-path: ../lib/some_common.jar
When I deploy this the appserver (websphere) cannot find the JAR file when I try to start the server. I am getting the ClassDefNotFoundError because the classes inside the EJB cant find the vendor JAR files when I try to start the instance. However I know that common.jar is setup correctly though, else the EJB wouldn't have compiled since it needed to have those vendor jars on the classpath for javac.
So what I want to know is this:
How can I get the runtime to correctly see the Vendor jar files.
Will the EJB be able to see the xml files at run-time? I am concerned about this because these xml files are located outside of the EJB inside of a jar that is just in the EAR, it isn't even a module its just a jar inside the EAR.
Does it even matter when using websphere? From what I gather some containers don't even care what is in the Class-path of MANIFEST.MF.
There are several improvements I can suggest, based on running into similar problems.
First and most importantly, use the appxml attribute of the Ant ear task to specify your deployment descriptor (usually named application.xml); also include references to the vendor JAR files bundled as defined below
I would recommend you not put your vendor JAR files into another JAR - instead, just copy them into the EAR at the same level as EJBFILE.jar
The configuration XML files can go in a sub-directory of the EJBFILE.jar (such as config), and then you can reference them as /config/filename.xml.
The application.xml file will tell WebSphere where to find your JAR files. Classpath traversal in an application server is not the same as that of a compiler, which JBoss has taught me the hard way.
I am using all of the above patterns, and my in-container code (deployed in the EAR) can see all my XML files, as well as find all my dependencies.

Categories

Resources