I have found this solution on stackoverflow. Warning - Build path specifies execution environment J2SE-1.4
I am getting almost the same problem but instead of 1-4 i am having 1-6. Unfortunately I don't really understand this configuration thing. It's new thing to me. I am trying second answer to get this working. I found this pom.xml in src under my project and it's xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.jpereira.trainings.designpatterns.creational.singleton</groupId>
<artifactId>singleton</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>singleton</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Configure Build Process -->
<build>
<plugins>
<!-- Compiler plugin to use Java 1.6 compatiblity -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Eclipse plugin to force download of source and JavaDoc jars -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
What and where should I add sth? I am using Eclipse on Windows 7. My version of java is: 1.8.0.25-b18 Words like plugin and Maven and JUnit are highlighted red. I would be grateful for help!
Try
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
And then regenerate the Eclipse project with mvn eclipse:eclipse.
Related
Not getting java support after creating maven project in eclipse
when maven project created I am not getting src/main/java,src/test/java and jre system libraries folders. i am following steps to create new project
steps to create
** maven project: File-->new-->project-->select maven project-->next-->select create a simple project-->next-->give project id and artifact id-->finish.**
<?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>MavenProject1</groupId>
<artifactId>MavenProject1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MavenProject1</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Yes, you wont get that. Its just a basic, very simple maven project that eclipse creates for you, so that you can structure the project as you like.
You now have 2 options:
create all the structuring by yourself
Create a new maven project and instead of selecting select create a simple project, select from archetype, and from there you can you can select what you like (Ex: maven-archetype-quickstart ) according to what you like.
For more info on setting up maven project with arch type search in youtube. You will get a lot of video tutorials.
I am designing a program that has to run with the mvn test command and take a user input from the command line. When I run the program with mvn test everything works until Scanner.next() is executed, then the CLI hangs and I have to close the program.
my test method
public class AppTest
{
#Test
public void shouldAnswerWithTrue()
{
Scanner sc = new Scanner(System.in);
System.out.println("Awaiting input");
String in = sc.next();
System.out.println("TEST!" + in);
assertTrue( true );
}
}
my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.vogella.build.maven.intro.Main</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Is it possible to handle the input this way with the Scanner class? Or at all through the maven command line interface in this way?
As far as I know you can't use Scanner as part of any code via Maven. Maven is to help you build, test, deploy - not actually help you at runtime. Furthermore, typically speaking, a unit test shouldn't rely on input at runtime.
Solution 1: Run the jUnit test directly with Java from command line
java -cp .:/usr/share/java/junit.jar org.junit.runner.JUnitCore AppTest
More information here.
Solution 2: Use system properties
You can then use System.getProperty("myVariable");
which you would run as mvn -Dtest=shouldAnswerWithTrue -DargLine="-myVariable=abc"
See more information about this method here.
I'm not a very experienced Java user in terms of compilation with maven, eclipse, etc...
I'm trying to build a small proyect with some maven dependencies, and my idea is to include all the dependencies in the ganarated Jar.
This is the content 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>amgrd</groupId>
<artifactId>testFlink</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>testFlink</name>
<description>testFlink</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<flink.version>0.10.0</flink.version>
<jdk.version>1.8</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka_2.11</artifactId>
<version>0.10.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Main-Class>StreamingWordCount</Main-Class>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I splitted it on three parts to remark the piece of XML that should be configuring the project to include the jars in the generated file.
Then I show the context menu of the project and click on Run as... -> Maven --> And I type the target "package".
The generated jar does not contain dependencies, only pom.xml, manifest and my source code classes.
Thank you in advance
There should be two jars in your target directory after you build. One that only contains your classes, and one with all the classes. The latter has the suffix jar-with-dependencies.jar.
Had to reinstall eclipse the other day, and moved it from one folder to another.. not sure if its relevant but I am getting an error when trying to run one of my projects - this is a new project I have never run successfully before. I have also tried copying the code to a newly built project but still no luck.
An internal error occurred during: "Launching Main (14)".
Container path cannot be null
Other projects are running fine.
Not sure if this is relevant but pom.xml below:
<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>GmailTest2</groupId>
<artifactId>GmailTest2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>GmailTest2</name>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.api.client</groupId>
<artifactId>google-api-client-http</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.api.client</groupId>
<artifactId>google-api-client-http</artifactId>
<version>1.2.3-alpha</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>enter code here
I am trying to use checkstyles google_checks.xml with maven-checkstyle-plugin. If I use the google_checks.xml with the latest checkstyle intelliJ plugin everything is correct but when I try configurating it via maven-checkstyle plugin I get this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check (default-cli) on project XX_XX_XX: Failed during checkstyle configuration: cannot initialize module TreeWalker - Unable to instantiate AvoidEscapedUnicodeCharacters:
Unable to instantiate AvoidEscapedUnicodeCharactersCheck
My pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
[...]
<checkstyle.file.path>develop/checkstyle/google_checks.xml</checkstyle.file.path>
</properties>
[...]
<build>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.13</version>
<configuration>
<configLocation>${checkstyle.file.path}</configLocation>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>${checkstyle.file.path}</configLocation>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
</plugins>
</reporting>
Do you guys have some suggestions about what could be wrong?
fixed this by updating the checkstyle-dependency manually to the latest stable version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.13</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.latest.version}</version>
</dependency>
</dependencies>
<configuration>
<configLocation>${checkstyle.file.path}</configLocation>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
Maven checkstyle plugin uses checkstyle 5.7 (the first line of plugin description).
Checkstyle 5.7 does not have this check (see checks package on grepcode).
You need either to disable this check or to wait for official fix of MCHECKSTYLE-261.
I give a demo at
https://github.com/favoorr/Maven-Checkstyle-Multimodule-Use
Multi modules and use Google Chechstyle