Shaded Jar in Springboot - java

I'm trying to build shaded jar in spring boot application but having some issues. I don't know what i'm doing wrong here. I also read the following links but no luck
maven-shade-plugin error: Cannot find setter, adder nor field in org.apache.maven.plugins.shade.resource.ManifestResourceTransformer for 'resource'
here is my 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>dashboard</groupId>
<artifactId>dashboard</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.2.7.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>jira.widgets</groupId>
<artifactId>jira-widgets</artifactId>
<version>0.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.5.RELEASE</version>
</parent>
<!-- Additional lines to be added here... -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.text.dashboard.hello.Application</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When i run mvn package then i got following exception on console
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building dashboard 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # dashboard ---
[INFO] Deleting C:\Users\confiz\Documents\workspace-sts-3.7.3.RELEASE\dashboard\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # dashboard ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) # dashboard ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\confiz\Documents\workspace-sts-3.7.3.RELEASE\dashboard\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # dashboard ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) # dashboard ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) # dashboard ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # dashboard ---
[INFO] Building jar: C:\Users\confiz\Documents\workspace-sts-3.7.3.RELEASE\dashboard\target\dashboard-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.1.5.RELEASE:repackage (default) # dashboard ---
[INFO]
[INFO] --- maven-shade-plugin:2.3:shade (default) # dashboard ---
[WARNING] Map in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer declares value type as: class java.util.jar.Attributes but saw: class java.lang.String at runtime
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.609 s
[INFO] Finished at: 2016-04-15T10:55:02+05:00
[INFO] Final Memory: 22M/224M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project dashboard: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.3:shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer -> [Help 1]
[ERROR]
Scenario is : i have two spring boot projects and both have same type which executable jar. I'm adding other project in this project as dependency. That's why i'm building a jar which have all the dependencies
Any suggestions?

I don't know why but it worked for me. Use just
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.text.dashboard.hello.Application</Main-Class>
</manifestEntries>
</transformer>
Instead of
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.text.dashboard.hello.Application</Main-Class>
</manifestEntries>
</transformer>
</transformers>

Related

error: cannot find symbol(Heroku Discord Bot)

