Can't compile multi module Spring project with Maven - java

I took an older Java 11, Spring based multi module project that I didn't work on since about two years and tried to make it compile and run on my new laptop. It worked on my old laptop, but I can't make it run on the new laptop. When running mvn clean install the module called "util" compiles fine. But the "shared" module, which requires the "util" module, does not find the util module: "cannot find symbol". What happens is that all the fxml and image files are copied to the target directory but there is not a single class file. Because the information about the issue was very limited in STS (Spring development tool) I installed Maven 3.8.2. and tried to fix it from the command line. Based on the information and what I found in the internet I added org.codehaus.mojoversions-maven-plugin and org.apache.maven.plugins:maven-enforcer-plugin plus I tried with and without explicit version tags, since I got warnings as the versions are already defined in spring-boot-dependencies-2.5.4.pom.pom. So, when I run mvn versions:display-plugin-updates I find the outcome very confusing, since in the very end it states "BUILD SUCCESS" but if I scroll up, there is an Error message saying: "Project does not define required minimum version of Maven. Update the pom.xml to contain maven-enforcer-plugin to force the maven version which is needed to build this project". But this is what I did?!
Please see below the current parent pom. Please let me know should you need more information. Thank you in advance for your help.
Please have in mind that my expertise in Maven is rather limited. I understand the basics, when it gets to all these plugins, I get lost. Therefore, I would be grateful for "dummies" style answers.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.agiletunes</groupId>
<artifactId>agiletunes-parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>agiletunes-parent</name>
<description>Maven parent for all agileTunes modules</description>
<modules>
<module>../agiletunes-productmanager</module>
<module>../agiletunes-testmanager</module>
<module>../agiletunes-shared</module>
<module>../agiletunes-authserver</module>
<module>../agiletunes-util</module>
</modules>
<properties>
<java.version>11</java.version>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- for testing Spring Boot applications with JUnit -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

This is happening because what you defined in the configurations of the maven-enforcer-plugin actually maven-enforcer-plugin runs in the validation life cycle and when you run the mvn versions:display-plugin-updates with the below configurations what happen is,
<requireMavenVersion>
<version>3.0.0</version>
</requireMavenVersion>
it will check the project maven version and then check the plugin versions, and you will get an error if the project minimum version is not compatible with the plugin versions.
[INFO] Project inherits minimum Maven version as: 3.0.0
[INFO] Plugins require minimum Maven version of: 3.1.1
[INFO] Note: the super-pom from Maven 3.6.3 defines some of the plugin
[INFO] versions and may be influencing the plugins required minimum Maven
[INFO] version.
[INFO]
[ERROR] Project requires an incorrect minimum version of Maven.
[ERROR] Update the pom.xml to contain maven-enforcer-plugin to
[ERROR] force the Maven version which is needed to build this project.
[ERROR] See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[ERROR] Using the minimum version of Maven: 3.0.0
so what you can do is change the version in the maven-enforcer-plugin to the project version.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.1.1</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
and after that, the error will be gone,
[INFO] Project inherits minimum Maven version as: 3.1.1
[INFO] Plugins require minimum Maven version of: 3.1.1
[INFO] Note: the super-pom from Maven 3.6.3 defines some of the plugin
[INFO] versions and may be influencing the plugins required minimum Maven
[INFO] version.
[INFO]
[INFO] No plugins require a newer version of Maven than specified by the pom.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
but actually you don't need maven-enforcer-plugin to define, I'm not sure if there is a list of plugins that don't need to be explicitly added, but I assume it's the most common ones like maven-surefire-plugin and maven-clean-plugin

Related

