Currently I'm working with EJB services running on Weblogic 12c Server. When I write a JUnit test to call EJB services, an error appears with:
java.lang.NoClassDefFoundError:
weblogic/i18n/logging/MessageLoggerRegistryListener
Anyone knows where is this class from? I googled it but got no result.
This class can be found in the /wlserver/modules/features/weblogic.server.merged.jar and in the /wlserver/server/lib/wlclient.jar files.
Additionally if you are doing this in a maven project, and you're using the Oracle Maven repository, you can use
<dependency>
<groupId>com.oracle.weblogic</groupId>
<artifactId>wlclient</artifactId>
<version>12.1.3-0-0</version>
<scope>provided</scope>
</dependency>
Set WL_HOME in your environment variable correctly:
Variable name: WL_HOME
Variable value:
your weblogic 12c installation path like: C:/Oracle/Middleware/Oracle_Home/wlserver/server
Related
I'm currently looking into testing jetty servlets. I found the org.eclipse.jetty.testing.ServletTester class in some old documentation (just by random searching on the web), but it seems to be removed in newer versions.
Is there a replacement for it, and if yes, where can i find it?
If there is no replacement, I would be happy to hear about different ways to accomplish the goal of testing servlets!
Thanks in advance
The class org.eclipse.jetty.testing.ServletTester is the old Jetty 7 and Jetty 8 ServletTester.
It can be found in the following maven artifacts ...
https://search.maven.org/search?q=fc:org.eclipse.jetty.testing.ServletTester
The newer org.eclipse.jetty.servlet.ServletTester (note the package change) is available for Jetty 9.x, Jetty 10.x, and Jetty 11.x in the following artifacts ...
https://search.maven.org/search?q=fc:org.eclipse.jetty.servlet.ServletTester
Standard maven repository behaviors here, as the class is not a runtime class, it sits in the tests jar (also on maven central).
Example:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.35.v20201120</version>
<classifier>tests</classifier>
</dependency>
When I am trying to run my app I have the following error message :
cannot Deploy pro_jpa
deploy is failing=Error occurred during deployment: Exception while deploying the app [pro_jpa] : java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader. Please see server.log for more details.
So I add this to my pom :
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version>
</dependency>
But it didn't fix the issue even if it supposed to add the needed jar to the app.
I also tried to add the guava.jar to the server lib but it doesn't change anything.
If anyone has an idea thank you.
Add the runtime scope to the dependency in pom.xml, to get it available at runtime:
<scope>runtime</scope>
I have no more this issues when I am working with version 2.3 of the web app it is only appearing when I am using version 3.0.
I am using BoneCP and glassfish so the issue may comes from it.
To solve it I need to add the jar to the domaine itself in glassfish under :
glassfish5\glassfish\domains[domain name]\lib\ext
I end with this jar :
bonecp-0.8.0-rc1.jar
guava-29.0-jre.jar
mysql-connector-java-8.0.20.jar
slf4j-api-1.7.30.jar
In a test WebSocket application using Atmosphere servlet I'm getting the following exception:
SEVERE: Servlet.service() for servlet AtmosphereServlet threw exception
java.lang.ClassNotFoundException: javax.servlet.AsyncContext
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:191)
at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:177)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
From the below posts I understand that this might be caused by a Servlet container version older than Servlet 3.0:
ClassNotFoundException: javax.servlet.AsyncContext in Jetty hello world
ClassNotFoundException: javax.servlet.AsyncContext in Jetty hello world in eclipse
Grails project - Servlet call - ClassNotFoundException: javax.servlet.AsyncContext
However the application is running on Tomcat7, and the following dependency is added in pom.xml:
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
I've checked all other dependensies in the project and was not able to find anything else related to Servlet. Still I'm getting the exception.
Questions: How to find a jar file which is actually used by the application? How to find the dependency which is causing the usage of an old version?
I was finally able to solve the dependency conflict by doing the following.
To find the jar file which is used by application I used the below simple code:
public void listJarFilesAndClassVersions() {
Class classToCheck = javax.servlet.ServletRequestWrapper.class;
URL location = classToCheck.getResource('/'
+ classToCheck.getName().replace('.', '/') + ".class");
System.out.println(location.toString());
for(Package p : Package.getPackages()) {
if (p.getName().startsWith("javax.servlet")) {
System.out.println("Class: " + p.getName()
+ ", version: " + p.getSpecificationVersion());
}
}
}
The class javax.servlet.ServletRequestWrapper was chosen because it does exist in the old Servlet 2.5.
The execution of the above script gives me the following:
jar:file:/C:/Users/[username]/.m2/repository/org/apache/tomcat/servlet-api/6.0.29/servlet-api-6.0.29.jar!/javax/servlet/ServletRequestWrapper.class
Class: javax.servlet.jsp, version: 2.1
Class: javax.servlet, version: 2.5
Class: javax.servlet.http, version: null
So, first, it confirms that the Servlet of version 2.5 is used, and second, the "bad" jar is located in the maven repository under the tomcat directory.
After a short reasearch I was finally able to find the root cause of that: when deploying and running the maven application I need to specify the concrete version of tomcat, otherwise maven uses the libraries from tomcat of version 6. So the fix for me was to change
mvn -Dmaven.tomcat.port=8080 tomcat:run-war
to
mvn -Dmaven.tomcat.port=8080 tomcat7:run-war
Now if I execute the above script it gives the following result:
jar:file:/C:/Users/[username]/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/7.0.47/tomcat-embed-core-7.0.47.jar!/javax/servlet/ServletRequestWrapper.class
Class: javax.servlet.jsp, version: 2.2
Class: javax.servlet, version: 7.0
Class: javax.servlet.http, version: 7.0
Class: javax.servlet.annotation, version: 7.0
Class: javax.servlet.descriptor, version: 7.0
Hope it helps others who is running into the same issue.
There're two ways in which I usually find a conflict.
If you are using Eclipse, open the pom.xml in IDE, and switch to "Dependency Hierarchy" tab. In the left panel is the dependency tree, and in the right panel are the dependencies actually getting used. Right after each dependency it's its scope (eg. compile / test / runtime / omitted for conflict)
In terminal run the command. mvn dependency:tree It will print out the dependency like in Eclipse.
I am trying to use Apache CXF to talk to a unknown web service. I have followed the Dynamic Client example from Apache.
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL.toExternalForm(), SERVICE_NAME);
This was working but now i am getting this exception when calling createClient():
java.lang.IllegalStateException: Unable to create schema compiler
Caused by:
javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC]
This looks similar to an existing bug. I am using DOSGi singlebundle 1.2 which includes cxf-minimal-2.2.9.jar; meaning the bug should be fixed in the version I'm using. the jaxb-api is included in my Apache CXF distribution which upon inspection contains jaxb-xjc.
Can anybody provide me some insight as to what I'm doing wrong? I swear this used to work.
"java.lang.ClassNotFoundException: com/sun/tools/ " is often occurs if you use JRE in your IDE intead of JDK.
Make sure, you use JDK in IDE (e.g. eclipse)
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.11</version>
</dependency>
resolved problem
Another solution is to include the cxf-rt-core in your Maven dependencies.
OK, this probably is supposed to be the easiest thing in the world, but I've been trying for the entire day, and it's still not working.. Any help is highly appreciated!
EDIT: For the correct procedure, please see Pascal's answer.
My wrong (since I did not disabled LoadTimeWeaving) procedure is left for reference..:
What I did:
Downloaded Tomcat 6.0.26 & Spring 3.0.1
Downloaded PetClinic from https://src.springframework.org/svn/spring-samples/petclinic
Built & deployed petclinic.war. Ran fine with default JDBC persistence.
Edited webapps/WEB-INF/spring/applicationContext-jpa.xml and set jpaVendorAdaptor to Hibernate.
Edited webapps/WEB-INF/web.xml and changed context-param from applicationContext-jdbc.xml to applicationContext-jpa.xml
Copied everything in the Spring 3.0.1 distribution to TOMCAT_HOME/lib.
Launched tomcat. Saw
Caused by: java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
Uncommented line <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> in webapps/META-INF/context.xml.
Same error. Added that line to TOMCAT_HOME/context.xml
Deployed without error. However, when I do something it will issue an error saying
java.lang.NoClassDefFoundError: javax/transaction/SystemException at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)
11.Changed scope of javax.transaction from test to default (just deleted test), as suggested by scaffman.
12.Runs fine!! Thank you!
Ok, here is what I did:
Get Tomcat 6.0.26
Checkout the petclinic sample:
svn co https://src.springframework.org/svn/spring-samples/petclinic/trunk/ petclinic
cd into the petclinic directory
Modify src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml to use Hibernate:
COMMENT the <context:load-time-weaver> (load-time weaver SHOULD NOT be used with Hibernate, this is for Toplink)
Declare Hibernate as jpaVendorAdapter (comment the Toplink part, uncomment the Hibernate part)
Modify the src/main/webapp/WEB-INF/web.xml to use the applicationContext-jpa.xml
Modify the pom.xml to bundle jta.jar in the war (as pointed out by #skaffman):
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>com.springsource.javax.transaction</artifactId>
<version>1.1.0</version>
<!--scope>test</scope-->
</dependency>
Build the war
mvn install
Deploy it to Tomcat
cp target/petclinic.war $TOMCAT_HOME/webapps
Browse
http://localhost:8080/petclinic
Looks like a problem with PetClinic packaging:
http://forum.springsource.org/showthread.php?t=85042
and
http://jira.springframework.org/browse/SPR-6880
There's fix in there for the pom.xml