I'm trying to make my Discord bot to work on Heroku but I keep getting an error. The build process works fine but the bot doesn't go online. I went to Resources --> More --> View Logs and saw an error. I understood the error as some methods not getting recognized and I removed the error one. But another one would just pop up. The code and bot works on local using IntelliJ. Anyone can help me with this please?
The error/Resource logs:
2021-04-18T23:58:17.202220+00:00 app[Worker.1]: location: class Main
2021-04-18T23:58:17.226725+00:00 app[Worker.1]: src/main/java/Main.java:9: error: cannot find symbol
2021-04-18T23:58:17.226770+00:00 app[Worker.1]: jda.setActivity(Activity.listening("!help"));
2021-04-18T23:58:17.226835+00:00 app[Worker.1]: ^
2021-04-18T23:58:17.226906+00:00 app[Worker.1]: symbol: variable Activity
2021-04-18T23:58:17.226942+00:00 app[Worker.1]: location: class Main
2021-04-18T23:58:17.228071+00:00 app[Worker.1]: 5 errors
2021-04-18T23:58:17.230942+00:00 app[Worker.1]: error: compilation failed
2021-04-18T23:58:17.336252+00:00 heroku[Worker.1]: Process exited with status 1
2021-04-18T23:58:17.440163+00:00 heroku[Worker.1]: State changed from up to crashed
Build/Deploy logs:
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/java
-----> Java app detected
-----> Installing JDK 15... done
-----> Installing Maven 3.6.2... done
-----> Executing Maven
$ mvn -DskipTests clean dependency:list install
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< org.example:CalciteDiscordBot >--------------------
[INFO] Building CalciteDiscordBot 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # CalciteDiscordBot ---
[INFO] Deleting /tmp/build_6a1072dc/target
[INFO]
[INFO] --- maven-dependency-plugin:2.8:list (default-cli) # CalciteDiscordBot ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # CalciteDiscordBot ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/build_6a1072dc/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # CalciteDiscordBot ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 21 source files to /tmp/build_6a1072dc/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # CalciteDiscordBot ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/build_6a1072dc/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # CalciteDiscordBot ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # CalciteDiscordBot ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # CalciteDiscordBot ---
[INFO] Building jar: /tmp/build_6a1072dc/target/CalciteDiscordBot-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # CalciteDiscordBot ---
[INFO] Installing /tmp/build_6a1072dc/target/CalciteDiscordBot-1.0-SNAPSHOT.jar to /tmp/codon/tmp/cache/.m2/repository/org/example/CalciteDiscordBot/1.0-SNAPSHOT/CalciteDiscordBot-1.0-SNAPSHOT.jar
[INFO] Installing /tmp/build_6a1072dc/pom.xml to /tmp/codon/tmp/cache/.m2/repository/org/example/CalciteDiscordBot/1.0-SNAPSHOT/CalciteDiscordBot-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.854 s
[INFO] Finished at: 2021-04-18T23:57:57Z
[INFO] ------------------------------------------------------------------------
-----> Discovering process types
Procfile declares types -> Worker
-----> Compressing...
Done: 76.7M
-----> Launching...
Released v23
https://calcitediscordbot.herokuapp.com/ deployed to Heroku
Main.java
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import javax.security.auth.login.LoginException;
public class Main {
public static void main(String[] args) throws LoginException {
JDABuilder jda = JDABuilder.createDefault("I inserted token here");
jda.setActivity(Activity.listening("!help"));
jda.build();
}
}
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>org.example</groupId>
<artifactId>CalciteDiscordBot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>15</maven.compiler.target>
<maven.compiler.source>15</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.0_246</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
</project>
Procfile:
Worker: java src/main/java/Main.java
If you run locally with an IDE like IntelliJ, it will handle things like this to you, but you need add a plugin to create a jar with dependencies before deploying it.
<?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>org.example</groupId>
<artifactId>CalciteDiscordBot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>...</properties>
<dependencies>...</dependencies>
<repositories>...</repositories>
<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>
Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
To fix this problem, you'd have to change the pom.xml and Procfile.
Add this line to the pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>MAIN_CLASS_PATH</mainClass>
<name>BOT_NAME</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
Add this inside of your plugins tag in your build tag. Change MAIN_CLASS_PATH to your own main class and change BOT_NAME to your project's/bot's name.
Change the Worker for the Procfile to this:
worker: sh target/bin/BOT_NAME
Same thing here ^, change BOT_NAME to your project's/bot's name.
Most credit goes to BooleanCube's Discord. And thank you #Kaneda for the help!

JUnit 5 tests are not firing and tests aren't showing in test runner

I am having trouble getting JUnit 5 tests to run on VSCODE. I believe my environment is set up properly. A clone of junit5-samples | junit5-jupiter-starter-maven builds and runs as expected. My project does not.
My project builds under maven but runs no tests. So this is probably a Maven or project configuration issue and not related to VSCODE.
I have tinkered with various ideas for a couple of hours to no avail. Something is different, probably a mistake and maybe additional pairs of eyes can find it. Any help you might provide will be greatly appreciated.
Here is some project information
'mvn clean package' runs without error, but no tests run. CodeLens is also not working.
Run Test|Debug Test is missing. No tests show up in test runner.
Here is my POM file with a few redactions:
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.redacted</groupId>
<artifactId>redacted</artifactId>
<packaging>jar</packaging>
<version>0.1.1</version>
<name>redacted</name>
<properties>
<skipTests>false</skipTests>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
</properties>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<!-- <skipTests>${skipTests}</skipTests> -->
</configuration>
</plugin>
<!-- <plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin> -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.3.6</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/WSDL/redacted.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here is the output from the mvn command:
[INFO]
[INFO] ------------------------< com.redacted:redactedClient >-------------------------
[INFO] Building redactedClient 0.1.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # redactedClient ---
[INFO] Deleting D:\repos\redacted\redactedClient\target
[INFO]
[INFO] --- cxf-codegen-plugin:3.3.6:wsdl2java (generate-sources) # redactedClient ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # redactedClient ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\repos\redacted\redactedClient\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # redactedClient ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to D:\repos\redacted\redactedClient\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # redactedClient ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\repos\redacted\redactedClient\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # redactedClient ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\repos\redacted\redactedClient\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # redactedClient ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.444 s
[INFO] Finished at: 2020-04-26T09:55:55-07:00
[INFO] ------------------------------------------------------------------------
A test method should have the return type void whereas your test method GetModList() has Boolean.
In JUnit Jupiter you can remove public from the test class also from all test methods.

