I am trying to create shaded jar for my spring project with bellow pom.xml, which runs fine in IDE but when I run mvn clean package and execute the jar with java -jar .\flink-0.0.1-SNAPSHOT-test.jar I am getting:
Your project setup is incompatible with our requirements due to
following reasons:
Spring Boot [0.0.1-SNAPSHOT] is not compatible with this Spring Cloud release train
Change Spring Boot version to one of the following versions [2.6.x, 2.7.x] .
I checked spring cloud compability matrix where spring cloud 2021.0.x is compatible with spring boot 2.6.x.
<groupId>com.example</groupId>
<artifactId>flink</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>flink</name>
<description>flink</description>
<properties>
<spring-cloud.version>2021.0.1</spring-cloud.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.8</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>test</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.Application</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Project currently contain only single Main Class:
#SpringBootApplication
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
}
Shading the jar means that the version compatibility that checks the manifest is broken. Set spring.cloud.compatibility-verifier.enabled=false
Related
I am trying to read from Kafka. My issue is exactly similar to the one discussed here. My code and pom.xml is very similar too. For me, the code runs perfectly fine in my local machine. But the same code fails when I build Uber jar and run it in Dataproc cluster. I have tried all the suggestions discussed on the original post. But none of them helps.
I get the below error:
Failed to find data source: kafka. Please deploy the application as per the deployment section of "Structured Streaming + Kafka Integration Guide"
Can someone please help?
Spark Version: 2.4.8
Scala Version: 2.12
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>*****</groupId>
<artifactId>*****</artifactId>
<version>****</version>
<name>${project.artifactId}</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Scala Version-->
<scala.version>2.12.10</scala.version>
<scala.major.version>2.12</scala.major.version>
<!-- Spark/Hadoop Version-->
<spark.version>2.4.8</spark.version>
<!-- Open Source Dependencies -->
<google.cloud.libraries.bom.version>16.2.0</google.cloud.libraries.bom.version>
<cloud.bigdataoss.gcs.connector.version>hadoop2-2.1.3</cloud.bigdataoss.gcs.connector.version>
<google.spark.bigquery.version>0.19.1</google.spark.bigquery.version>
<commons.io.version>2.4</commons.io.version>
<protobuf.java.version>3.14.0</protobuf.java.version>
<com.google.guava.version>30.1-jre</com.google.guava.version>
<google-cloud-storage.version>1.79.0</google-cloud-storage.version>
<!-- Plugin Versions-->
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.deploy.plugin.version>2.8.2</maven.deploy.plugin.version>
<maven.release.plugin.version>2.5.3</maven.release.plugin.version>
<maven.site.plugin.version>3.9.1</maven.site.plugin.version>
<scalatest.maven.plugin.version>1.0</scalatest.maven.plugin.version>
<maven.source.plugin.version>3.2.0</maven.source.plugin.version>
<dependencyManagement>
<!-- reference : https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM -->
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>${google.cloud.libraries.bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.major.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.major.version}</artifactId>
<version>${spark.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql-kafka-0-10 -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql-kafka-0-10_${scala.major.version}</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.typesafe.scala-logging/scala-logging -->
<dependency>
<groupId>com.typesafe.scala-logging</groupId>
<artifactId>scala-logging_2.12</artifactId>
<version>3.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.holdenkarau/spark-testing-base -->
<dependency>
<groupId>com.holdenkarau</groupId>
<artifactId>spark-testing-base_2.12</artifactId>
<version>2.4.7_1.1.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-secretmanager -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-secretmanager</artifactId>
<!--<version>2.0.4</version>-->
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.mrpowers/spark-fast-tests -->
<dependency>
<groupId>com.github.mrpowers</groupId>
<artifactId>spark-fast-tests_2.12</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.auth/google-auth-library-oauth2-http -->
<!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>[${protobuf.java.version}]</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
<version>[${com.google.guava.version}]</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>${google-cloud-storage.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.bigdataoss</groupId>
<artifactId>gcs-connector</artifactId>
<version>${cloud.bigdataoss.gcs.connector.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.spark</groupId>
<artifactId>spark-bigquery-with-dependencies_${scala.major.version}</artifactId>
<version>0.22.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- Added to enable jar creation using mvn command-->
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<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>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<excludes>
<exclude>org.scalactic:*</exclude>
<exclude>org.scalatest:*</exclude>
<exclude>org.apache.spark:*</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.org.mainClass</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>META-INF/services</resource>
<file>io.grpc.LoadBalancerProvider</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>META-INF/services</resource>
<file>io.grpc.NameResolverProvider</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<!-- <exclude>META-INF/maven/**</exclude>-->
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>**/logback.xml</exclude>
<exclude>**/log4j.properties</exclude>
<exclude>module-info.class</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com</pattern>
<shadedPattern>repackaged.com</shadedPattern>
<includes>
<include>com.microsoft.**</include>
<include>com.google.common.**</include>
<include>com.google.protobuf.**</include>
</includes>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.5.6</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
</project>
I created a jar using maven spring boot plugin and tried to run the jar using java -jar App.jar. The main file is configured with Spring boot and when I tried package it start the jar I am getting error as -
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.database.DatabaseApplication.main(DatabaseApplication.java:12)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
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)
... 1 more
This indicated that the dependency jar is missing in the packaged jar. I tried looking for various solutions on the web but to my failure none worked for me. I check the answer NoClassDefinitonFound and Package dependency jar but it did not work and I ended up getting the same error everytime. Below is the build section of my pom. Can anyone please help ?
Current configuration
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>${start-class}</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Other configurations
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${start-class}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<build>
<plugins>
<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}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>${start-class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
Below is the pom.xml file without build added -
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.database</groupId>
<artifactId>Database</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>Database application </name>
<description>Database operations application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<start-class>com.database.App</start-class>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
</dependencies>
<build>
...
</build>
I want to package dependencies into the jar file created after running mvn clean package. Using terminal to build the application and not building it using eclipse.
Please, use this configuration for build section in your pom.xml.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I have a parent maven project SampleProject and it has two modules Sample1 and Sample2. The SampleProject has a main method, how to create an executable jar for SampleProject so that it executes the main method
Pom.xml for SampleProject is:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.test.sample</groupId>
<artifactId>SampleProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>SampleProject</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.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.7</version>
</dependency>
<dependency>
<groupId>sample</groupId>
<artifactId>com.sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\\Users\\pchand\\Desktop\\ExtentReport-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>
</dependencies>
<modules>
<module>Sample1</module>
<module>Sample2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test.sample.SampleProject.Runner</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Hi im a bit new to heroku. The app works fine on local but on heroku i get this error when trying to do a rest request on a controller
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>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
<name>testing</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>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
</dependencies>
<build>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.Application</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>src/main/jwebapp</warSourceDirectory>
<warName>gs-maven-0.1.0</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
<processTypes>
<web>
java $JAVA_OPTS -cp target/classes:target/dependency/* Application
</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>
</project>
error logs here
LOGS
2016-10-22T07:30:13.637732+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-10-22T07:30:13.637732+00:00 heroku[web.1]: State changed from crashed to st
arting
2016-10-22T07:30:18.085285+00:00 heroku[web.1]: Starting process with command `j
ava -Dserver.port=17355 $JAVA_OPTS -jar target/*.jar`
2016-10-22T07:30:19.552462+00:00 heroku[web.1]: Process exited with status 1
2016-10-22T07:30:19.559097+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-10-22T07:30:19.499662+00:00 app[web.1]: Create a Procfile to customize the
command used to run this process: https://devcenter.heroku.com/articles/procfile
2016-10-22T07:30:19.503097+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults
based on dyno size. Custom settings will override them.
2016-10-22T07:30:19.503942+00:00 app[web.1]: Error: Unable to access jarfile tar
get/*.jar
2016-10-22T07:30:39.331500+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=waisserver.herokuapp.com request_id=4249b569-93d2
-4257-adc2-3ddf8577e4fd fwd="188.172.153.178" dyno= connect= service= status=503
bytes=
Thanks Alex. The Spring boot guide worked. For the record my pom.xml file looks like this now and i didnt even need a procfile.
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>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<name>testing</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
</dependencies>
<build>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.Application</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>src/main/jwebapp</warSourceDirectory>
<warName>gs-maven-0.1.0</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
<processTypes>
<web>
java $JAVA_OPTS -cp target/classes:target/dependency/* Application
</web>
</processTypes>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
We see the following in your logs:
Starting process with command java -Dserver.port=17355 $JAVA_OPTS -jar target/*.jar
...
Error: Unable to access jarfile target/*.jar
heroku-maven-plugin
I've only used Procfile in the past, but I see that you can also use heroku-maven-plugin to specify the startup command (heroku documentation).
I believe you need to set the <processType> tag in heroku-maven-plugin rather than maven-war-plugin:
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<configuration>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* Application</web>
</processTypes>
</configuration>
</plugin>
Then, deploy with this command: mvn heroku:deploy -Dheroku.appName=myapp
Spring Boot ?
On top of that, I see the dependency spring-boot-starter-web. Is this a spring-boot app ? Then, you shouldn't have the maven-war-plugin and rather build a valid spring-boot archive using spring-boot-maven-plugin (see this example)
If you go down the spring-boot route, you could build it as a Jar and use the following Procfile (placed at the root of your project, with capital P):
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/gs-maven-0.1.0.jar
I think you can wildcard the version, so you don't have to modify the Procfile continuously:
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/gs-maven-*.jar
Take a look at this: http://nicholaspaulsmith.com/spring-boot-on-heroku/
I am trying to compile an integration server using the springboot java framework. I am using Maven to compile a jar file, but I keep running into an issue with the way Maven stores jars in repositories.
The Jar I am working with is sapjco3.jar, which will crash on run (not package) because it neeeeds its name to be sapjco3.jar. Because the Maven repo naming convention is:
/%groupId%/%artifactId%/%version%/%artifactId%-%version%.jar
The library ends up being called sapjco3-3.0.jar.
Is there some way to pop my sapjco3.jar into my application without using a repository (I haven't been able to add it to the java.library.path or by editing the entries and xml in the ~/.m2 directory). Otherwise, is there a way to script renaming it once it is inserted??
My platform is ubuntu 14.04 LTS, by the way.
My POM file (missing the xml header, because StackOverflow doesn't parse it right):
<modelVersion>4.0.0</modelVersion>
<name>SampleIntegrationServer</name>
<description>Sample Integration Server</description>
<groupId>com.Sample</groupId>
<artifactId>SampleIntegrationServer</artifactId>
<packaging>jar</packaging>
<version>0.0.2</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud-aws-version>1.0.4.RELEASE</spring-cloud-aws-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
<version>${spring-cloud-aws-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-messaging</artifactId>
<version>${spring-cloud-aws-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>net.sf.jt400</groupId>
<artifactId>jt400</artifactId>
<version>6.7</version>
</dependency>
<dependency>
<groupId>com.sap</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.3.RELEASE</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<includeEmptyDirs>true</includeEmptyDirs>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
The crash:
Factory method 'createSapConnection' threw exception; nested exception is java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco3-3.0.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar".
I just want this to build!!
Thanks
I solved this problem with custom layout
import org.springframework.boot.loader.tools.Layouts.Jar;
public class ResistantToSapjco3JarLayout extends Jar implements CustomLoaderLayout {
#Override
public void writeLoadedClasses(LoaderClassesWriter writer) throws IOException {
// do Spring Boot defaults
writer.writeLoaderClasses();
URL jcoClassUrl = getClass().getClassLoader().getResource("com/sap/conn/jco/JCo.class");
if (jcoClassUrl == null) {
throw new IllegalStateException("No sapjco3 JAR on plugin classpath. "
+ "Make sure sapjco3 is added to spring-boot-maven-plugin dependency section");
}
if (!jcoClassUrl.toString().startsWith("jar:file")) {
throw new IllegalStateException("sapjco3 is not JAR");
}
JarURLConnection jarUrlConnection = (JarURLConnection) jcoClassUrl.openConnection();
JarFile sapjco3Jar = jarUrlConnection.getJarFile();
JarWriter jarWriter = (JarWriter) writer;
jarWriter.writeNestedLibrary("BOOT-INF/lib/",
new Library("sapjco3.jar", new File(sapjco3Jar.getName()), LibraryScope.COMPILE, false));
}
}
pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layoutFactory implementation="com.company.ResistantToSapjco3JarLayoutFactory" />
<excludeArtifactIds>sapjco3</excludeArtifactIds>
</configuration>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>resistant-to-sapjco3</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>sapjco3</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.13</version>
</dependency>
</dependencies>
</plugin>
ResistantToSapjco3JarLayoutFactory
public class ResistantToSapjco3JarLayoutFactory implements LayoutFactory {
#Override
public Layout getLayout(File source) {
return new ResistantToSapjco3JarLayout();
}
}
I solved the issue using shade plugin for maven. Having maven dependency for sapjco3 with scope provided:
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>${sapjco3.version}</version>
<scope>provided</scope>
</dependency>
Then the work is done by copying the library when shading and excluding it when the spring maven plugin adds it's version, so that we have the original one:
<build>
<finalName>price</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<includeArtifactIds>sapjco3</includeArtifactIds>
<includeTypes>jar</includeTypes>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>BOOT-INF/lib/sapjco3.jar</resource>
<file>sapjco3.jar</file>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.7.RELEASE</version>
<configuration>
<excludeGroupIds>com.sap.conn.jco</excludeGroupIds>
</configuration>
</plugin>
...