How can i resolve my build error about maven? - java

I've tried to build a project with Maven. In the folder where there's pom.xml file I've launched git bash and used "mvn compile" command but I got a build failure with following message:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error: Source option 5 is no longer supported. Use 6 or later.
[ERROR] error: Target option 1.5 is no longer supported. Use 1.6 or later.
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 46.905 s
[INFO] Finished at: 2019-11-12T10:21:58+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project unitime: Compilation failure: Compilation failure:
[ERROR] error: Source option 5 is no longer supported. Use 6 or later.
[ERROR] error: Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] -> [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/MojoFailureException

Add a configuration section to your maven-compiler-plugin in your pom.xml file and set source and target to eg. 1.8.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

Related

How To Host My Telegram Bot [JAVA] Using Heroku & Maven and GitHub?

My pom.xml File :
<modelVersion>4.0.0</modelVersion>
<groupId>TelegramBOT</groupId>
<artifactId>TelegramBOT</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<release>13</release>
<appName>TelegramBOT</appName>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* Main</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.telegram/telegrambots -->
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9</version>
</dependency>
</dependencies>
</project>
This is The Build Of pom.xml But I am Not Able To Host In Heroku... Its Shows An Error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.182 s
[INFO] Finished at: 2020-06-28T11:59:51Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project TelegramBOT: Compilation failure: Compilation failure:
[ERROR] /tmp/build_07ca4d72478d669dcc1d1150921b9882/src/com/TelegramBot/EraserHead/GameHandler.java:[17,60] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /tmp/build_07ca4d72478d669dcc1d1150921b9882/src/com/TelegramBot/EraserHead/ImageGuess.java:[23,60] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] -> [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/MojoFailureException
! ERROR: Failed to build app with Maven
We're sorry this build is failing! If you can't find the issue in application code,
please submit a ticket so we can help: https://help.heroku.com/
! Push rejected, failed to compile Java app.
! Push failed
This The Heroku Console ....
But In Eclipse Console Its Says BUILD SUCCESSFUL!
I Can't Figure Out What To Do ... Do I Really Need To Create Procfile ???
Please Help... If You Need to See The Source Code Of My Program,
It Is There In My GitHub Account : https://github.com/saikat0326/Saikat-Telegram-BOT
Thanks In Advance...
it looks like the Maven Compiler plugin is using Java 5 (it should be using Java 6 by default), hence you get the build error diamond operator is not supported in -source 1.5
Heroku supports various Java version (see Supported Java versions), you should just be able to set the target version in your POM file
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
The diamond operator – introduced in Java 1.7 – adds type inference and reduces the verbosity in the assignments.
Problem in your source code try to re-write it.
I had similar issu and my now looks like this
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<webjars-bootstrap.version>4.1.3</webjars-bootstrap.version>
<webjars-jquery-ui.version>1.12.1</webjars-jquery-ui.version>
<webjars-jquery.version>3.3.1-1</webjars-jquery.version>
<java.version>${java.version}</java.version>
<maven.compiler.source>${versions-maven-plugin.version}</maven.compiler.source>
<maven.compiler.target>${versions-maven-plugin.version}</maven.compiler.target>
</properties>

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java

I am trying to execute the testNG main class using pom.xml file by using the below command in Maven Run Configurations.
exec:java -Dexec.mainClass=com.selenium.controls.TestNGMainClass
Here, I am using Java 8.
But I got the below error.
[INFO] ------------------------------------------------------------------------
[INFO] Building seleniumScriptsRegression 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) # seleniumScriptsRegression ---
[WARNING] java.lang.ClassNotFoundException: com.selenium.controls.TestNGMainClass
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:270)
at java.lang.Thread.run(Unknown Source)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.331 s
[INFO] Finished at: 2018-01-29T10:59:54+05:30
[INFO] Final Memory: 13M/32M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project seleniumScriptsRegression: An exception occured while executing the Java class. com.selenium.controls.TestNGMainClass -> [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
Kindly help me to fix the issue.
Assuming you have a Main.java in src/test/java
Add this in your pom.xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>Main</mainClass>
</configuration>
<executions>
<execution>
<id>run-selenium</id>
<phase>integration-test</phase>
<goals><goal>java</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
and run it via :
mvn clean install or mvn exec:java

Maven runs JUnit tests in Eclipse but compilation fails from the command line

I have created a very simple project in Eclipse to run a very simple JUnit test. These tests work fine when tests are executed from within Eclipse, but the code does not compile when run via maven command line.
The command I am using to run maven is simply 'maven test'. The following is the maven output:
MacBook-Pro:leonard-reference-test randy$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building leonard-reference-test 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # leonard-reference-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) # leonard-reference-test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/randy/PSH/workspaces/playground/leonard-reference-test/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/randy/PSH/workspaces/playground/leonard-reference-test/src/main/java/info/leonard/reference/test/ReferenceTestClient.java:[3,17] package org.junit does not exist
[ERROR] /Users/randy/PSH/workspaces/playground/leonard-reference-test/src/main/java/info/leonard/reference/test/ReferenceTestClient.java:[8,10] cannot find symbol
symbol: class Test
location: class info.leonard.reference.test.ReferenceTestClient
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.043 s
[INFO] Finished at: 2015-12-15T19:10:49-07:00
[INFO] Final Memory: 11M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project leonard-reference-test: Compilation failure: Compilation failure:
[ERROR] /Users/randy/PSH/workspaces/playground/leonard-reference-test/src/main/java/info/leonard/reference/test/ReferenceTestClient.java:[3,17] package org.junit does not exist
[ERROR] /Users/randy/PSH/workspaces/playground/leonard-reference-test/src/main/java/info/leonard/reference/test/ReferenceTestClient.java:[8,10] cannot find symbol
[ERROR] symbol: class Test
[ERROR] location: class info.leonard.reference.test.ReferenceTestClient
[ERROR] -> [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/MojoFailureException
MacBook-Pro:leonard-reference-test randy$
The pom.xml for this is as follows:
<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>info.leonard.reference</groupId>
<artifactId>leonard-reference-test</artifactId>
<version>0.0.1</version>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
</plugin>
</plugins>
</build>
</project>
And the only Java file in the project is as follows:
package info.leonard.reference.test;
import org.junit.Test;
public class ReferenceTestClient
{
#Test
public void testOne()
{
System.out.println("simple test");
}
}
That's it... no other files in the project. Maven tests run successfully from within Eclipse, but the code doesn't even compile from within Maven.
A valid pom.xml file, or other modifications to this simple project, is appreciated.
You have your file in src/main/java/ directory but the scope for the JUnit dependency is test. This means maven will not take it into account when compiling non-test code. Please put your file in src/test/java.
Test scope means that junit is only available in src/test/java
move
/Users/randy/PSH/workspaces/playground/leonard-reference-test/src/main/java/info/leonard/reference/test/ReferenceTestClient.java:
over to
/Users/randy/PSH/workspaces/playground/leonard-reference-test/src/test/java/info/leonard/reference/test/ReferenceTestClient.java:

The import javax.annotation cannot be resolved during Maven build

I am getting the following error while building a .war using mcn clean package with Apache Maven. Can some one give me a way to resolve it? Thanks.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.593s
[INFO] Finished at: Thu Sep 05 22:35:10 GMT+05:30 2013
[INFO] Final Memory: 13M/24M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (default) on project application: Compiler errors :
[ERROR] error at import javax.annotation.PreDestroy;
[ERROR] ^^^^^^^^^^^^^^^
[ERROR] C:\Documents and Settings\User\My Documents\application\application\src\main\java\com\Service\MyService.java:13:0::0 The import javax.annotation cannot be resolved
[ERROR] -> [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
Does your pom.xml set the Java Compiler version?
Some (all?) versions of maven-compiler assume the Java 1.4 compiler... which of course causes issues since Annotations were new in Java 1.5.
You can force it to Java 7 by including a plugin block for maven-compiler-version in your project's pom.xml and set its source and target properties... something like this:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Download JSR305 from here to fix the problem.

Error while using maven site plugin (AbstractMethodError)

When trying to do a mvn site:run with this project:
<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.example</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>test</name>
<description>test</description>
<reporting>
<plugins>
<!-- Project Reports -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
<!-- Change report -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>changes-maven-plugin</artifactId>
<version>2.0-beta-1</version>
</plugin>
</plugins>
</reporting>
I get the following error:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-site-plugin:3.0:run (default-cli) # test ---
2013-08-21 12:44:07.381:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:2.7
[INFO] configuring report plugin org.codehaus.mojo:changes-maven-plugin:2.0-beta-1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.477s
[INFO] Finished at: Wed Aug 21 12:44:08 CEST 2013
[INFO] Final Memory: 16M/179M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:run (default-cli) on project test: Execution default-cli of goal org.apache.maven.plugins:maven-site-plugin:3.0:run failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-site-plugin:3.0:run: java.lang.AbstractMethodError: null
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.apache.maven.plugins:maven-site-plugin:3.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/user/.m2/repository/org/apache/maven/plugins/maven-site-plugin/3.0/maven-site-plugin-3.0.jar
[ERROR] urls[1] = file:/home/user/.m2/repository/org/apache/maven/reporting/maven-reporting-exec/1.0.1/maven-reporting-exec-1.0.1.jar
[ERROR] urls[2] = file:/home/user/.m2/repository/org/apache/maven/reporting/maven-reporting-api/3.0/maven-reporting-api-3.0.jar
...
[ERROR] urls[39] = file:/home/user/.m2/repository/commons-lang/commons-lang/2.5/commons-lang-2.5.jar
[ERROR] urls[40] = file:/home/user/.m2/repository/commons-io/commons-io/1.4/commons-io-1.4.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] -> [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/PluginContainerException
2013-08-21 12:44:08.256:INFO::Shutdown hook executing
2013-08-21 12:44:08.257:INFO::Shutdown hook complete
The error happens only after I add the changes-maven-plugin regardless of whether there is anything in src/changes/ or not. Up until now, I wasn't able to figure out what exactly the problem is. Can someone explain what I'm doing wrong here?
I think you want to use the maven-changes-plugin instead.

Categories

Resources