ERROR: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy 405,

With maven, I want to deploy this project locally with all the dependencies to the tomcat server. But I get some errors. I use the operating system archlinux and tomcat installed in the "/opt" directory.
Java version: "11.0.2" 2019-01-15 LTS
Maven version:3.0.6
Tomcat version:9.0.17
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>TomcatServer</id>
<username>onur</username>
<password>onur123</password>
</server>
</servers>
<profiles>
<profile>
<properties>
<tomcathome>/opt/apache-tomcat-9.0.17</tomcathome>
</properties>
<repositories>
<repository>
<id>DefaultRepo</id>
<url>http://localhost:8080/estech</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>
</settings>
This is my pom.xml. I use maven deploy plugin for deploy to tomcat server. How can I fix this?
<?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.pmyo.group5</groupId>
<artifactId>estech</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<distributionManagement>
<repository>
<id>DefaultRepo</id>
<name>localhost</name>
<url>http://localhost:8080/estech/</url>
</repository>
</distributionManagement>
<name>estech Maven Webapp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<finalName>estech</finalName>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<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-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Error:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.pmyo.group5:estech >-----------------------
[INFO] Building estech Maven Webapp 1.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # estech ---
[INFO] Deleting /home/onur/IdeaProjects/Es-tech/estech/target
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # estech ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/onur/IdeaProjects/Es-tech/estech/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # estech ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 21 source files to /home/onur/IdeaProjects/Es-tech/estech/target/classes
[INFO] /home/onur/IdeaProjects/Es-tech/estech/src/main/java/Models/ProductComments.java: Some input files use or override a deprecated API.
[INFO] /home/onur/IdeaProjects/Es-tech/estech/src/main/java/Models/ProductComments.java: Recompile with -Xlint:deprecation for details.
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) # estech ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/onur/IdeaProjects/Es-tech/estech/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) # estech ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) # estech ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:3.2.2:war (default-war) # estech ---
[INFO] Packaging webapp
[INFO] Assembling webapp [estech] in [/home/onur/IdeaProjects/Es-tech/estech/target/estech]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/onur/IdeaProjects/Es-tech/estech/src/main/webapp]
[INFO] Webapp assembled in [152 msecs]
[INFO] Building war: /home/onur/IdeaProjects/Es-tech/estech/target/estech.war
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-cli) # estech ---
Uploading to DefaultRepo: http://localhost:8080/estech/com/pmyo/group5/estech/1.0/estech-1.0.war
Uploading to DefaultRepo: http://localhost:8080/estech/com/pmyo/group5/estech/1.0/estech-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.847 s
[INFO] Finished at: 2019-05-02T19:48:25+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-cli) on project estech: Failed to deploy artifacts: Could not transfer artifact com.pmyo.group5:estech:war:1.0 from/to DefaultRepo (http://localhost:8080/estech/): Failed to transfer file http://localhost:8080/estech/com/pmyo/group5/estech/1.0/estech-1.0.war with status code 405 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
maven-deploy-plugin is not for deploying your WAR into Tomcat. It is used to transfer build artifacts into repository.
You should take a look at tomcat-maven-plugin or cargo-maven-plugin

No test found with Maven + JUnit + Eclipse

I'm triying to generate a .war with my Eclipse project and Maven. When I'm going to execute the task "mvn test" Maven don't execute/find any of my test:
C:\eclipseJava\workspace\myproject>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject0.1
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.sun:tools:jar:1.4.2 is missing, no dependency informat
ion available
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocate
d to commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # myproject
---
[debug] execute contextualize
[INFO] Using 'utf-8' encoding to copy filtered resources.
[INFO] Copying 21 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # myproject---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # my
project ---
[debug] execute contextualize
[INFO] Using 'utf-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # myproject---
[INFO] Surefire report directory: C:\eclipseJava\workspace\myproject\target\sure
fire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.424s
[INFO] Finished at: Thu Dec 19 11:47:53 CET 2013
[INFO] Final Memory: 6M/10M
[INFO] ------------------------------------------------------------------------
And this is part of my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<groupId>myproject</groupId>
<artifactId>myproject</artifactId>
<version>0.1</version>
<name>myproject</name>
<build>
<!--
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/*Test*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
-->
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>false</filtering>
<directory>src/es/mycompany/myproject/test</directory>
<includes>
<include>ValoresTest.java</include>
</includes>
</testResource>
</testResources>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>es/mycompany/myproject/test/ValoresTest.java</include>
</includes>
</configuration>
</plugin>
-->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>myproject</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<path>/u</path>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
...
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>project-repo</id>
<url>file://${project.basedir}/local-maven-repo/</url>
</repository>
<repository>
<id>maven-restlet</id>
<url>http://maven.restlet.org</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding>
</properties>
</project>
If I add the lines commented in maven-surefire-plugin I don't get the message but the tests don't run anyway...
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject 0.1
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.sun:tools:jar:1.4.2 is missing, no dependency informat
ion available
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocate
d to commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # myproject
---
[debug] execute contextualize
[INFO] Using 'utf-8' encoding to copy filtered resources.
[INFO] Copying 21 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # my
project ---
[debug] execute contextualize
[INFO] Using 'utf-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # myproje
ct ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.16:test (default-test) # myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.190s
[INFO] Finished at: Thu Dec 19 12:01:22 CET 2013
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
I'm a newbie in Maven and I don't know where is my fail :( Any help please? I'm working with Java, Eclipse, JUnit4 and Maven.
Thanks!

force lifecycle prerequisite for maven plugin execution?

I use the maven-properties-plugin during the initialization phase to read in a bunch of properties from a properties file.
I also have the jetty plugin configured to set a couple of the project properties - including those read in above - as system properties to jetty.
If I run the result as
mvn initialize jetty:run-war
it works.
If I just say
mvn jetty:run-war
it fails. How can I force a goal specified on the command line to run in a lifecycle that includes the initialization phase?
Following works for me. Hope this helps.
file: pom.xml
<profiles>
<profile>
<!-- mvn -Plocal -->
<id>local</id>
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run-war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
If I just say mvn jetty:run-war it fails.
That's not what I'm experiencing. If you look at the documentation of the jetty:run-war goal, you'll see that it:
Invokes the execution of the lifecycle phase package prior to executing itself.
So all the phases preceding package plus the package itself are run and, consequently, the plugins bound to them. And indeed, with the following POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>q2488581</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>q2488581 Maven Webapp</name>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Running mvn jetty:run-war produces the following output:
$ mvn jetty:run-war
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building q2488581 - Maven Webapp
[INFO] task-segment: [jetty:run-war]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing jetty:run-war
[INFO] [properties:read-project-properties {execution: default}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/q2488581/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] No sources to compile
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[q2488581] in [/home/pascal/Projects/stackoverflow/q2488581/target/q2488581]
[INFO] Processing war project
[INFO] Copying webapp resources[/home/pascal/Projects/stackoverflow/q2488581/src/main/webapp]
[INFO] Webapp assembled in[76 msecs]
[INFO] Building war: /home/pascal/Projects/stackoverflow/q2488581/target/q2488581.war
[INFO] [jetty:run-war {execution: default-cli}]
...
As we can see, properties:read-project-properties is invoked during the initialize phase (before process-resources to which resources:resources is bound) as expected.
In other words, I cannot reproduce your problem (or maybe you should be more specific).

Categories

Resources