error compiling[m: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor

I am facing below error while building code Spring Boot and Apache Avro example from STS, however if I run this code command line it works well.
[INFO] [1m--- [0;32mmaven-compiler-plugin:3.8.1:compile[m [1m(default-compile)[m # [36mavroposgen[0;1m ---[m
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to E:\Kafka-Streams-with-Spring-Cloud\avroposgen\target\classes
[INFO] [1m------------------------------------------------------------------------[m
[INFO] [1;31mBUILD FAILURE[m
[INFO] [1m------------------------------------------------------------------------[m
[INFO] Total time: 5.729 s
[INFO] Finished at: 2021-12-15T22:00:20+05:30
[INFO] [1m------------------------------------------------------------------------[m
[ERROR] Failed to execute goal [32morg.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile[m [1m(default-compile)[m on project [36mavroposgen[m: [1;31mFatal error compiling[m: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module #0x18ff1520) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module #0x18ff1520 -> [1m[Help 1][m
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the [1m-e[m switch.
[ERROR] Re-run Maven using the [1m-X[m switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [1m[Help 1][m http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>learningjournal.guru.examples</groupId>
<artifactId>avroposgen</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Avro Pos Generator</name>
<description>Avro Pos Generator by Learning Journal</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>src/main/avro</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<imports>
<import>${project.basedir}/src/main/avro/LineItem.avsc</import>
<import>${project.basedir}/src/main/avro/DeliveryAddress.avsc</import>
</imports>
<stringType>String</stringType>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
</repository>
</repositories>
</project>
In eclipse go to->
Step 1 : window->preference->java->complier-> set compiler compliance level to 1.8 if you are using jdk1.8 or java8
Step 2:window->preference->java->installed JREs->
EDIT(if your installed JRE is not being used)->
JRE HOME : (the one which you have installed in your system jre path
should be that of inside jdk)
in my case it is-> C:\Program Files\Java\jdk1.8.0_291\jre
Please try to change these config of your ide.
Seems your compiler or jre version is not matched in ide as per installed
java version.

Maven pom file, what is it doing?

I have just started using Maven, in a newbie capacity, just want to understand something around dependencies.
I am trying to build a micro web service using iText and the pdf output functionality.
So my very first steps is seeing if I can get a pdf output from a very simple Java program.
In my pom file i have the following dependencies:
<!-- iText Core -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>${itext.version}</version>
<type>pom</type>
</dependency>
<!-- iText pdfHTML add-on -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>2.1.6</version>
</dependency>
After reading the information on the Maven site, the pom file should do all of the heavy lifting in getting the dependencies, this is the bit i'm a little confused on.
Will the pom file physically download the files to the the app location on application start so that he app can utilize these files?
if that's the case it doesn't seem to be doing this and so am I missing something in the pom file to enable this?
The full pom file is:
<?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>
<itext.version>RELEASE</itext.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- iText Core -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>${itext.version}</version>
<type>pom</type>
</dependency>
<!-- iText pdfHTML add-on -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>2.1.6</version>
</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>
Any help appreciated.
Thanks
When maven build is executed, Maven automatically downloads all the dependency jars into the local repository.
the local repository of Maven is a folder location on the developer's machine, where all the project artifacts are stored locally.
Usually this folder is named .m2.
Here's where the default path to this folder is – based on OS:
Windows: C:\Users\User_Name\ .m2
Linux: /home/User_Name/.m2
Mac: /Users/user_name/.m2
https://www.baeldung.com/maven-local-repository
Maven does download the dependencies to the local m2 repository. But this is more meant for building the application, not for running.
What you want (copy the dependencies next to the output jar) can be achieved with the goal dependency:copy-dependencies
See this blog post:
https://technology.amis.nl/2017/02/09/download-all-directly-and-indirectly-required-jar-files-using-maven-install-dependencycopy-dependencies/
Managing dependencies is one of the key features of Maven.
Dependency management: It is possible to define dependencies to other
projects. During the build, the Maven build system resolves the
dependencies and it also builds the dependent projects if needed.
Resolving dependencies does mean it downloads all the specified jars in the local system.
The Maven tooling reads the pom file and resolves the dependencies of
the project. Maven validates if required components are available in a
local repository. The local repository is found in the .m2/repository
folder of the users home directory.
Note that .m2/ is a hidden folder. If you are using Linux, would be this path /home/someuser/.m2
Read this
If however its not downloading the jars or creating the .m2 directory at all, then either you are not building the project right or you are not connected to the internet.

Impossible to compile using maven-compiler-plugin with Java higher than 1.8

I have a NetBeans maven-based project that I want to switch from Java 1.8 to 12 but I can't compile it.
After many attempts, I have decided to start from the beginning, and create a very simple project to understand how to do this change.
Well, I have tried and I can't compile the simple project either.
Could someone explain what I am doing wrong?
Preamble
NetBeans: 10.0
JAVA_HOME: C:\Program Files\Java\jdk-12 (I have tried also 9, 10, 11)
Maven:
Project creation
Create Project with a Window (first TopComponent)
I changed the JDK version from 11 (default in NetBeans 10.0) to 12
This is the autogenerated POM with and the javax.annotation-api 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>
<parent>
<groupId>it.prj</groupId>
<artifactId>Project-parent</artifactId>
<version>2.9</version>
</parent>
<artifactId>Project-source</artifactId>
<packaging>nbm</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<useOSGiDependencies>true</useOSGiDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<useDefaultManifestFile>true</useDefaultManifestFile>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-api-annotations-common</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-windows</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-ui</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-awt</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-settings</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Then I start the Clean & Build > SUCCESS
I changed the Java version from 1.7 to 12
This add the related Plugin to the POM
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
Update the version field, so it becomes:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
Then I restart the Clean & Build > FAILED
cd D:\Project\Project-source; "JAVA_HOME=C:\\Program Files\\Java\\jdk-12" "M2_HOME=C:\\Program Files\\apache-maven-3.6.0" cmd /c "\"\"C:\\Program Files\\apache-maven-3.6.0\\bin\\mvn.cmd\" -Dmaven.ext.class.path=\"C:\\Program Files\\Netbeans 10.0\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install\""
Building Project-source 2.9
--- maven-clean-plugin:2.5:clean (default-clean) # Project-source ---
Deleting D:\Project\Project-source\target
--- maven-resources-plugin:3.1.0:resources (default-resources) # Project-source ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource
--- maven-compiler-plugin:3.8.0:compile (default-compile) # Project-source ---
Changes detected - recompiling the module!
Compiling 1 source file to D:\Project\Project-source\target\classes
--- nbm-maven-plugin:4.1:manifest (default-manifest) # Project-source ---
NBM Plugin generates manifest
Adding OSGi bundle dependency - javax.annotation:javax.annotation-api
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest (default-manifest) on project Project-source:
Execution default-manifest of goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest failed.: IllegalArgumentException
EDIT
i have tried to remove nbm-maven-plugin as suggested but this change the structure of Project and i don't know how to reinclude this module
Please use the 4.2 version like this:
<groupId>org.apache.netbeans.utilities</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<version>4.2</version>
replacing any references to:
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
jar file generated by jdk>8 cannot be parsed by older version of the plugin.
In your example nbm-maven-plugin fails but the compilation process is fine.
Temporarily remove nbm-maven-plugin from your build and see if Maven can build without it. Perhaps you can skip this plugin altogether as it seems specific only to NetBeans IDE.

GWT Maven project made with WebAppCreator don't work in devmode

I have created a GWT project with maven configuration on this way :
webAppCreator -out HelloWorldGWT -templates sample,maven,readme ua.vitvyaz.hellowordgwt.HelloWorldGWT
I tried to run project on devmode :
mvn gwt:devmode
But in the browser i got :
"HTTP ERROR 404
Problem accessing /HelloWorldGWT.html.
Reason: Not Found"
I looked, the directory WEB-INF was empty.
What is wrong in pom.xml?
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>ua.vitvyaz.hellowordgwt</groupId>
<artifactId>HelloWorldGWT</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ua.vitvyaz.hellowordgwt.HelloWorldGWT</name>
<properties>
<!-- Setting maven.compiler.source to something different to 1.8
needs that you configure the sourceLevel in gwt-maven-plugin since
GWT compiler 2.8 requires 1.8 (see gwt-maven-plugin block below) -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Don't let your Mac use a crazy non-standard encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- ensure all GWT deps use the same version (unless overridden) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>2.8.0-rc1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- GWT Maven Plugin-->
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0-rc-6</version>
<executions>
<execution>
<goals>
<goal>import-sources</goal>
<goal>compile</goal>
<goal>import-test-sources</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleName>ua.vitvyaz.hellowordgwt.HelloWorldGWT</moduleName>
<moduleShortName>HelloWorldGWT</moduleShortName>
<failOnError>true</failOnError>
<!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use
a different source language for java compilation -->
<sourceLevel>1.8</sourceLevel>
<!-- Compiler configuration -->
<compilerArgs>
<!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
<arg>-compileReport</arg>
<arg>-XcompilerMetrics</arg>
</compilerArgs>
<!-- DevMode configuration -->
<warDir>${project.build.directory}/${project.build.finalName}</warDir>
<classpathScope>compile+runtime</classpathScope>
<!-- URL(s) that should be opened by DevMode (gwt:devmode). -->
<startupUrls>
<startupUrl>HelloWorldGWT.html</startupUrl>
</startupUrls>
</configuration>
</plugin>
<!-- Skip normal test execution, we use gwt:test instead -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
From the README.txt that webAppCreator generated:
-- Option D: Using Maven --
If you have generated your project with the option '-maven', you have a 'pom.xml'
file ready to use. Assuming you have Maven installed in your system, 'mvn' is
in your path, and you have access to maven repositories, you should be able to run:
mvn clean # delete temporary stuff
mvn test # run all the tests (gwt and junit)
mvn gwt:devmode # run development mode (needs "mvn package" to be run before)
mvn package # generate a .war package ready to deploy
For more information about other available goals, read Maven and gwt-maven-plugin
documentation (http://maven.apache.org, https://tbroyer.github.io/gwt-maven-plugin/)
so first run mvn package, then mvn run:devmode.
The website still documents GWT 2.7, not 2.8 (as of September 2016).
from the GWT Documentation page you should run mvn gwt:run to bring up the new application in superDevMode.
UPDATE
You have to build your project prior running it. In other words try:
mvn clean package gwt:devmode
It should work now.

maven support for android projects?

I want to start a project for Android but i really like to build it using Maven. Does Google provide support for Maven or plan to support it? It would be great if anybody know at least an archetype for Maven that I can use meanwhile. Thanks in advance.
Seems like there is a maven plugin for that :-)
What I really wanted was an article like this, but i found it after the question was answered.
Update:
People at SpringSource did a Spring Android project that supports the usage of the Spring Framework in an Android environment and have Maven support. I will give it a try.
Here is an article about Spring Android and Maven using Eclipse 3.6 and Android SDK 9, split in two parts:
First part
Second part
The Android Maven plugin has been updated to support changes made in the Android SDK r14 release. You will need to adjust your POM to use the new version. I experienced an out of memory error with the new version when building my app, so note the dex jvmArguments section to allow for more available memory.
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.0.0-alpha-13</version>
<configuration>
<sdk>
<platform>${android-platform}</platform>
</sdk>
<dex>
<jvmArguments>
<jvmArgument>-Xms256m</jvmArgument>
<jvmArgument>-Xmx512m</jvmArgument>
</jvmArguments>
</dex>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
The latest version of the Android Configurator (m2e-android) for Eclipse also supports the changes in r14. Lastly, I've posted a follow up blog on the SpringSource site called Updated Maven Support for Android Projects, which goes over these updates to the tools.
Here is what I did to add maven support to an existing android project in Eclipse. I installed the 'm2e' plugin via the Eclipse market place. Then I installed the 'm2e-android' plugin. At the moment it is called 'Android Configurator for M2E' in Eclipse market place. After installing the two plugins and restarting Eclipse, right click on an existing android project-->Configure-->Convert to Maven Project. Choose a unique group id and an artifact id for your project then click finish. Copy the following contents to the pom.xml of the project and replace all the existing contents. Change the value of the 'version' tag under 'dependencies' to the SDK version you are using. Also change the value of the 'platform' tag near the end of the file to the value of your platform. Do not forget to also change the groupId, artifactId and name of the xml.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.myproject</groupId>
<artifactId>MyProject</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>MyProject</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<!-- platform or api level (api level 4 = platform 1.6)-->
<platform>10</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
After that right click on the project-->Maven-->Update Project. If Eclipse is complaining about errors in the xml, you may want to install maven then run
mvn clean install
from the console in the folder that contains the pom.xml file.
as #Riduidel said before, you can use com.jayway.maven.plugins.android.generation2 plugin. Note, that you don't need download any plugins, you need to have just the maven for using this plugin.
How I did it:
manually add pom.xml to your android project (to the root of project).
download apache-maven-3.1.1 and add your bin folder ( ex D:\java\apache-maven-3.1.1\bin;) to path in Environment Variables.
configure settings.xml in [Your_maven_path]\conf with next:
<pluginGroups>
<pluginGroup>com.jayway.maven.plugins.android.generation2</pluginGroup>
</pluginGroups>
Add content to pom.xml. My example:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.ENumbers</groupId>
<artifactId>ENumbers</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<name>MainApp</name>
<properties>
<platform.version>2.2.1</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>stax</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<path>
D:\Program Files\Android\android-sdk
</path>
<platform>22</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Look at important <packaging>, <build> nodes, it's content and com.google.android dependency.
Now you can open Maven window in your IDE. For Intellij Idea I do it next:
Edit->Tool Windows->Maven and add your pom.xml for initializing maven directory.
That's all.

Categories

Resources