I tried java 9 with eclipse oxygen 1a Release. As far as Simple java 9 project is concern. It is working. Here is the screen shot of java 9 simple program
Here is my Welcome.java. It can be seen that I am using Java 9 feature in this program
package com.jdojo.intro;
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to the Module System.");
// Print the module name of the Welcome class
Class<Welcome> cls = Welcome.class;
Module mod = cls.getModule();
String moduleName = mod.getName();
System.out.format("Module Name: %s%n", moduleName);
}
}
But with Maven project with Java 9 I am having problem. I created almost same project with maven. Here is my pom.xml file. I also used junit 5 dependency
<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>pk.training.basit</groupId>
<artifactId>Ch3-02-HelloWorldMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Ch3-02-HelloWorldMaven</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>9</java-version>
<!-- Unit testing -->
<junit.version>4.12</junit.version>
<junit-jupiter-engine.version>5.0.1</junit-jupiter-engine.version>
<junit-platform-runner.version>1.0.1</junit-platform-runner.version>
<!-- Logging -->
<log4j.version>2.9.1</log4j.version>
<jboss-logging.version>3.3.1.Final</jboss-logging.version>
<junit-jupiter-engine.version>5.0.1</junit-jupiter-engine.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<maven-failsafe-plugin.version>2.20</maven-failsafe-plugin.version>
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Unit Testing -->
<!-- JUnit Jupiter test engine implementation, only required at runtime. -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform-runner.version}</version>
<scope>test</scope>
</dependency>
<!-- Logging-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
<scope>compile</scope>
</dependency>
......
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>pk.training.basit.HelloFXApp</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</build>
The project structure can be seen in the screen shot. Here is my AppTest.java
package pk.training.basit;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class AppTest {
#Test
void myFirstTest() {
assertEquals(2, 1 + 1);
}
}
If module-info.java file is not present in src/main/java. Then this test case run. By simply mouse-right click and select Run As--> Junit Test. If I select the java file, which is Welcome.java and select Run As --> Java Application. Then I get the following output
Welcome to the Module System.
Module Name: null
Which is OK. Because now it is considering class path. And no module is present on module path. So module name is null. But as soon as I introduce module-info.java in src/main/java/ folder. Things start getting messy. Here what I tried with module-info.java. First I tried this
module pk.training.basit {
}
Same as my First project without maven. I get error in my AppTest.java. Imports are not resolving. Now if I right click on my Welcome.java and select Run As --> Java Application . It says error exist want to proceed. If I select yes. I get the following output
Error occurred during initialization of boot layer
java.lang.module.FindException: Module pk.training.basit not found
Now if I delete my module-info.java. And then right mouse click on my project name which is Ch3-02-HelloWorldMaven and select Configure --> Create module-info.java. It asks me for module name. If I enter my module name pk.training.basit and click Finish. Then here is the result
Now if i again try to run the Welcome.java. I get the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module pk.training.basit not found
Now if i remove my AppTest.java. And change module-info.java to this
module pk.training.basit {
exports pk.training.basit;
//requires org.junit.jupiter.api;
}
And try to run the Welcome.java. Although there is no error present now in project. I get the output
Error occurred during initialization of boot layer
java.lang.module.FindException: Module pk.training.basit not found
I don't know what I am doing wrong. Or there is problem with maven or eclipse. But here what I tried with eclipse oxygen 1a, Maven and eclipse.
Also I just have java 9 GA. No java 8 or java 7 on my machine. For just java 9 I have to include this in eclipse.ini file. -vm C:\Program Files\Java\jdk-9\bin\javaw.exe
....
openFile
--launcher.appendVmargs
-vm
C:\Program Files\Java\jdk-9\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.8
-Dosgi.instance.area.default=#user.home/eclipse-workspace
-XX:+UseG1GC
....
If I am doing something wrong. Then please let me know.
Also you can't have more than one module-info.java file in one project in eclipse. Like if we consider this link Java 9 multi module project. Then for multi module project the structure is you have project root folder. Then in project root folder you have one source folder for one module. And another source folder for another module. Both source folders have their own module-info.java file.
But if I try to do the same in eclipse. Then I get the error. Multiple modules-info.java files found on class path.
Like the idea is you have one maven project. Which manage all your dependencies. Like spring, apache, etc. And in this project you have one source folder like module.web which contains your web modules related java files and its own module-info.java. You have another source folder module.service. which contains its own module-info.java.
But it seems you can't do it in eclipse in single project. I don't know it's valid or not but I tried it and I see you can't do it in eclipse in this way.
Anyways if I am doing something wrong then please let me know.
Thank you.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Longtime Java developer trying to learn Scala(not with Spark). I wanted to build a basic Scala program that can be built using Maven and run as an executable jar. In addition, I wanted to go ahead and incorporate Log4j into it, so that I have a basic framework for building stand-alone jars. I had some trouble googling all the pieces I needed to do this, but I finally figured this out, so I wanted to post how to do this for others to use.
So, it turns out that I had to go with Log4j2(which I have never used) instead of Log4j(which I have used a lot). So, the basic environment I am using here is:
OS = Windows 10
IDE = IntelliJ IDEA 2018.1.6 (Community Edition)
Java SDK = 1.8.0_111
Language = Scala 2.12.6
Build Tool = Maven
Steps:
1. Go to File -> new project
Select a Maven project, and the net.alchim31.maven:scala-archetype-simple archetype:
starting a new maven project
Fill out group ID, artifact ID, and version on the next page:
groupId, artifactId, and version
Then go with the defaults for the next 2 pages, and click "Finish"
2.) Import Maven dependencies:
When the project first opens up, you should see a small popup in the bottom right corner, click on “Enable Auto-Import”:
auto-import
3.) make a resources folder inside your project's main/scala folder
4.) go to File -> Project Structure:
In this window, you want to add this src/main/resources path as a resources folder,
so in the project structure window, click modules, then resources, then rick click on
your resources folder and select “resources”.
Then you should see your folder on the right in purple as a resources folder, click “Apply”, then click “OK”:
Project Structure window
5.) make a new package called "classes" inside your src/main/scala folder
6.) In the src/main/resources folder, make a new configuration file called log4j2.properties. This is for the log4j configuration.
7.) In this file, put the following information in it to configure a rolling log file called msggen.log that roles over every 10MB:
name = PropertiesConfig
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = /home/ubuntu/logs/msggen/msggen.log
appender.rolling.filePattern = /home/ubuntu/logs/msggen/msggen.%d{dd-MMM}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 5
logger.rolling.name = msgGenLog
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile
8.) In your pom.xml, you need to add the log4j2 dependencies:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api-scala_2.12</artifactId>
<version>11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
9.) You also want to add build plugins for when you want to generate the executable jar.
Inside the build and plugins tags, add the following plugin tags(change the finalName tag to what you want your jar name to be):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>msggen</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.scala.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
10.) In your src/main/scala/classes folder that you made earlier, make a Scala object called LogUtil.scala, with the following code:
package classes
import org.apache.logging.log4j._
object LogUtil {
val msggenLogger:Logger = LogManager.getLogger("msgGenLog");
def msggenLoggerDEBUG(message: String): Unit = {
this.msggenLogger.debug(message)
}
}
11.) change your App.scala object to invoke your logger, here’s my code:
package com.scala
import classes.LogUtil
/**
* #author ${user.name}
*/
object App {
def main(args : Array[String]) {
LogUtil.msggenLoggerDEBUG("Hi there!");
}
}
12.) right click on the App.scala object and select “Run ‘App’” to test that the log file gets made and populated(set the config property appender.rolling.fileName to set where you want the log file to be created):
test log message
To Build the JAR file:
1.) Go to File -> project structure again, and select the “Artifacts” tag on the left, then click the “+” button, then JAR -> from modules with dependencies:
project structure for artifact
2.) In the “create JAR from modules” window, select your App.scala class as the main class, and make sure to specify the src/main/resources folder to where you want your manifest file to be made in(change it from src/main/scala):
create jar from modules window
3.) Click OK and make a note of the "Output Directory" field which tells you where your jar is going to be after it is made.
4.) Click “Apply” and then “OK”.
5.) In the main window, go to “Build” -> Build Artifacts -> then in the little window that pops up, select “build” again
6.) Now in the Output Directory path noted earlier, you should see your jar file.
7.) I’m on Windows, so open a command line and go to the location where your jar is, and run it by typing
Java -jar msggen.jar
8.) go to your log file again to verify that your test message was logged:
log file with 2nd message
So, now you should have a basic framework for a Scala application with Maven and Log4j2 integration within it.
Here is my full pom.xml for reference:
<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.scala</groupId>
<artifactId>msggen</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>My wonderfull scala app</description>
<inceptionYear>2018</inceptionYear>
<licenses>
<license>
<name>My License</name>
<url>http://....</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.12.6</scala.version>
<scala.compat.version>2.12</scala.compat.version>
<spec2.version>4.2.0</spec2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api-scala_2.12</artifactId>
<version>11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.compat.version}</artifactId>
<version>3.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-core_${scala.compat.version}</artifactId>
<version>${spec2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-junit_${scala.compat.version}</artifactId>
<version>${spec2.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.3.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<!-- Tests will be run with scalatest-maven-plugin instead -->
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>TestSuiteReport.txt</filereports>
<!-- Comma separated list of JUnit test class names to execute -->
<jUnitClasses>samples.AppTest</jUnitClasses>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I generated the application with JHipster with Gradle as the build tool.
When I created entity I added filtering support, which generated JPA static metamodel. But IntelliJ doesn't recognize the metamodels.
I have enabled the annotation processor settings on IntelliJ but it doesn't seem to work.
What settings do I have to change for IntelliJ to recognize the JPA static metamodels?
By default, the metamodel classes get generated into the /target/generated-sources/annotations folder. It seems like that folder isn't registered as a source folder.
You can either change that manually in your IDE or if you're using a Maven build, you can do that automatically by adding the following plugin to your build configuration:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
I explained that in more details in one of my Hibernate Tips.
I'm not allowed to comment but I wanted to add to Thorben Janssen's answer.
Besides the plugin config I also had to add this to the dependencies of the project:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.21.Final</version>
</dependency>
This is what generates the sources in the target/generated-sources/annotations path.
So the pom ended up like this:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.21.Final</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<goals>
<goal>add-source</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<sources>
<source>target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
To get IntelliJ IDEA to recognize the generated classes, I had to add this line on build.gradle
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
Update
Better solution is to modify IntelliJ Plugin
idea {
module {
sourceDirs += file("build/generated/source/apt/main")
generatedSourceDirs += file("build/generated/source/apt/main")
}
}
Intellij's build recognize all processors listed in this file:
META-INF/services/javax.annotation.processing.Processor
.
Case you use Eclipse Link, include this line inside the file:
org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
Case Hibernate:
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
Ensure that you have all dependencys: I will describe using maven just for example:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>
OR
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.2.12.Final</version>
<scope>provided</scope>
</dependency>
For me it wasn't a problem of the configuration files (none of the above mentioned solutions worked), but I simply had to reload all Maven project files.
For this in IntelliJ Idea:
Go to the Maven tab on the right side of the IDE (you might have to make it visible under View -> Tool Windows)
Open the project and compile
On the top left corner of the tab press Reload all Maven Projects
Now, the meta classes (e.g. SampleClass_) should be importable and recognized by IntelliJ
I'll start with 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>HPK</groupId>
<artifactId>WRB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>WRB</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>4.5.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.3</version>
<executions>
<execution>
<configuration>
<arguments>
<argument>-visitor</argument>
<argument>-package</argument>
<argument>wrb.grammar</argument>
</arguments>
</configuration>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-clean-plugin
</artifactId>
<versionRange>
[3.0.0,)
</versionRange>
<goals>
<goal>clean</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
When I run maven install on this project, maven should generate the sources from the antlr4 plugin within the wrb.grammar package, but it doesn't. It does everything, but put the sources into those directories, it simply puts them in what it calls the "default-package", which is just the root of antlr/generated-sources.
If I use the Antlr4IDE-plugin by right clicking the grammar and selecting it under run as, the sources are generated in the right directory.
Another person I'm working with on this small project has no problem using maven-install. Besides our operating systems and eclipse versions, everything is the same.
I'm using Eclipse Oxygen on MacOS.
What am I doing wrong that the maven-plugin doesn't generate my desired directory?
I have checked the sources of antlr4 version 4.3. The -package parameter is only used by the code generator templates but not anywhere in the actual tool source code (seeGithub search results for genPackage). So it cannot have an effect on the location of the output files.
Instead, the location of each output file is determined based on the location of the corresponding input file (see here and here in the sources). This is fits with the explanation in the maven plugin docs:
If your grammar is intended to be part of a package called org.foo.bar then you would place it in the directory src/main/antlr4/org/foo/bar. The plugin will then produce .java and .tokens files in the output directory target/generated-sources/antlr4/org/foo/bar When the Java files are compiled they will be in the correct location for the Javac compiler without any special configuration. The generated java files are automatically submitted for compilation by the plugin.
Additionally, when using the antlr4-maven-plugin it is not necessary to specify the -package option. As the plugin derives the value of the -package paramter from the input file path and automatically adds it to the antlr invocation (see here in the sources). That is probably also the reason why -pacakge is not directly available as a configuration parameter in the maven plugin.
Solution
In order to have the generated files placed in a directory structure that matches your package names, you need to use the same structure for the input files.
Essentially, all you need to do is to put your grammar files in src/main/antlr4/wrb/grammar, remove the -package parameter from the configuration and it everything work as expected.
By the way: instead of writing
<arguments>
<argument>-visitor</argument>
</arguments>
you could simply write
<visitor>true</visitor>
since this parameter is directly understood by the antlr4-maven-plugin.
I am in the process of migrating my build from Ant to Maven. The Ant build used to compile a "code generator", execute this "code generator" which produced a set of Java and C code. It then took the generated Java code and compiled it along with some additional code produce a single jar.
I have replicated this this in Maven quite easily and it works well when I run from the command line but Eclipse is complaining and is giving me an error relating to the pom file
Failure to find {group.id}:{artifact.id}:pom:1.0.0-SNAPSHOT in
http://{our internal site repository}/nexus/content/groups/public was
cached in the local repository, resolution will not be reattempted
until the update interval of snapshots has elapsed or updates are
forced
where the group.id and artifact.id are the group and artifact id of my code generator plugin
and any code that references the generated code also fails to compile.
My maven build consists of
a generator project that contains just the Java code for the code generator.
a generator-plugin project that contains just the code to wrap the generator as a Maven plugin. This is dependent upon the generator project.
an xyz project that uses the plugin to generate the code. The code ends up in the target/generated-sources/xxx folder of this project. I have configured the build-helper-maven-plugin as per Maven compile with multiple src directories to include this extra source directory.
If I manually add the generated source folder to the Eclipse build path all of the errors relating to the code not being there go away on that project but not on any downstream projects and the "Failure to find..." error listed above remains.
What puzzles me a little is that it is referring to the ...:pom:1.0.0-SNAPSHOT when in fact my generator-plugin is defined as a maven-plugin.
Is this a sensible approach?
Why am I getting a "Failure to find..." error?
Why isn't Eclipse picking up my generated-sources folders?
I should also say I have the m2e plugin and the m2e connector for build-help-maven-plugin installed in my Eclipse IDE.
It looks like a problem during the download of the lib from the repository. I already had the same error message once.
Did you take a look at your local repository?
Go to the .m2 folder and look for /nexus/content/groups/public. If the folder is there, open it and see if the lib was download correctly. If not, try to delete the folder and try to run mvn install to force the download of the lib.
At Eclipse, run Right button > Maven > Update Project too.
Are you using an local repository like Artifactory, aren't you? Also look for the lib in the repo1-cache (or similar) folder. See if the jar is there.
Are you behind any firewall or proxy?
Using eclipse Indigo3.7, this was what I found that worked good using spring 3.1.1 which does have the 3.0.6 version as well in it. Once I got the plugins setup and put into the correct area of the pom and included the argline and endorseddirs to have the java sources put out into the target/generated-sources/cxf folder then maven generated the sources ok.
....
<properties>...
<dependencyManagement>
<dependencies>.....
</dependencyManagement>
<dependencies>
<dependency>....
</dependencies>
<!-- *************************** Build process ************************************* -->
<build>
<finalName>projName</finalName>
<plugins>
<!-- Force Java 6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Deployent on AS from console
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${version.jboss.as.maven.plugin}</version>
</plugin>
-->
<!-- wildbill added tomcat plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<!-- Surefire plugin before 2.9 version is buggy. No need to declare here,
it's being referenced below w/ the version
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
-->
<!-- developer added these -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<endorseddirs>target/generated-sources/cxf</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Djava.endorsed.dirs=target/generated-sources/cxf</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<endorseddirs>target/generated-sources/cxf</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<argLine>-Djava.endorsed.dirs=target/generated-sources/cxf</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems>
<artifactItem>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2</version>
</artifactItem>
<artifactItem>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2</version>
</artifactItem>
</artifactItems>
<outputDirectory>target/generated-sources/cxf</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
<!-- *********************** Profiles ************************************ -->
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be
used when invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization
your app will need. -->
<!-- By default that is to put the resulting archive into the
'deployments' folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>projName</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>process-sources</id>
<phase>generate-sources</phase>
<configuration>
<fork>once</fork>
<additionalJvmArgs>-Djava.endorsed.dirs=target/generated-sources/cxf</additionalJvmArgs>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</plugin>
<!-- Actual war created in default target dir -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
If your wsdl folder is in ${basedir}/src/main/resources it'll find it automatically
Hope this helps!
I'm trying to create a new project with Eclipse in order to create GWT application under maven 2 system.
I have create the project with the follow mvn command
mvn archetype:generate -DarchetypeRepository=repo1.maven.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0
I have installed the follow eclipse plugins:
* m2eclipse
* egit
* gwt plugin
Here my POM 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/maven-v4_0_0.xsd">
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.mobc3.paperquid</groupId>
<artifactId>Backoffice</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>GWT Maven Archetype</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.3.0</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>2.3.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin
documentation at codehaus.org -->
<configuration>
<runTarget>Backoffice.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>com.mobc3.paperquid.backoffice.client.Messages</i18nMessagesBundle>
</configuration>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
I can compile and deploy my application using the linux shell but I have many problems to build and run the application inside eclipse.
I haven't found any tutorial that explain how to create step by step a GWT application under maven inside eclipse.
Can someone help me?
One more option:
Make a gwt project by using the gwt plugin in Eclipse. Now you have an Eclipse gwt project.
Select the project in Project Explorer, right-click it, then choose Configure. Then select Convert to Maven Project. Now you get a gwt-maven project.
Now add necessary dependencies to pom.xml.
Here is the relevant (I think) section from my pom setup when I was running my GWT app with the gwt:run goal:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.3.0</version>
<configuration>
<runTarget>/ModuleName.html</runTarget>
<modules>
<module>${project.groupId}.package.ModuleName</module>
</modules>
<copyWebapp>true</copyWebapp>
</configuration>
<executions>
<execution>
<configuration>
<extraParam>true</extraParam>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
I should say, though, that I now use the GWT Eclipse Plugin to run my app within Eclipse, so it's been a while since I used this configuration. From what I remember reading, the "copyWebapp" "true" is one of the key pieces of configuration. It also helped me to specify the module name directly, because the gwt-maven-plugin sometimes had problems locating it.