I generate exectuable jar then tries to run it in cmd java xml-generator.jar
unfortunately but I have Error: Could not find or load main class xml-generator.jar
pom.xml file with dependecies, which I used in this project
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.example.XMLGenerator</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.XMLGenerator</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
edit* thanks to maven-shade-plugin, two jar files are generated for me in the target directory.
MANIFEST.MF file
Manifest-Version: 1.0
Main-Class: XMLGenerator
exectuable jar is generated by IntelliJ IDE, any idea how to fix it?
xml-generator (module)
-.idea
-src
--main
---java
----META-INF
-----MANIFEST.MF
----XMLGenerator.class
-target
--xml-generator-1.0-SNAPSHOT (generated jar)
pom.xml
java xml-generator.jar
tells Java to launch the class named xml-generator.jar
on the default classpath, which most likely is not what you want.
The option to launch an executable jar is -jar
, and the jar is generated by Maven, so in your case that would be
java -jar target/xml-generator-1.0-SNAPSHOT.jar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.