I'm getting the following error when trying to run my jar file on the command line:
$ java -jar target/Controller-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.vismark.Controller.App.main(App.java:11)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
The project runs just fine on eclipse, but this error shows up when running it via commandline.
Below is my pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vismark</groupId>
<artifactId>Controller</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Controller</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.vismark.Controller.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
I'm likely missing something in my pom, I;m just not sure what it is. Where did I go wrong?
You most likely want to package an executable JAR. Since you are using Spring Boot you should follow chapter 71. Spring Boot Maven Plugin which explains how to do it using Spring Boot Maven Plugin.
Normally this is done by adding following build configuration to your pom.xml which be trigger during package phase.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
As a note you are using ancient JUnit 3.8.1, you really should upgrade.
Related
I have created a simple SpringBoot project using maven and my only class present is App.java containing
package com.mycompany.app;
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
#RestController
public class App {
// Logger logger = LoggerFactory.getLogger(App.class);
#GetMapping("/test-docker")
public String getData() {
return "in docker tutorial project of example";
}
public static void main( String[] args )
{
// System.out.println("SOP method");
SpringApplication.run(App.class, args);
}
}
This is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
<build>
<!-- <pluginManagement>lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<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>com.mycompany.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!-- </pluginManagement> -->
</build>
</project>
When I do a mvn install, the jar file is created in my target directory. When I run the following command,
java -jar target/my-app-1.0-SNAPSHOT.jar
I get the error:
lrd72218673:my-app subnara$ java -jar target/my-app-1.0-SNAPSHOT.jar
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.IllegalArgumentException: Unable to load factories from location [META-INF/spring.factories]
at org.springframework.core.io.support.SpringFactoriesLoader.loadSpringFactories(SpringFactoriesLoader.java:151)
at org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(SpringFactoriesLoader.java:122)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:428)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:420)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:268)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:249)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.mycompany.app.App.main(App.java:24)
... 8 more
Caused by: java.io.IOException: Unable to open root Jar file 'file:/Users/subnara/Documents/Code/DevOps/MicroServices+Docker+Kubernetes/Sample/my-app/target/lib/spring-boot-actuator-autoconfigure-2.1.0.RELEASE.jar'
at org.springframework.boot.loader.jar.Handler.getRootJarFile(Handler.java:344)
at org.springframework.boot.loader.jar.Handler.getRootJarFileFromUrl(Handler.java:325)
at org.springframework.boot.loader.jar.Handler.openConnection(Handler.java:99)
at java.base/java.net.URL.openConnection(URL.java:1126)
at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:170)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:133)
at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:122)
at org.springframework.core.io.support.SpringFactoriesLoader.loadSpringFactories(SpringFactoriesLoader.java:139)
... 16 more
Caused by: java.lang.IllegalArgumentException: File /Users/subnara/Documents/Code/DevOps/MicroServices Docker Kubernetes/Sample/my-app/target/lib/spring-boot-actuator-autoconfigure-2.1.0.RELEASE.jar must exist
at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.openIfNecessary(RandomAccessDataFile.java:234)
at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.<init>(RandomAccessDataFile.java:216)
at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.<init>(RandomAccessDataFile.java:206)
at org.springframework.boot.loader.data.RandomAccessDataFile.<init>(RandomAccessDataFile.java:49)
at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:88)
at org.springframework.boot.loader.jar.Handler.getRootJarFile(Handler.java:338)
... 23 more
I am a noob in this area and any help is much appreciated.
TL;DR: Use the spring-boot-maven-plugin maven plugin and take a look at https://start.spring.io/.
When I try to reproduce the problem:
create a folder with the specified pom.xml and App.java file in it
run mvn install in the folder
run java -jar target/my-app-1.0-SNAPSHOT.jar
I don't run into the problem.
Since we are using the same code (assuming your question contains the same code as you were using), I wonder whether the problem might be related to your version of Maven and Java. I am using Maven 3.6.3 and java 11.0.11.
That being said, I noticed the build configuration in your pom is rather complex. It can be simplified significantly using spring-boot-maven-plugin.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Since your issue seems to be related to missing libraries and this spring-boot plugin also handles adding these libraries to the generated jar, switching to this plugin might also solve your problems.
Since you mention you just created the project, I would like to suggest you take a look at https://start.spring.io/. It's a too to bootstrap new spring boot projects. One advantage, and the reason I'd suggest it to you, is that it generates a project that should work. You don't have to figure out which plugins or dependencies to add, the generator does that for you.
I'm building a small app with Maven that has dependencies and is an executable jar file.
Here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>site-downloader</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.company.siteripper</groupId>
<artifactId>common-interfaces</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.company.Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The build completes with no issues but when executing the jar it writes
no main manifest attribute, in local maven repo / my jar.
I sought aid at the docs and Baeldung too to no avail.
I seek assistance to make the jar include its dependencies and is executable at the same time.
Edit:
I updated my pom to use the jar and the dependencies plugins instead of the assembly. Here is the updated pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>site-downloader</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.company.siteripper</groupId>
<artifactId>common-interfaces</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
com.company.Main
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
But I get a NoClassDefFoundError when running it:
C:\Users\myusername\Documents\Commands>call java -jar
D:.m2\repository\com\company\site-downloader\1.0.0\site-downloader-1.0.0.jar
-9gag https://9gag.com/gag/arGEvRX?ref C:\Users\myusername\Documents\sites\data\android Error: A JNI error
has occurred, please check your installation and try again Exception
in thread "main" java.lang.NoClassDefFoundError:
org/openqa/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException:
org.openqa.selenium.WebDriver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
To create an executable jar, you have to use the following maven jar plugin. I provide below the code snippet.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
your main class
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
For more details, refer below the github link to get an idea of how to create executable/runnable jar.
https://github.com/debjava/runnableJar
As per docs, Maven Assembly Plugin for Maven is primarily intended to
allow users to aggregate the project output along with its
dependencies, modules, site documentation, and other files into a
single distributable archive.
Refer below the details of Maven Assembly plugin.
http://maven.apache.org/plugins/maven-assembly-plugin/
This is how I solved your issue:
Please ignore business logic,
since I am using MongoDB, added MongoDB driver as a dependency and able to run with java -jar command.
The end goal is same as of yours.
I am using maven-shade plug-in.
Checkout project from Github source code:
unzip, build, test
OR
1. Created a maven project
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4
Update pom.xml with following, added mongo client code from OP and printing collection names
Execute
mvn clean package
Execute
java -jar test.jar
output I got is:
INFO: Opened connection [connectionId{localValue:1, serverValue:9}] to localhost:27017
Jun 01, 2019 8:17:22 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 0, 5]}, minWireVersion=0, maxWireVersion=7, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=2249770}
Jun 01, 2019 8:17:22 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:2, serverValue:10}] to localhost:27017
admin
config
local
test
[XenonSuite] Successfully connected to MongoDB
pom.xml(ignore package names)
Check shade plugin configuration
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>test</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<mainClass>test.App</mainClass>
</properties>
<packaging>jar</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.10.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>test.App</mainClass>
</transformer>
</transformers>
<finalName>test</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
There are multiple ways to solve this problem
Ref: https://www.baeldung.com/executable-jar-with-maven
I created a simple Maven project on a rasberry pi and my project connects to a mysql database to be able to insert in, so to handle the dependencies and the plugins I have this pom.xml but when I try to make mvn package I have the following error knowing that it worked a first time and that it did well insert in my database I tried to look at several examples on the internet without result. thank you in advance
The error:
[ERROR] Plugin org.apache.maven.plugins:maven-surefire-plugin:2.17 or
one of its dependencies could not be resolved: Failed to read
artifact descriptor for
org.apache.maven.plugins:maven-surefire-plugin:jar:2.17: 1 problem
was encountered while building the effective model for
org.apache.maven.plugins:maven-surefire-plugin:[unknown-version]
[ERROR] [FATAL] Non-parseable POM
/home/pi/.m2/repository/org/apache/apache/13/apache-13.pom: comment
started on line 3 and column 5 was not closed (position:
START_DOCUMENT seen ...\ufffd\u63D\ufffd\u1\u4
\ufffd\ufffd2/\ufffd\ufffd7\ufffd/\ufffd\u00\ufffd\ufffd\u3\u0
\ufffd\n\u0\u0\ufffd\u3\u0
\ufffd\u0\u0\ufffd\ufffd$\u40d\ufffd\ufffd\ufffd\ufffd\ufffd\u40\ufffd\ufffd\u3\u0\u13\ufffdI\ufffd\ufffd\u1a\u0\u0U\ufffd\ufffd\ufffd\u1au\ufffd...
#81:40) caused by: java.io.EOFException: no more data available
START_DOCUMENT seen ...\ufffd\u63D\ufffd\u1\u4
\ufffd\ufffd2/\ufffd\ufffd7\ufffd/\ufffd\u00\ufffd\ufffd\u3\u0
\ufffd\n\u0\u0\ufffd\u3\u0
\ufffd\u0\u0\ufffd\ufffd$\u40d\ufffd\ufffd\ufffd\ufffd\ufffd\u40\ufffd\ufffd\u3\u0\u13\ufffdI\ufffd\ufffd\u1a\u0\u0U\ufffd\ufffd\ufffd\u1au\ufffd...
#81:40 # /home/pi/.m2/repository/org/apache/apache/13/apache-13.pom,
line 81, column 40
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>csRunBI</groupId>
<artifactId>csRunBi</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<properties>
<jodatime.version>2.5</jodatime.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
<build>
<finalName>csRunProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<!-- Jar file entry point -->
<addClasspath>true</addClasspath>
<mainClass>Main</mainClass>
<classpathPrefix>dependency-jars/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- exclude junit, we need runtime dependency only -->
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If you are calling the variable jdk.version with ${jdk.version} you should define it in your pom.xml. You can simply add the new variable between your <properties>...</properties> tag like it:
<properties>
<jodatime.version>2.5</jodatime.version>
<log4j.version>1.2.17</log4j.version>
<jdk.version>1.8</jdk.version>
</properties>
You can read more about the pom properties: pom properties documentation
I have my Storm application (maven) project structured as follow:
parent-project/
├── pom.xml
├── storm-application/
└── pom.xml
├── utils/
└── pom.xml
I structured my pom.xml files as follow:
parent-project:pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>utils</module>
<module>storm-application</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
storm-application:pom.xml
<parent>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>my.project.parent-project</groupId>
<artifactId>storm-application</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>my.project.parent-project</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> ...storm dependency... </dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
utils:pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>my.project.parent-project</groupId>
<artifactId>utils</artifactId>
<packaging>jar</packaging>
<dependencies>
... some project related dependencies ...
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
</build>
My objective would be to include the sibling module utilsin storm-application.
I need to include the module utils directly in the jar package of the storm-applicationmodule.
In fact, if I run the main function directly from IntelliJ it works, because it recognize the project structure, but if I try to deploy the application with Storm I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: my/project/parent-project/utils/MyClass
at my.project.parent-project.storm-application.MainClass.main(MainClass.java:116)
Caused by: java.lang.ClassNotFoundException: my.project.parent-project.utils.MyClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
I even tried to use the maven-assembly-plugin to include all the dependency in the package but I still get the same error.
Update
So what I was missing was that the assembly creates a second jar on the form name-version-jar-with-dependencies.
Plus, the storm dependency should be of <scope>provided</scope> otherwise it complains.
Still, I'm wondering if there would be an easier way to achieve this inter-module dependency.
I found a cleaner way to do so. Instead of using the assembly plugin, I use the shade plugin, so that the fat jar keeps the standard name.
Finally, this is the storm-application/pom.xml that, for me, works:
<parent>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>my.project.parent-project</groupId>
<artifactId>storm-application</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>my.project.parent-project</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> ...storm dependency... </dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have found this solution on stackoverflow. Warning - Build path specifies execution environment J2SE-1.4
I am getting almost the same problem but instead of 1-4 i am having 1-6. Unfortunately I don't really understand this configuration thing. It's new thing to me. I am trying second answer to get this working. I found this pom.xml in src under my project and it's xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.jpereira.trainings.designpatterns.creational.singleton</groupId>
<artifactId>singleton</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>singleton</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Configure Build Process -->
<build>
<plugins>
<!-- Compiler plugin to use Java 1.6 compatiblity -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Eclipse plugin to force download of source and JavaDoc jars -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
What and where should I add sth? I am using Eclipse on Windows 7. My version of java is: 1.8.0.25-b18 Words like plugin and Maven and JUnit are highlighted red. I would be grateful for help!
Try
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
And then regenerate the Eclipse project with mvn eclipse:eclipse.