I am trying to run a webservice that I coded in Apache CXF. I keep getting this error:
Stacktrace:] with root cause
java.lang.ClassNotFoundException: org.apache.cxf.message.Message
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
I have the cxf-core artifact added to my pom file and also I can see it included in the WAR file. And also the JAR which is actually throwing the exception. The part of the code that is throwing the exception is:
getBindingProvider().getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT, connectTimeout);
getBindingProvider().getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPointUrl);
getBindingProvider().getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 3720000);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Content-Type", Collections.singletonList("application/soap+xml"));
headers.put(Message.CONTENT_TRANSFER_ENCODING, Collections.singletonList("UTF-8"));
headers.put(Message.ENCODING, Collections.singletonList("UTF-8"));
getBindingProvider().getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
Am I doing something wrong?
I am building it with the maven-jar-plugin, like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultEntries>true</addDefaultEntries>
<addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<attachClasses>true</attachClasses>
<includeEmptyDirectories>true</includeEmptyDirectories>
<outputDirectory>${project.basedir}/target/</outputDirectory>
</configuration>
</plugin>
How are you running it? If you run the war file, which contains the cxf jar file, which contains the Message class, it should not throw a classcastexception. Unless you have conflicting dependencies. Or something goes wrong with classloaders.
Check for conflicting jars. In intellij, they are marked at the right of your screen. Eclipse has something similar.
Related
I'm trying to run SoapUI using a project cloned from github (IntellijJ File -> New -> Project from Version Control) :
git clone https://github.com/SmartBear/soapui.git
Then I'm running maven compile and it goes without errors. But when I try to run the app, I'm getting following error:
15:20:40,429 WARN [SoapUI] Missing folder [C:\%USERPROFILE%\IdeaProjects\soapui\ext] for external libraries
15:20:40,429 WARN [SoapUI] Missing folder [C:\%USERPROFILE%\IdeaProjects\soapui\ext] for external libraries
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at com.eviware.soapui.config.SoapuiSettingsDocumentConfig$Factory.parse(SoapuiSettingsDocumentConfig.java:59)
at com.eviware.soapui.DefaultSoapUICore.initSettings(DefaultSoapUICore.java:261)
at com.eviware.soapui.SwingSoapUICore.initSettings(SwingSoapUICore.java:99)
at com.eviware.soapui.DefaultSoapUICore.init(DefaultSoapUICore.java:143)
at com.eviware.soapui.StandaloneSoapUICore.<init>(StandaloneSoapUICore.java:38)
at com.eviware.soapui.SoapUI$SoapUIRunner.run(SoapUI.java:792)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.RuntimeException: Cannot load SchemaTypeSystem. Unable to load class with name schemaorg_apache_xmlbeans.system.s05EC9A3AACC8687CD214E9B1A496DB91.TypeSystemHolder. Make sure the generated binary files are on the classpath.
at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:788)
at com.eviware.soapui.config.SoapuiSettingsDocumentConfig.<clinit>(SoapuiSettingsDocumentConfig.java:20)
... 19 more
Caused by: java.lang.ClassNotFoundException: schemaorg_apache_xmlbeans.system.s05EC9A3AACC8687CD214E9B1A496DB91.TypeSystemHolder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:774)
... 20 more
Here's a link to POM:
https://github.com/SmartBear/soapui/blob/next/soapui/pom.xml
After reading some similar issues I assume there's something wrong with POM but I cannot tell what.
Any hints?
Hi I got a same problem and fixed it.
It was happened here.
settingsDocument = SoapuiSettingsDocumentConfig.Factory.newInstance();
public static final class Factory
{
public static com.eviware.soapui.config.SoapuiSettingsDocumentConfig newInstance() {
return (com.eviware.soapui.config.SoapuiSettingsDocumentConfig) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newInstance( type, null ); }
root cause is this one.
can not load this class.
"org.apache.xmlbeans.XmlBeans.getContextTypeLoader()"
This solution is a adding jar-with-dependencies plugin.
Error when using XmlBeans generated classes
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies
you has to add two blocks in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</buid>
and
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
</dependency>
I have been looking over the maven war plugin and how to configure it. Here is my situation. I have a web application that is distributed to several production facilities. There are two files, in this web app, that are customized for each facility. These are /js/config.js and /META-INF/context.xml.
I have my project in a typical maven structure:
/src
|--/main
|--webapp
|--/js
|--config.js
|--properties
|--plant.properties
|--/META-INF
|--context.xml
I've left out non-essential directories for brevity.
The config.js has been altered to contain "parameter" I want substituted:
var Config {
...
system_title: '${plant_name} - Audit System',
...
}
The relevant portion of my pom is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<filters>
src/main/webapp/js/properties/fayetteville.properties
</filters>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>src/main/webapp/js</directory>
<filtering>true</filtering>
<exclude>**/properties</exclude>
</resource>
</webResources>
</configuration>
</plugin>
When I run "mvn clean package", I would expect to see ${plant_name} replaced with what is in my properties file. In this case, my properties file contains a single key-value pair:
plant_name=Austin
But I am not seeing the substitution. The resulting config.js in the target folder still contains ${plant_name} as does the config.js in the resulting war file.
I really don't want to use profiles if possible. Eventually, I want the build process to use a list of properties files to do this for all plants.
From my research, including a number of SO questions and answers, I feel I have things configured correctly.
What might I be doing wrong?
So, the software is working properly and everything is fine. I did find some answers to my question online but I can't seem to fix my problem. Everything seems to be okay in my Build Path and in order.
The error I'm getting:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/service/ServiceRegistry
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.hibernate.service.ServiceRegistry
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I need to export my project to a JAR file, please help me, I'm desperate. And thanks to anyone that cares to answer in advance.
Building a jar-with-dependencies will solve your problem.
Add the following to your pom.xml file:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.main.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Run mvn clean compile assembly:single
Then you will be able to run java -jar name-with-dependencies.jar
So, I've figured out what was the problem. The problem was, I was using Java 8 for my project while I had installed (some time ago) Java 9 on my PC. When I tried to run the JAR file, it used Java 9 to run it and it had some dependencies misplaced. I just uninstalled Java 9, exported the project with jre 1.8.0_144 and I'm running jdk 1.8.0_121 on my PC. Everything works great now.
Thank you #Gal and #AJNeufeld for your answers and your help.
There seem to be many many posts about similar questions however I have been unable to find exactly what I am looking for.
Basically, I have a Java Application built using Maven in Eclipse. When I execute the project from withing Eclipse it works correctly as it can find all files in my resources directory. When I do a normal jar with dependencies build using maven it also works. However, in the final item I cannot get this to work:
I would like the resources to be excluded from the main executable jar and placed into a directory on the same level as the jar itself. This was a user can just make changes to the settings and execute the jar, so:
|--root level
|-Jar
|-resources
|-log4j.properties
|-settings.properties
I have the maven-jar-plugin doing this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.org.interfaces.SharepointClient.App</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>http://org.com</url>
<key>value</key>
<Class-Path>resources/settings.properties resources/log4j.properties</Class-Path>
</manifestEntries>
</archive>
<excludes>
<exclude>settings.properties</exclude>
<exclude>log4j.properties</exclude>
</excludes>
</configuration>
</plugin>
And I have the maven-assembly-plugin creating the resources directory with all the resource files.
The project compiles and generates the directory structure as I want it however, the class files are unable to locate anything in the resources directory even though I specifically added them the classpath in the manifest.mf
This is the Manifest for details:
Manifest-Version: 1.0
Build-Jdk: 1.7.0_17
Class-Path: resources/settings.properties resources/log4j.properties
lib/log4j-1.2.17.jar lib/jaxws-api-2.2.11.jar lib/jaxb-api-2.2.9.ja
r lib/javax.xml.soap-api-1.3.5.jar lib/javax.annotation-api-1.2-b03
.jar lib/jsr181-api-1.0-MR1.jar lib/saxon-9.1.0.8.jar lib/saxon-9.1
.0.8-dom.jar
Created-By: Apache Maven 3.0.5
Main-Class: com.org.interfaces.SharepointClient.App
key: value
url: http://org.com
mode: development
Archiver-Version: Plexus Archiver
When Executed I receive an error on this line of code:
PropertyLoader.class.getClassLoader().getResourceAsStream("settings.properties");
The error is:
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.org.interfaces.SharepointClient.PropertyLoader.getProps(PropertyLoader.java:29)
EDIT:
I am only having trouble getting java to load resources, not dependencies. Those appear to load correctly.
I think you are making this more difficult that it need be. Take a look at this http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html. You should simply add all of your dependencies to the pom.xml file. This way, whenever you transport your code, maven will use the pom.xml file to rebuild the project with all of your dependencies. http://mvnrepository.com/ makes it even easier. All you have to do is search for the dependency in the repository, and copy it into your pom file.
I was looking up how to get the application name(artifact id) and version from maven pom or manifest when I came across this question Get Maven artifact version at runtime.
The above works for me when I package the project but I can't seem to get anything to work when I try to run the program using eclipse. I tried using the .properties method when building since I assumed that is not package dependent but I am still not getting a result. If anyone has an idea or solution to this problem it would be greatly appreciated.
My last attempt is below. This uses the manifest when packaged(which works) and trying to get the .properties file when running in eclipse.
String appVersion = getClass().getPackage().getImplementationVersion();
if(appVersion == null || "".equals(appVersion)) {
appVersion = Glob.getString(appVersion);
if(appVersion == null || "".equals(appVersion)) {
System.exit(0);
}
}
Create a property file
src/main/resources/project.properties
with the below content
version=${project.version}
artifactId=${project.artifactId}
Now turn on maven resource filtering
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
so that this file is processed into
target/classes/project.properties
with some content similar to this
version=1.5
artifactId=my-artifact
Now you can read this property file to get what you want and this should work every time.
final Properties properties = new Properties();
properties.load(this.getClassLoader().getResourceAsStream("project.properties"));
System.out.println(properties.getProperty("version"));
System.out.println(properties.getProperty("artifactId"));
An easy solution with maven 4 is now to add a VersionUtil static method in your package:
package my.domain.package;
public class VersionUtil {
public static String getApplicationVersion(){
String version = VersionUtil.class.getPackage().getImplementationVersion();
return (version == null)? "unable to reach": version;
}
}
The thing is you need this ´mave-war-plugin´ in the project's pom, saying you want to add addDefaultImplementationEntries:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
...
Then call the VersionUtil.getApplicationVersion() from some place in your code.