I am trying to run my Spring Boot application through the command line but I am getting this error
MigrationsApplication.java:3: error: package org.springframework.boot does not exist
import org.springframework.boot.SpringApplication;
^
MigrationsApplication.java:4: error: package org.springframework.boot.autoconfigure does not exist
import org.springframework.boot.autoconfigure.SpringBootApplication;
^
MigrationsApplication.java:8: error: cannot find symbol
#SpringBootApplication
^
symbol: class SpringBootApplication
MigrationsApplication.java:15: error: cannot find symbol
SpringApplication.run(MigrationsApplication.class, args);
^
symbol: variable SpringApplication
location: class MigrationsApplication
4 errors
when I try to build it using the command javac MigrationsApplication.java
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 https://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.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.migrations</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Migrations</name>
<description>Demonstration of some migrations</description>
<properties>
<java.version>15</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<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-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Main Class
package com.migrations.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.IOException;
#SpringBootApplication
public class MigrationsApplication {
public static void main(String[] args) {
//if entered the command run in the command line
SpringApplication.run(MigrationsApplication.class, args);
//if entered the command create in the command line
/*MigrationGenerator generator=new MigrationGenerator();
try {
generator.generateMigrationFile("TEST2");
} catch (IOException e) {
System.out.println("There was an error generating the file");
}*/
}
}
I also have this "error " Select Run/Debug Configuration
How can I fix this? Maybe I imported my project from start.io in a wrong way or is it because I don't have Maven installed?
Updating 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 https://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.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.migrations</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MigrationsApp</name>
<description>Migrations</description>
<properties>
<java.version>15</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<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-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.company.common</groupId>
<artifactId>common-files</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>migrations.MigrationsAppApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This will not work. Because If one class is dependent on another class that hasn't been compiled yet, the program won't run
javac *.java // compliles all java files in the dir
java MigrationsApplication // runs the particular file
So you should compile all files before trying to run the program dependent on other files.
If your files are packaged, then something like this
javac com.mypackage/.*java
java com.mypackage.MigrationsApplication
For Error in your debug configuration, Check what is missing or wrongly provided in the configuration.
Also, I suggest to create a sprint boot project and run it as a Spring boot JAR from the command line either or from the IDE itself
To run it as a JAR:
java -jar target/your.jar
Related
I am trying my hand at creating tests for my Spring boot app using Spock/Groovy. I am following a guide, and the first test is to test whether all the beans are created. I auto wired one of my controller classes, ChannelController, and expected it to be created. However, the test is showing that it's actually null. I created some other simple tests in the test file (1 + 1 == 2) and they all run and pass. Can anyone help me out?
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 https://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.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>magic_eight_ball</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>magic_eight_ball</name>
<description>REST Api for Magic Eight Ball</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
My Specification.groovy file:
package com.example.magic_eight_ball
import com.example.magic_eight_ball.controller.ChannelController
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Specification
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.web.servlet.MockMvc
#SpringBootTest
class FirstSpecification extends Specification {
#Autowired
ChannelController channelController
def "when context is loaded then all expected beans are created"() {
expect: "the ChannelController is created"
channelController
}
}
My directory structure for the test file is: src/test/groovy/com/example/magic_eight_ball/Specification.groovy
My directory structure for the ChannelController class is:
src/main/java/com/example/magic_eight_ball/controller/ChannelController.java
You included spock-core as a dependency, but not spock-spring. Change your dependency to say spock-spring instead, and your test should work.
is it possible?
I want to create stub server for smoke testing with features:
on build it gets contracts of multiple rest applications from git repository, build stubs and push them back to repository as jsons
on startup it gets stub jsons from repository and run them
I tried this:
main class:
#SpringBootApplication
#EnableStubRunnerServer
public class SpringCloudStubRunnerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudStubRunnerApplication.class, args);
}
}
application.yaml:
server:
port: 8080
stubrunner:
stubsMode: REMOTE
repositoryRoot: git://git#github.com:Granomir/spring-cloud-config-stubs.git
ids:
- ru.mts.poisk:my-content-adapter:+:stubs:8090
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 https://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.4.3</version>
<relativePath/>
</parent>
<groupId>ru.mts.poisk</groupId>
<artifactId>spring-cloud-stub-runner</artifactId>
<version>1.0-S1-SNAPSHOT</version>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-stub-runner</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<version>2.2.6.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>2.2.6.RELEASE</version>
<extensions>true</extensions>
<configuration>
<contractsRepositoryUrl>git://git#github.com:Granomir/spring-cloud-config-stubs.git</contractsRepositoryUrl>
<contractDependency>
<groupId>${project.groupId}</groupId>
<artifactId>my-content-adapter</artifactId>
<version>${project.version}</version>
</contractDependency>
<contractsMode>REMOTE</contractsMode>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>pushStubsToScm</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I 'mvn clean install -DskipTests' for generating stubs than I have following in log:
[INFO] Pattern to pick contracts equals [^/tmp/git-contracts-1614681706091-0/META-INF/ru.mts.poisk/my-content-adapter/1.0-S1-SNAPSHOT(/)?.*ru/mts/poisk/spring-cloud-stub-runner/.*$]
[INFO] Ant Pattern to pick files equals [**/ru/mts/poisk/spring-cloud-stub-runner/**/]
so my app doesn't generate stubs and has nothing to push back, because I have another directory structure in git
I have a micro-service based application that I am building out locally. I have a situation where micro-service A is depending on micro-service B and as such I have included B in A's pom as a dependency and there are no errors in the code and all of the classes are recognized. However, when I go to do a 'mvn clean install' command on A, I get the error where none of the packages in B are recognized as well as 'Cannot find symbol' for all of the classes from B that I am trying to use in A.
I have tried changing the execution goal of the maven plugin to 'repackage' in the pom of B like:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have also confirmed that the JAR file is getting correctly built out to my local maven repository in my .m2 folder and made sure that the classes and code is contained there.
I also have tried breaking down the maven commands into sub-commands instead of just doing a maven clean install
POM for MS A
<?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.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.oz</groupId>
<artifactId>franchise-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>oz-franchise-api</name>
<description>API for FRP</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SPRING WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- DATABASE/JPA BACKEND -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- USEFUL TOOLS -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- OTHER OZ DEPENDENCIES -->
<dependency>
<groupId>com.oz</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
POM for MS B
<?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.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.oz</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>oz-core-library</name>
<description>The core library for oz</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SPRING BOOT -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- DATABASE/JPA BACKEND -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MYSQL DATABASE -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<!-- JAVAX VALIDATION -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- LOMBOK -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If your two microservices both need a set of classes, put that classes into a separate (third) jar, build it as normal jar and use it as dependency in both.
I'm having issues when I run my application as a java application.
I've tried various solutions but with no success.
I still get the following message:
Could not find or load main class com.alliacom.audit.AuditApplication
This is the 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>
<groupId>com.alliacom</groupId>
<artifactId>audit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>audit</name>
<description>Alliacom auditing tool</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>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>lightadmin-nexus-releases</id>
<url>http://lightadmin.org/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.alliacom.audit.AuditApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
and this is my main application,
AuditApplication.java
package com.alliacom.audit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
#SpringBootApplication
#EnableJpaAuditing
public class AuditApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(AuditApplication.class, args);
}
}
The project seems fine,
there are no errors during build,
but I don't see the cause of the problem.
The fastest solution, since your pom is very small:
Got to Spring Initializer: https://start.spring.io/
Generate a new Maven / Java / SpringBoot 2.0 project.
run it and check your system is fine
start adding your customizations one at a time, and try after each modification.
In few minutes you'll have found the culprit.
Try removing the following from your pom file (it is not needed):
<configuration>
<mainClass>com.alliacom.audit.AuditApplication</mainClass>
</configuration>
You need to use the plugin like this
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
I am migrating my old Spring setup to Spring Boot 1.5.1.RELEASE.
I'm failing to get an executable .jar, I followed countless examples but my jar fails to become an executable.
It's a multi-module setup so here is my parent 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz</artifactId>
<name>xyz</name>
<version>1.0.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<commons.version>3.5</commons.version>
<guava.version>21.0</guava.version>
</properties>
<modules>
<module>mainApp</module>
<module>module1</module>
<module>module2</module>
..........
</modules>
<dependencyManagement>
<dependencies>
<!-- Spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<!-- google guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
This is the pom of the mainApp, it is the module that has Application.java which holds main method.
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xyz</artifactId>
<groupId>com.xyz</groupId>
<version>1.0.0</version>
</parent>
<artifactId>mainApp</artifactId>
<groupId>com.xyz.mainApp</groupId>
<packaging>jar</packaging>
<name>mainApp</name>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Security OAuth2-->
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<!-- xyz dependencies -->
<dependency>
<groupId>com.xyz.module3</groupId>
<artifactId>module3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.xyz.module2</groupId>
<artifactId>module2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>xyz</finalName>
</build>
</project>
Things that work:
So things work okay when I do mvn clean install in the folder of parent pom.xml and then run mvn spring-boot:run in the mainApp folder
Things that fail:
when I execute java -jar mainApp/target/xyz.jar I get an error like:
no main manifest attribute, in mainApp/target/xyz.jar
if I attempt to run the jar like ./mainApp/target/xyz.jar, well I can't as the file is not an executable, my macOS Sierra terminal shows this for file permissions:
-rw-r--r-- 1 userXYZ staff 37641156 Feb 1 13:14 xyz.jar
If I manually change the permissions to -rwxr--r-- and attempt to run the file I get this gibberish:
/xyz.jar: line 1: PK: command not found
./xyz.jar: line 2: syntax error near unexpected token `)'
./xyz.jar: line 2: ?iAJ META-INF?iAJMETA-INF/MANIFEST.MFu??J?0??y?y??,??nW*???Jb3?F?LI?????qa?n?3???)Mp5&V????ñ^IQ?????ޱ?.#??`?$?{<??7?m6?j܀?W????'????γڎ9?>????RT?͡?V??
G??
3iR?G4???dә?A(̀?z?ϖV]ٷ??T??O>?^??0wy?u?^??S]?iG?2?"???i?$?'
The problem is not how the plugin is configured, but where the plugin is configured.
I have wrapped my plugins with <pluginManagement>, which was causing all the problems, when i removed it all was resolved and worked perfectly
update your build block in pom.xml with following, make sure you are using using Maven 3.2 (or better):
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
the main class entry is missing in the jar manifesto.
Please modify the boot maven plugin as below:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Plugin info