I am working on a Java project which is managed by Maven.
The project actually is composed of three sub-projects:
- Backend
- Builder
- Frontend
Every single of those projects is Maven based and the Builder works as a bridge between Frontend and backend.
In fact the Builder is the parent project for all of them.
The pom.xml of the Builder is as follows:
...
<modules>
<module>Model</module>
</modules>
...
Whereas the Model has pom.xml like this:
...
<parent>
<groupId>...</groupId>
<artifactId>Builder</artifactId>
<version>1.0.0.0</version>
</parent>
<artifactId>Model</artifactId>
<build>
*Backend build directives*
</build>
...
The problem is that from Visual studio Code i can build every single module successfully without errors but the code editor gives me "import cannot be resolved.." wherever i have dependecies towards backend.
I came to think that this is a bug of the "Java Language Support by RedHat" which cannot find dependencies ...
Has this happened to anybody?
--- Edit 28/11/2019 ---
I forgot to clearify that all of the Builder's dependencies (so towards Backend and other Util libraries) are resolved correctly as I can see those Jars inside Frontend's resolved dependencies folder.
you could try like this:
in your parent project pom.xml:
<groupId>com.blackr</groupId>
<artifactId>cloudtest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
in your child project pom.xml:
<artifactId>module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.blackr</groupId>
<artifactId>cloudtest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath> //Location of the parent project's pom.xml file
</parent>
Related
My goal is to turn an existing maven project (char-counter) into a module of my multi-module maven project. How can I do this? I use Eclipse 4.16.0.
Here is the structure of my projects.
You can include the sub-modules inside your parent maven project in following way.
Inside your multi-module-project pom.xml
<modules>
<module>char-counter</module>
</modules>
See here: Maven Multiple module
Assuming that you want to convert your char-counter project to multi-module-project.
You need to have following in your multi-module-project pom.
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>Anagram<module>
<module>Calculator<module>
</modules
And then in Anagram project's pom :
<parent>
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.child</groupId>
<artifactId>Anagram</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
And in Calculator project's pom:
<parent>
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.child</groupId>
<artifactId>Calcultor</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
Also you need to add dependency of one module to other,in which you want to use the code from other module and then you need to deploy the artifact(module) which has dependency included in it and has starting point to run (like main).
I have two Maven projects "SomeSuperName1" and "SomeSuperName2"
Both of these projects have an aggregator pom like this
<parent>
<groupId>com.company.yeah</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath/>
</parent>
<groupId>com.company.yeah.myapp</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<name>SomeSuperName1</name>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>Child1</module>
<module>Child2</module>
</modules>
A module pom look like this
<parent>
<groupId>com.company.yeah.myapp</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>Child1</artifactId>
<packaging>pom</packaging>
I want IntelliJ to show both projects in the project view using the Maven name "Some Super Name", i.e. like
- "SomeSuperName1"
- "SomeSuperName2"
but it constantly fails doing so. Instead the first project is added as "Some Super Name" while the other is put in a module group structure like
- "SomeSuperName1"
- parent (1) (com
- company
- yeah
- SomeSuperName2
I disabled "Create module groups for multi-module Maven projects" before importing both projects but no success.
Also importing via the "Maven Projects" View or via the File->New->Module from existing Sources doesn't help. Can anyone help pls? Problem is it's not only ugly imho but jumping to classes/methods doesn't work anymore. A workaround is to rename the module from "parent (1) (com.company.yeah.SomeSuperName2)" to just SomeSuperName2 but this change is gone when restarting IntelliJ.
This has nothing to do with IntelliJ. Your pom file (or project structure) is misconfigured.
I think this will work.
<groupId>com.company.yeah.myapp</groupId>
<artifactId>SomeSuperName</artifactId>
<packaging>pom</packaging>
<name>Here you can put any name</name>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>SomeSuperName1</module>
<module>SomeSuperName2</module>
</modules>
Here you can find a nice reference.
Hope that helps.
I have two dependencies one of them is built on top of the other.
The first project is with POM
<parent>
<groupId>com.company</groupId>
<artifactId>bom</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<groupId>com.company.site</groupId>
<artifactId>site</artifactId>
<packaging>war</packaging>
<dependency>
<groupId>com.company.platform</groupId>
<artifactId>platform</artifactId>
</dependency>
This project is built on top of another project (dependence)
which have the following POM
<parent>
<groupId>com.company</groupId>
<artifactId>bom</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>platform</artifactId>
<packaging>pom</packaging>
How can I import these two projects in Intellij so when i make changes in sources in the platform project, these projects two be available in site project.
I have access to both depositories and their sources.
Best regards.
If you must have 2 projects (instead of a single multi-module project) it's really quite simple - open two intellij windows, one for site and one for platform.
Next, you need to define group and version for platform.
<groupId>com.company.platform</groupId>
<artifactId>platform</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
Now update the pom for site with the 1.0.0-SNAPSHOT version for platform dependency.
Your workflow is like this:
make change in platform project, use Maveh Projects window to build (clean install)
switch to site project, which depends on platform-1.0.0-SNAPSHOT, use Maven Projects window to Reimport all Maven Projects
You should then see the code updates from platform in site project.
When you want to go in production you need to go from -SNAPSHOT to release (non-snapshot) dependencies.
I have an existing web project which currently uses Ant. I have tasks that:
create the jar based on only certain packages for other applications which use this project as a dependency
create the war file for the app
and a lot of others.
Separately I have a webservice project which uses the jar built by the previous application. This project uses Maven.
Now what I want to achieve is to move the first project to Maven, break it into core and web, and then move the webservice project into the first one.
So the result will be a multi-module project:
core
ui
webservice
Is it possible to move the sources that deal with the web delivery mechanism into the ui module (which will be a war in Maven), or I need to keep the sources in the core?
What would the best approach to do this be?
Should I look into Maven profiles?
I am a novice with Maven, so I am unsure on how to approach this.
Yes you can achieve what you want with Maven. I would break the modules like this:
Core:
<groupId>com.myapp</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
UI:
<groupId>com.myapp</groupId>
<artifactId>ui</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<!-- Dependends on core -->
<dependency>
<groupId>com.myapp</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Web service:
<groupId>com.myapp</groupId>
<artifactId>ws</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<!-- Also Dependends on core -->
<dependency>
<groupId>com.myapp</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Main Project:
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>core</module>
<module>ui</module>
<module>ws</module>
</modules>
Then, in Core / UI and Web service you declare myapp as the parent:
<parent>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
For further info refer to:
Introduction to the POM: Particularly: Inheritance and Project Aggregation
Maven by Example: Chapter 6. A Multi-module Project: For a sample project
Multi-modules projects: For the folder structure
I've been previously managing a 3-module project as 3 seperate maven projects. As this project has been moving forward, I decided I ought to take advantage of the dependency management of maven2 to streamline integration between these 3 evolving modules.
I defined a super-project that deploys as POM. Some shared dependencies are defined here, and the modules are defined in the POM in the order of dependency from the least dependent module to the most dependent module. Each module has a POM definition back to the parent, and where it applies there are dependencies from one module to the deployed artifact of another module. I'll include possibly worthwhile pom.xml lines at the end.
On to the problem, I setup this project yesterday and was able to get each module building and working on its own. I then come back today to work on one of the modules now that some fresh requirements have come in and all of sudden everything is breaking. I'm editing the projects in Eclipse, and each time I modify a file, it no longer can resolve any of the classes defined within the same project. That is to say if I have a class foo.bar.class1 and it has an object of foo.bar.class2, Eclipse (and the compiler at large) complains that it cannot resolve class foo.bar.class2... Now this is blowing my mind because this other class is in the same project and package. Similar issues are also present for classes not in the same package.
Is there something broken in my maven setup, or does anyone have any idea why these projects can't even resolve classes in the same package??
-::POMs::-
Parent -> /path/to/project/mainApp
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>mainApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Main App</name>
<modules>
<module>Broker</module>
<module>Soap</module>
<module>UI</module>
</modules>
Broker -> /path/to/project/mainApp/Broker
<parent>
<artifactId>mainApp</artifactId>
<groupId>com.moremagic</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>Broker</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
Soap -> /path/to/project/mainApp/Soap
<parent>
<artifactId>mainApp</artifactId>
<groupId>com.moremagic</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>SOAP</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
...
<dependency>
<groupId>com.moremagic</groupId>
<artifactId>Broker</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
...
UI -> /path/to/project/mainApp/UI
<parent>
<artifactId>mainApp</artifactId>
<groupId>com.moremagic</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>UI</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
...
<dependency>
<groupId>com.moremagic</groupId>
<artifactId>SOAP</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.moremagic</groupId>
<artifactId>Broker</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
...
It sounds like the problem is with your Eclipse setup and not Maven.
Does mvn compile work from the command-line within your projects? From both the parent project and each individual module (after doing mvn install for the dependencies)?
Are you using a Maven plugin for Eclipse, such as m2eclipse? Check that it is configured to load dependent projects from within Eclipse, rather than looking to the repository ("Enable Workspace Resolution"). What happens if you do Project > Clean to clean out all of the projects?