How can I change libraries on Eclipse with Maven builder?
When I change my JRE library by the project properties and then rebuild a project JRE returns to previous version.
How can I add a new library?
A library is just a dependency. You can add dependencies to you pom-file:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
This add the junit-library.
When I change my JRE library by the project properties and then rebuild a project JRE returns to previous version.
This is the case with m2eclipse/m2e, as the Eclipse plugin will revert any changes made to the project properties. In most cases, you're better off specifying the version of the source code, and the target version of the bytecode, via the maven-compiler-plugin configuration:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin<artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
M2Eclipse/M2E uses these values in the project POM to determine the Java runtime to use for building the project. Considering that it never makes sense (or is impossible) to have multiple Java runtimes for an Eclipse project, you ought to specify the source and target values for the project, either in the project POM or in a parent POM.
If you are using Maven, then you control all your dependencies via the pom.xml file. You can either use the maven eclipse plugin to generate the eclipse artifacts, or my preferred approach which is to use the m2eclipse plugin. This plugin makes it easy to keep maven and the eclipse workspace in sync.
Related
Using IntelliJ 12, I have a java project and I use maven with a pom.xml.
My project is using java8, but it seems the default project language level has been set to 6 while importing the project.
I can change the language level to 8.0 (F4 -> Modules -> Language level) however every time I edit my pom.xml the project level is switched back to "use project language level", and I have to edit this settings again and again.
Is there something I need to add to the pom.xml to set the default language level to 8.0?
As per Mark's comment, here is how to do it:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
A shorter version of vikingsteve's answer is:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
I'm upgrading a project from JDK 8 to JDK 10+. I had the compiler properties specified correctly as follows:
<properties>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
However the Idea project would keep resetting the language level to 8.
Eventually I figured out that Idea's Maven import process was using JDK 8 to import the project which limited the language level to <= 8.
To fix I updated the 'JDK for importer' property under Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing to use JDK 11.
I think this has to do with a conceptual conflict between the Maven compiler plugin and IntelliJ idea. Apparently the newer versions of the compiler plugin have a default level of 1.5 (see http://maven.apache.org/plugins/maven-compiler-plugin/). So if the compiler plugin is used at all in a project, and the compiler level is not explicitly set in the pom.xml, whenever the POM is re-processed the level will revert to the default.
So there is a conceptual conflict which is ignored by Intellij IDEA. The IDE still allows one to set the project and module settings, but provides no warning or feedback that this setting is controlled by pom.xml. Solutions would either be to explicitly allow overriding the POM compiler plugin setting (perhaps not wise because what then happens when you use maven on the command line), or to deactivate the controls in the IDE when this setting from the POM is in effect.
The solution at the present time is to set the desired compiler level in the compiler plugin in the pom, the re-import, rather than trying to set it in module settings.
There are two ways of doing this, add either one of them in your pom.xml file:
First- Add Properties
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
second- Add Plugin
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Let me know if it helps.
None of the solutions helped in my case. I didn’t need to specify any Java version in my pom.xml.
I needed to open the <project-name>.iml file and change the JDK version there.
Original:
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<!-- ... ^ -->
<!-- ... | -->
Updated:
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<!-- ... ^ -->
<!-- ... | -->
This makes no sense at all. At no point have I specified a JDK version for Java 1.5.
What solved the issue for me was a list of updates:
In Project Structure > modules: changes the language level Java version to 8
In Project Structure > Project: Java version should be 1.8
In pom file, same changes specified in the responses above
In Settings > Java compiler > changed the bytecode versions to 8
In Settings > maven > importing > JDK for importer should be 1.8
I struggled a lot with this problem, due to building microservices with Dropwizard. Eventually I found out that I had my build properties in the wrong pom file (The main service's pom.xml).
So, even though the other packages are more like libraries, I were not able to use the Java 8 syntax.
When I refactored the build plugin into the "global" .pom.xml" file, all child containers were able to use the new syntax.
May help someone having issues with multi-container projects
thank you it works.
be careful not to make the same mistake I did.
if you have profiles, add the plugin in the right profile.
<profiles>
<profile>
<id>foo</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>bar</id>
.......
</profile>
<profiles>
For me the solution of updating the POM (plugins plus properties) to the required Java compiler version (1_7 in my case) worked.
However as the .iml file for each project was generated with original pom (with default compiler version of 1_5 as explained by someone above) has a JDK version of 1_5, this still overrides the pom version.
I deleted the .idea folder manually and imported the module into IntelliJ with a reimport from the updated pom. When I reimported the Module from updated POM,I could see that the iml files had the updated JDK version (1_7 in my case) .
There was one additional step I had to follow, in addition to setting the maven build properties, adding the maven-compiler-plugin, and modifying the Java version in the .iml file. (each documented already in the other answers). You also have to set the compiler version in the settings.
Problem: Expected Java version: 11 but Stuck at version: 8
I tried almost all the answers, still I was stuck with language_level 8 and nowhere in my project or in the Intellij IDE I found any trace that could relate to Java version 8.
Then I explored the pom.xml of the parent with no success but in the pom.xml of the grand-parent, I found that the release version is 8.
Solution:
Adding the following 3 lines in the properties made the difference.
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
</properties>
I am using specific jar library, provided via Maven vendor-specific repository. There is only jar file in the repository, i.e. no sources and no javadocs.
But I know, that sources are available online, in SVN repository. Can I tell Maven to download sources of specific JAR from specific SVN location and may be from specific revision number?
No you can't tell maven to download sources from a SVN repository. Maven expects all kinds of artifacts within the appropriate Maven repository.
What you can do is to tell Maven in which Repository to look for the libraries including the resources.
If the sources are not available in a Maven repostory format, you can tell your IDE (e.g. Eclipse) to link them directly from a location on your hard disk.
Jars are not stored in SVN repositories, they're stored in artifact repositories when working with Maven. Keeping binary artifacts (such as jar files) under version control is considered bad practice.
If you would like to check if a certain artifact produces a sources or javadoc artifact which is available via Maven Central, then you can check in:
http://search.maven.org/
http://www.jarvana.com/
http://findjar.com/
If you have your own Maven repository (such as Nexus, Artifactory), etc, you can use it as well.
If I understand you correctly, your problem is that the sources for these artifacts are not being displayed in your IDE. If this is the case and you are sure they produce source/javadoc artifacts, then you can set up your IDE to resolve these dependencies.
If you're using Eclipse, you will need something along the lines of:
<project ...>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
In the pom.xml file you have to set the dependencies, for example:
<dependency>
<groupId> junit </ groupId>
<artifactId> junit </ artifactId>
<scope> test </ scope>
<version> 4.10 </ version>
</ dependency>
I think you can not see it for revisions, look for the libraries including the resources and dependencies of pom.xml.
I'm using Eclipse EE 3.7 with m2e plugin installed. I have JDK7 set in eclipse.
When I import maven projects, the JRE is set to JRE System Library [J2SE-1.5], So i have compilation issues with java 6 related stuff. Instead I want the JRE in eclipse to be by default set to JRE System Library [J2SE-1.6]
When i try to open a new project in eclipse File -> new -> Java project on the first screen i have an option to choose JRE and the third option is Use default JRE (currently 'jdk1.7.0_03')
From this i can see that the default JRE in Eclipse is 1.7, but when i import new Maven projects, the JRE is set to 1.5 by default.
Any help, how can i do this?
The problem is not with Eclipse, but with the projects you're importing. m2e will set the project's JRE to match the maven project. The POM specifies the JRE version, and this is defaulted to 1.5 if not present. You need this in the POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
artbristol gave the correct answer (and I upvoted him).
That was in 2012. Here is an update more appropriate for today (2016, Java 8, Spring 4.x/Servlet 3.x):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
The root cause of this issue is Eclipse cannot resolve a valid value for the maven.compiler.source property when updating the .classpath file from the pom, it is simply using default one i.e
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5.
Just Add following properties into you pom.xml and update project:
<properties>
<javaVersion>1.8</javaVersion>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
You can have your brand new Maven project in Eclipse have JRE System Library version other than JavaSE-1.5. For that,find below jar in the following location.
File: maven-compiler-plugin-3.1.jar
Location:
.m2\repository\org\apache\maven\plugins\maven-compiler-plugin\3.1
Then unzip the jar and locate "META-INF\maven\plugin.xml" which has four occurrences of default-value="1.5". Replace all four 1.5 with 1.8 or whatever the version you want. You would know the rest of the process.
Reference
I have 2 Maven web projects A and B. B contains some common parts and A depends on B.
In A's pom.xml I have:
<dependencies>
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>B</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
</build>
I have 2 problems:
When making some changes in B, if I run a maven build on A I don't see the changes in the resulting exploded archive.
Trying to deploy A from Eclipse does not work - the contents of B are not included in the resulting war/exploded archive.
Thanks for your help.
Well, if you changes stuff in B, you have to re-install it into your local maven repo (mvn install) for other local projects that have it as dependency to receive the latest modifications.
When building a maven project it's best if you build it using Maven (like with commands such as mvn package) and not using some other building tool (such as Eclipse). If you wanna build it a la Maven but from the comfort of your Eclipse GUI, you can istall m2_eclipse plugin from :
http://m2eclipse.sonatype.org/installing-m2eclipse.html
which integrates Maven with Eclipse. Then, when you rigth click on your project in Eclipse, under the "Run..." options you'll have the one that allows your to Maven build it, redirecting all console output to the Eclipse console window.
And as a final note, in a setup such as the one aboce, ideally you'd create a parent Maven project (packaged as "pom") which has as child projects B and A (in that order). This way if you've modified stuff in both projects and you want everything to be build with the latest modifs, you can just do a maven install on the parent pom and Maven will take care of everything.
Amplifying #AndreiBodnarescu's point, you may not be seeing the changes you made to project-B when you build project-A because the changes aren't available in the Maven repository.
If project-B is being built on the same machine can you ensure that you used mvn install to install to your local repository? If project-B is being derived from a build on a different machine then use mvn deploy to deploy project-B to a common shared repository. In this case you may still not pick up project-B if you aren't using SNAPSHOTted versioning or you don't increment project-B's version number.
I see that B is of type war. What is the packaging of A? Is it an EAR? If so using the maven-war-plugin with project-A is not going to be of help.
Does anyone know of a good guide for creating a project with the new 2.0 release of GWT using maven and eclipse? I am running into a lot of problems getting them to play nicely together.
For what it's worth, I can create a gwt project using the maven eclipse plugin which works fine, but porting it to maven doesn't work (so a guide for this would be great).
Likewise, I can use the maven plugin (gwt-maven-plugin), but when I import it to eclipse (import -> materialize maven projects), it does not get recognised as a GWT project...
Thanks
EDIT: I've updated my answer with additional steps provided by the OP. Credits to the OP for the details.
I just broke my Eclipse setup trying to install the latest version of the Google Plugin for Eclipse (for GWT 2.0) so I can't confirm everything but, let's assume the following prerequisites are fulfilled:
Eclipse 3.5
Google Plugin for Eclipse (installed from http://dl.google.com/eclipse/plugin/3.5, see instructions)
m2eclipse Plugin for Eclipse (installed from http://m2eclipse.sonatype.org/update)
Did you try to:
Create a new project from Eclipse (New > Other... then select Maven Project and choose the gwt-maven-plugin archetype).
Edit the generated pom.xml, update the gwt.version property to 2.0.0 (which has been released in the central repo), add the Codehaus Snapshot repository and set the gwt-maven-plugin version to 1.2-SNAPSHOT (the version 1.2 isn't released in central, this should happen soon) 1.2 (which has been released in central too).
Add a <runTarget> to the gwt-maven-plugin configuration as documented in Using the Google Eclipse Plugin.
Configure the maven-war-plugin as documented in the page mentioned in the previous step.
Manually enable GWT on the project from project preference by setting the Use Google Web Toolkit checkbox This step is unnecessary since you'll be building/running with a Maven run configuration, not the GWT Plugin for Eclipse.
This is how my pom.xml actually looks like:
<?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">
<!--
GWT-Maven archetype generated POM
-->
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.demo</groupId>
<artifactId>my-gwtapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>gwt-maven-archetype-project</name>
<properties>
<!-- convenience to define GWT version in one place -->
<gwt.version>2.0.0</gwt.version>
<!-- tell the compiler we can use 1.5 -->
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
<dependencies>
<!-- GWT dependencies (from central repo) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>com.mycompany.demo.gwt.Application/Application.html</runTarget>
</configuration>
</plugin>
<!--
If you want to use the target/web.xml file mergewebxml produces,
tell the war plugin to use it.
Also, exclude what you want from the final artifact here.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>target/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<warSourceDirectory>war</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run the gwt:eclipse goal (using m2eclipse Maven2 > build...) to setup your environment and create the launch configuration for your GWT modules.
Run gwt:compile gwt:run to compile and run a GWT module in the GWT Hosted mode.
You can run the following command to generate a Maven GWT project:
webAppCreator -maven -noant -out
For more information:
GWT webappcreator creating a Maven project: the source attachment does not contain the source for the file URLClassPath.class
Just in case. If you use Google GIN in your project you should add compile goal before gwt:compile. So the whole sequence would be:
compile gwt:compile gwt:run
You can read explanation here:
http://code.google.com/p/google-gin/wiki/GinTutorial#Compilation
An annoying problem with GWT and m2eclipse:
GWT Development Mode requires all JARs
to be placed in WEB-INF/lib. It's
especially painful when programmers
use m2eclipse, which provides its own
Eclipse classpath container.
http://code.google.com/p/google-web-toolkit/issues/detail?id=5693
good news, the workaround is working for me
very useful thread
#Pascal: thank you (I donot have enough reputations to comment on others posts; so here I am posting on what is working for me).
I needed 2.5.1 GWT (not 2.6, the latest) working with maven and eclipse (because sencha GXT is not supported for 2.6 yet). Tried following without luck
1)tried few archetypes with in eclipse to generate the project
2)modify pom file (based on above discussion) to change versions to 2.5.1
Following worked for me http://mojo.codehaus.org/gwt-maven-plugin/user-guide/archetype.html
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.5.1
mvn gwt:eclipse
mvn gwt:run