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.
Related
I have a Java 18, JavaFX 18 Maven project which has a lot of libraries, beside the javaFX libraries, that needs to be included in the artifact. I want to create an artifact, a jar, which contains all dependencies. I started following this video to create the jar: https://www.youtube.com/watch?v=UKd6zpUnAE4
Summarizing my steps, and referring to the steps in the video:
In IntelliJ in Project Structure/Project Settings/Libraries I removed all Maven added libraries, and added C:\Program Files\Java\javafx-sdk-18.0.2\lib
After, in Run/Edit Configurations... I added a VM options, and in that window I added
--module-path "C:\Program Files\Java\javafx-sdk-18.0.2\lib"
--add-modules javafx.controls,javafx.fxml
After, in the video, "Ken" the host of the video creates a class, with a main() method, that runs the application original main() class. I did not need this step, because I already has a class that does the same.
After, File/Project Structure/Project Settings/Artifact/ I added a JAR/From modules with dependencies/ and I choose the class I recently created, and shortened the path until the source folder (src)
Following this step, after I clicked add (+), and added the content of "...javafx-sdk-18.0.2/bin" all dll's and everything (all files).
Here, at this point, separate from the video, I also created a folder named "jars" and put all Maven dependencies jars in that folder.
According to the video, after these steps, with a double click on the artifact the jar runs without a problem.
However, I needed I more step. My dependency jars are signed jars, so I needed to open the artifact with WinRAR and remove the *.SF, *.DSA and *.RSA files. Earlier this caused me problems so I followed the idea here: Invalid signature file digest for Manifest main attributes exception while trying to run jar file, and here: "Invalid signature file" when attempting to run a .jar
After this, everything should be fine, however not :( The jar doesn't run on double click. When I run it from command line, I receive the following error:
$ java -jar jHasher.jar
jan. 15, 2023 3:19:07 DU. com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module #3a178016'
javafx.fxml.LoadException:
unknown path:53
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2685)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2532)
at view.GUI.start(GUI.java:29)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:263)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
at javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:523)
at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:373)
at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:335)
at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:245)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:778)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2924)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2639)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at com.sun.javafx.fxml.ModuleHelper.invoke(ModuleHelper.java:102)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:259)
... 19 more
Caused by: java.lang.UnsupportedOperationException: Cannot resolve 'win10-document'
at org.kordamp.ikonli.AbstractIkonResolver.resolve(AbstractIkonResolver.java:61)
at org.kordamp.ikonli.javafx.IkonResolver.resolve(IkonResolver.java:73)
at org.kordamp.ikonli.javafx.FontIcon.setIconLiteral(FontIcon.java:251)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 22 more
I have searched the following error message. I also found some posts on StackOverflow, however they are not clear to me, and I was not able to fix this issue. Please, guide me how to proceed. All suggestions are highly appreciated.
After several hard day, I was able to create the executable jar. I'd like to share the know-how with you.
After 5th step, skipping the WinRAR for removing the *.SF, *.DSA and *.RSA files. I added maven-shade-plugin to my pom.xml. The shade plugin can automatically remove these unwanted files, but unfortunately by itself cannot create a runnable JAR, because throws again exceptions and doesn't run on double click (JavaFX 18 Maven IntelliJ: Graphics Device initialization failed for: d3d, sw Error initializing QuantumRenderer: no suitable pipeline found).
To avoid this exception and include the unlocated/missing JavaFX files we have to repack the already packed JAR. To do that, I used the spring-boot-maven-plugin. After setting up the plugins (code below), you have to run the plugins with maven in a correct order! My maven command was the following: mvn clean package spring-boot:repackage
That it, finally the created JAR (JAR of the JAR) can run on double click.
My pom.xml's corresponding parts:
Shade plugin setting:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>controller.Start</mainClass>
</transformer>
</transformers>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
The Spring-boot-maven-plugin setting (this should be placed outside the plugins section, at the very end of the pom.xml):
<pluginManagement>
<plugins>
<plugin>
<!-- mvn clean package spring-boot:repackage -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
controller.Start
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
Make sure to run the plugins in the correct order, as mentioned above! I found this resource very useful: https://www.baeldung.com/spring-boot-repackage-vs-mvn-package
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 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.
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 am a java beginner.
I am trying a Java program in a unix system.
I am getting the below error
Exception in thread "main" java.lang.ClassNotFoundException: com.sybase.jdbc.SybDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at reportToCSVg.main(reportToCSVg.java:13)
I know that in eclipse i can just add the jconn.jar to make it work. please advise me the equivalent i need to do such that whenever i run the program in the server, i had included the jar file which is in a another path
you can set the classpath as follow: http://www.ehow.com/how_4784820_set-classpath-eclipse.html
and put your jar file in your projects classpath .
or you can put your jar file as
Select the library and click "Edit" (left side of the window)
Click "User Libraries"
Select the library again and click "Add JARs"
http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)
You can use Maven to package your -jar file containing all the dependencies if you are using Maven.
If you are using plain Eclipse with Ant -Just use the Fat-jar Plugin.
For Maven add the assembly plugin to pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>app.runner.Runner</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
For the Maven goal use the below -
maven assembly:single