Could not initialize class java.util.logging.LogManager - java

Why do I get this error. I get it in my develpment tool when I run my code as a java application (IBM RSA\Eclipse) and in my isolated deployment environment.
I can run junits against the code and they are successful so I know that parsing the particular application context file is not a problem (web service application context). The same jre and maven dependencies are on the classpath for junit and running java application.
I know cxf uses java logger by default but adding this command doesn't help,
System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger");
If I debug the code I see that the issue is raised when the application context files are parsed.
Caused by: org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [org.apache.cxf.jaxws.spring.NamespaceHandler] for namespace [http://cxf.apache.org/jaxws]: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError: Could not initialize class java.util.logging.LogManager

The solution was to add this System property and provide the default file when running as a java app.
System.setProperty("java.util.logging.config.file", "/log/logging.properties");
http://www.javapractices.com/topic/TopicAction.do?Id=143
Now I have another problem but similar in nature so hopefully I can find a similar solution.
Caused by: java.lang.NoClassDefFoundError: Could not initialize class java.net.ProxySelector

Related

Faced with error: nested exception is java.lang.UnsatisfiedLinkError when run java application as service in CentOs

I have a spring-boot web application and today I deploy it to Linux system. My application uses HSM device so it use a library called jcryptoki to work with it.
My service is deployed and run well, but unfortunately, I am facing with below error when executing business function:
nested exception is java.lang.UnsatisfiedLinkError: no jcryptoki in java.library.path
here is the document that I referred to create a service.
When I run this app as normal by run command java -jar ... it's worked well.
I found the same error occur when missing the lib path declaration $LD_LIBRARY_PATH. Maybe when running application as a service, the system cannot be found this lib path.
I run both case as root account, have I lost anything in configuration or permission?
Finally, I found the problem caused by the missing Environment declaration variable on the service definition file.
With specific declaration variable: LD_LIBRARY_PATH=LD_LIBRARY_PATH=/opt/safenet/protecttoolkit5/cpsdk/lib/linux-x86_64/ I add new file named imported_inv (located in etc/default) with content as above. In the service defination file, I declare additional info like this
reload service and then it works like a charm.

How to fix 'javax.xml.parsers.FactoryConfigurationError on every second server startup'

I'm writing a web application which uses JAXB and JAX-RS. The content-type used for getting/sending data to the server is XML. The web application runs in a GlassFish server(4.1.2/ 5), the JDK used is 1.8.
The problem is that the internal SAXParser allows doctype declarations which makes XEE-Attacks possible. I'm not able to inject the specific feature into the SAXParserFactory, so i built a wrapper for the SAXParserFactory, which sets the feature. The SAXParserFactory is registered using the system properties.
System.setProperty("javax.xml.parsers.SAXParserFactory","de.mycompany.sdk.parser.SAXParserFactoryWrapper");
Unfortunately, the server throws a ClassNotFoundException on every second startup, otherwise the application behaves normal.
Has anyone ideas how to fix it?
I've also tried to include the jar into the class path or specify it using the manifest, but did not work neither.
I get the following error:
javax.xml.parsers.FactoryConfigurationError: Provider de.mycompany.sdk.parser.SAXParserFactoryWrapper not found
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:200)
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:152)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:232)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.getSAXParser(DeploymentDescriptorFile.java:125)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:305)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:245)
Caused by: java.lang.ClassNotFoundException: de/mycompany/sdk/parser/SAXParserFactoryWrapper
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at javax.xml.parsers.FactoryFinder.getProviderClass(FactoryFinder.java:124)
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:188)
... 56 more```
ClassNotFoundException
can occur if you have multiple versions of a class (de.mycompany.sdk.parser.SAXParserFactoryWrapper in this case) in your class path. This generally happens when you have multiple versions of the same library in your classpath.
Thanks for your help! I found a solution for my problem. I deployed the application using the GlassFish CLI and it works! The previous tries were done using NetBeans. It seems that NetBeans does anything different during the startup or shutdown process of the GlassFish server wich involves the exception.

Error on war file deployment on WebLogic Server

I am deploying one war file on WebLogic server (12.1.3.0.0) but when I try to start that application to serve all requests. It get failed with the following error message:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.method.annotation.ExceptionHandlerMethodResolver.hasExceptionMappings()Z .
The same war file is working fine on Windows platform and other Linux machines but I am getting that error on one particular Linux machine so my understanding is that there is something missing (e.g. some package) on this machine but I am unable to identify that what exactly.
It means "I cannot find the method hasExceptionMappings inside class org.springframework.web.method.annotation.ExceptionHandlerMethodResolver"
Please check if the spring jar version that the WebLogic using is different when you are compile the WAR. The spring library could be a shared library, you may check the classpath first.
FYI: https://docs.oracle.com/middleware/1212/wls/WLPRG/classloading.htm#WLPRG319
If this code works on other machines and is definitely an identical deployment, then the difference must be on the machine where you are deploying it. I agree you should check the versions of the Spring files that are provided on this server against those where it does run successfully. When you find a difference you will know what needs fixing.

NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService

While running the application I was getting the following errors.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService
AxisService class is in axis2-kernel-1.6.2.jar file. Some of the classes from this jar are working fine without any issues, but some classes are throwing NoClassDefFoundError from this jar file at runtime. AxisService class is present in axis2-kernel-1.6.2.jar, even it throws error.
This is working fine in local machine. But error getting in Oracle r12 server.I have already set the class path for the jar file.
I am Using Java version is 1.6 and Apache axis2.1.6.2.
Had the same issue. I had included only jars that I needed to compile the application.
When I included everything from \axis2-1.6.2\lib\ folder, this exception were gone.
I had a similar problem using Tomcat and Axis2 and after a week finding out the error I realized there was a axis configuration problem. especifically my aplication can't instantiate the class which accedded to persistence layer. I include this parameter line:
<parameter name="ServiceTCCL">composite</parameter>
in services.xml file which is used by axis2 to work.
For more information see the comments in http://wso2.com/node/1131

Deploying an ear containing an Application Client on Glassfish 3.1.2 throws exceptions

I'm asking this question just so I can answer it myself, because it's driven me nuts for two days and no one else should have to suffer as I have.
When deploying my ear, I get exceptions like this :
Exception while invoking class org.glassfish.appclient.server.core.AppClientServerApplication start method
org.jvnet.hk2.component.ComponentException: injection failed on org.glassfish.appclient.server.core.jws.JavaWebStartInfo.dch with class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
at org.jvnet.hk2.component.InjectionManager.error_injectionException(InjectionManager.java:284)
at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:161)
at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:93)
.
.
Caused by: org.jvnet.hk2.component.ComponentException: Failed to create class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
.
.
Caused by: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
.
.
or sometimes like this :
Exception while loading the app : injection failed on org.glassfish.appclient.server.core.jws.JavaWebStartInfo.dch with class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
org.jvnet.hk2.component.ComponentException: Failed to create class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
at com.sun.hk2.component.ConstructorCreator.create(ConstructorCreator.java:71)
at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:80)
.
.
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.appclient.server.core.jws.DeveloperContentHandler
The bug is utterly baffling, because ear files that work perfectly well on one machine can fail to deploy on another, and a server can appear to become "infected" by the problem and refuse to deploy ears that previously worked perfectly well. Clearing out caches and generated files doesn't make it go away.
After hours and hours of fiddling with it I think I have the answer - the problem is caused by having a xerxes-impl jar file included in the ear lib folder. I suspect that through some class loading weirdness it is replacing the server's own xml parser. This accounts for the strange infection problem because the class path issues don't go away until the server is restarted. It's possible that the problem will manifest with any xml parser, but I haven't checked.
To solve the problem shut down glassfish, make sure the ear you're deploying doesn't have xerces in it, and then restart glassfish and deploy your new clean ear file. It should work. It did for me. Failing that, i think your only recourse is going to be blood sacrifice.
The JDK defines the javax.xml.parsers.DocumentBuilderFactory interface and provides an default implementation. Service providers can replace the implementation class by setting a system property "javax.xml.parsers.DocumentBuilderFactory". When you deployed xerces it used this property to provide it's own implementation.
Snippet from javax.xml.parsers.DocumentBuilderFactory:
public static DocumentBuilderFactory newInstance() {
try {
return (DocumentBuilderFactory) FactoryFinder.find(
/* The default property name according to the JAXP spec */
"javax.xml.parsers.DocumentBuilderFactory",
/* The fallback implementation class name */
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
} catch (FactoryFinder.ConfigurationError e) {
throw new FactoryConfigurationError(e.getException(),
e.getMessage());
}
}
All this applies as well to javax.xml.parsers.SAXParserFactory.
Choosing the Parser Implementation
If no other factory class is specified, the default SAXParserFactory class is used. To use a parser from a different manufacturer, you can change the value of the environment >variable that points to it. You can do that from the command line:
java -Djavax.xml.parsers.SAXParserFactory=yourFactoryHere [...]
The factory name you specify must be a fully qualified class name (all package prefixes >included). For more information, see the documentation in the newInstance() method of the >SAXParserFactory class.
http://docs.oracle.com/javase/tutorial/jaxp/sax/validation.html

Categories