"doubled POM" error when running m2e in eclipse - java

We recently experience the problem that POMs in the local repository are broken in a special way: The content of the POM appears twice, or, in some cases, just some end part of the POM appears twice. So these POMs look like
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
...
</project>
...
</project>
Obviously, these POMs cannot be read correctly.
One case in which the problem appears often is the following workflow:
Remove the local repository
Start Eclipse with an existing workspace
(Immediately) start a build inside Eclipse.
My guess is that m2e does not properly handle concurrency. The automatic download of dependencies in the background and the build try to download the same POMs at roughly the same time.
Is my analysis correct?
If so, can I do anything about it?
If not, what is the explanation?
EDIT
It seems that the error also occurs if one only starts Eclipse with a lot of projects in the workspace (without starting a in-Eclipse build).

Related

VS Code can not run non-Spring Maven project correctly

I must apologize if it is a duplicate question, but I googled first without getting a useful answer.
Description
Today I'm trying to migrate from IDEA to VS Code, but when running a non-spring Maven project in VS Code, it won't run with dependencies in pom.xml, I can only get Exception in thread "main" java.lang.NoClassDefFoundError in console.
Here I'll provided a brief example:
The project shown below use fastjson to parse a Map to JSON string, the fastjson is a maven repository defined in pom.xml.
Project Structure
App.java
package com.example;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
public class App {
public static void main(String[] args) {
Map<String, String> item = new HashMap<>();
item.put("a", "1");
item.put("b", "2");
System.out.println(JSON.toJSONString(item));
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1</version>
<name>demo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.78</version>
</dependency>
</dependencies>
</project>
Maven Dependencies Shown in VS Code
Try to run the project with Run and Debug in VS Code
Result
Look! The VS Code did not run this Maven project correctly, it did not run with dependencies in pom.xml!
Trivia
I have installed Extension Pack for Java for VS Code
I even installed Spring Boot Extension Pack for VS Code
I have installed Maven and configured corresponding Environment Variable, mvn command is able to run in console
The project above is running correctly in IDEA
Spring project is able to run normally in VS Code, but the problem project is maven without Spring
Help
Did I miss some configurations for VS Code to run Maven project? What should I do to make it running correctly in VS Code?
Your code throws no errors in my project:
I think there's a cache messed it, you may
Turn to local dependency installation folder, delete \User folder\.m2\repository\com\alibaba\fastjson\1.2.78
Delete the dependency fastjson in pom.xml
Open Command Palette and choose Java: Clean Java Language Server Workspace
re-add the fastjson dependency and follow the notification to synchronize project configuration.
Finally, I resolved my problem with VS Code myself. I put my solution here in case someone or I met the same problem in the future.
To solve the issue:
I moved my maven dependencies path to else where: I created a folder G:\maven-repo, and modified global settings.xml of maven like below:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>G:/maven-repo</localRepository>
</settings>
In settings.json of VS Code, I added the line below, which refers to where the settings.xml in step 1 is:
"java.configuration.maven.globalSettings": "G:/ideaIU/plugins/maven/lib/maven3/conf/settings.xml"
Restart VS Code, execute Java: Clean Java Language Server Workspace as #Molly Wang-MSFT said.
After restarting VS Code again, pressing the F5 key, the project finally runs correctly.

How to resolve dependencies on JNLP with Maven

I'm working on a Slick 2D project, with JDK 15, using Eclipse 09-2020, and I am resolving my dependencies via Maven. When I add Slick2D to pom.xml, it shows an error in the IDE at xsi:schemaLocation, saying "Missing artifact javax.jnlp:jnlp-api:jar:5.0"
I've tried re-downloading Java, resetting my JAVA_HOME variable, but to no avail. The other problems that I've come across reference "javaw.jar" in the lib directory, but that is not present in my JDK. How do I solve this?
Here's my pom.xml, if it helps:
<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>
<groupId>org.newproject</groupId>
<artifactId>newapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Slick Based API</name>
<dependencies>
<dependency>
<groupId>org.slick2d</groupId>
<artifactId>slick2d-core</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
Just a general note: The slick project seems dead. The official source repo has been taken offline. I would probably not use it for a completely new project.
But now to your question:
Java Webstart has been removed starting from Java11 since oracle did not opensource it. So what can you do?
You downgrade to Java 9/10
You use https://openwebstart.com (some adaptions might be necessary)
You remove JNLP from the project (since there are other means to start it)
Some other guy seems to have taken up the project. You can find it on github. In one of the forks JNLP has been removed, too.

maven can't download dependency Illegal character in path

The problem I'm facing here is that i can't download a pom from the local artifactory. (the pom is there)
To give a short overview about the projects i'm dealing with:
first of all there are 2 projects
one is the base project and there i declared in the parent pom the version like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>x.x.x.x</groupId>
<artifactId>x</artifactId>
<version>${global.version}</version>
<packaging>pom</packaging>
...
<properties>
<global.version>x.x.x-SNAPSHOT</global.version>
</properties>
</project>
the other one is declared the same way
now in the second project there is a dependency to the first project and if i want to build it there is an error popping up
Illegal character in path at index 29: URL/artifactory/x/x/x/x/x/x/${global.version}/x-${global.version}.pom
i know it is telling me to eliminate the ${global.version} but is there an other way to fix this up?
I fix it up some how...
The main problem here was the artifactory i think.
Whenever i deployed the maven project 1 to the artifactory there where these relative version instructions ${global.version} still written in the pom.
That's why every time project 2 wants to load the dependency it cant find the path.
So it's back to standard version declaration.

Maven - using version in the dependency

I have a new app, the pom for which has parent tags and all. I have to include in this app another dependency whose parent is different than the current apps parent. The problem is the version tag for the new dependency.
The current pom :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>
<artifactId>abc-pom</artifactId>
<groupId>com.abc</groupId>
<version>4.480.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<groupId>com.abc.libs</groupId>
<artifactId>dynamixSession</artifactId>
<packaging>jar</packaging>
<name>dynamixSession</name>
.....
.....
<dependency>
<groupId>com.pqr.someOtherProject</groupId>
<artifactId>SomeCoreProcessing</artifactId>
<version>4.2.14.2-SNAPSHOT</version>
<!-- <version>${project.version}</version>-->
<scope>provided</scope>
</dependency>
This pom works. Since I am hardcoding version number here, do I need to update this pom everytime the version changes ? Or will it be updated automatically. But I doubt that it updates automatically.
I would like to use '${project.version}' so that I don't have to update it. But if I use '${project.version}' it tries to look for 'com.pqr.someOtherProject.SomeCoreProcessing:4.480.0-SNAPSHOT', which is not existing.
Is there a way arround this or am I stuck with harcoding the version in my pom ?
Thanks
You can use versions plugin to achieve that. It would be the easiest way. The plugins is especially used for these kind of requirements.
But it would not be automatically updated. You would need to execute versions:use-latest-snapshots goal.
If you are using a continuous integration tool (e.g. Jenkins) you can automate this with nightly builds or some other way.
Just have a look at below link to see all the details of versions plugin. It is nicely documented.
http://mojo.codehaus.org/versions-maven-plugin/
Why don't you try {env.SomeCoreProcessing_version} instead? Just make sure you set/export the SomeCoreProcessing_version variable before kick starting your build.

Having a maven project build its own dependencies?

With maven is it possible to have a top-level project who's packaging type is "war" which will build itself and all of its dependent modules (packaged as jar) and have the build generate a project.war file?
Much of the documentation examples and other examples I've seen often use a top-level project with packaging type of "pom" and the project only serves the purpose of tying the modules together. Can I avoid this?
So basically I need something which is effectively like declaring a <module>my-module</module> for maven to build, and in that same POM, declaring a <dependency>...my-module's artifact...</dependency> on that same module which needs to be built. Maybe a plugin as someone already suggested?
Update: In other words (to simplify the problem): If I have project A and project B, where project A depends on project B - is there a way for me to execute a build on project A and also have it automatically build project B (and include project B as its dependency - creating projectA.war which contains projectB.jar)?
super_aardvark suggested correct way but,
For requirement I would suggest following structure It is suitable and good structure also :
Consedering ProjectA as project-webapp , ProjectB as project-core
You can have following structure :
Your Grand Project :
<?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.mycompany.project</groupId>
<artifactId>project</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Project Repository System</name>
<description>Project Repository System R2</description>
<modules>
<module>project-core</module>
<module>project-webapp</module>
</modules>
</project>
Your WebApp Project:
<?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">
<parent>
<groupId>com.mycompany.project</groupId>
<artifactId>project</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project-webapp</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Project Web Application</name>
<description>Project Repository</description>
<dependency>
<groupId>com.mycompany.project</groupId>
<artifactId>project-core</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</project>
Your Core Project:
<project>
<parent>
<groupId>com.mycompany.project</groupId>
<artifactId>project</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project-core</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Project Core</name>
<description>ProjectCore</description>
</project>
Your Directory structure should look like:
-------Grand Parent.pom
|
|--------project-webapp
| |
| project-webapp.pom
|
| -------project-core.pom
|
project-core.pom
From parent pom execute mvn clean install it will build both the web-app and core project
That's not really what a top-level project is for. Your WAR project has dependencies, which are the artifacts (e.g. jars) that will be included in the WAR (in WEB-INF/lib) when you run 'mvn package'. Your WAR project pom can have the top-level project as its parent, but it shouldn't be the parent of its dependencies. You may want to have that top-level project be the parent of both the WAR project and of the JAR projects that are dependencies in the WAR.
This is not possible in Maven 1, 2 or 3.
I'd recommend to give up this idea, because Maven's whole purpose is to enforce standardized development process. Don't fight the structure, just create a parent POM module and make the WAR module and other dependencies underneath it.
When you have a multi-module project and you're doing work in several modules simultaneously it can be tedious and error-prone to make sure all the necessary dependencies are updated.
In my situation, I would like my build system to detect changes and only build the modules that are necessary. One way this might be possible with maven is for someone to write a custom plugin that does this, which doesn't seem insurmountable given there are already complex plugins available, like the maven release plugin.
Others have already mentioned the aggregation pom concept, which is repeatable and does produce the necessary artifacts. But sometimes you end up building more than you really need to.
Maven profiles can help and here's a good article in that regard:
Using Aggregate and Parent POMs
Also note in the article the concept of the batch pom, which I was not previously aware of.
Remember, mvn clean install will push your artifact into your local repo. So if module A depends on module B, as long as your local repo has the latest build of module B then you should be all set. So, if there were an external tool that was watching for changes to module B and automatically built it when there were and pushed those changes into the local repo then when module A was rebuilt it would pick up those changes. There are continuous integration (CI) tools that can do this, like Jenkins. But you would need a local install to have this work directly with your local repo. It's still an option, though.
Another option would be for the CI environment to push your builds to an external maven repo (or even one you setup locally with something like Nexus). Then you setup your CI builds to pull from that location as well.
So, there are solutions that rely on other tools or potential plugins to do what you want - just depends how much time and effort you want to invest to get it all setup. But, once you get over that hurdle you'll have a system (and knowledge and experience) that you can use on all your projects, not to mention you'll be familiar with how many development shops/teams work.
I would recommend researching continuous integration and continuous delivery for more information and ideas.
In parent pom, you have to define a sequential order of modules to be compiled. You can add a war packing module to the last in that list. It will simply aggregate all previous compiled code together.
Not really - (Well, I can think of a couple of ways, but I'd not use them as they're convoluted and go against the basic ethos/practices of Maven).
Don't forget that the other purpose of the top-level pom is to provide a single point to set common details such the particular versions of dependencies used in the modules of the project.
NetBeans has an option that allows you to do exactly this with Maven projects but I don't know any pure Maven solutions. I think that the task is more suited for an IDE, because it knows for what depended projects you have the code (based of what projects you have opened in the workspace). How would Maven itself differentiate between a dependency that you want to build and one that needs to be fetched from the repository. And for those that need to be built, where should it look for the source code?
Anyway, another solution to the problem, that I used successfully a few times, is to create a simple shell script that navigates to your projects folders and starts the build then it waits for it to finish then proceeds to the next project and so on.

Categories