I have a project in Intellij 13 organized with the following structure:
main project
- pom.xml
module 1
- pom.xml
module 2
- pom.xml
I added "module 1" and "module 2" to the "main project" by using "Add maven projects"
In the "main project" pom.xml I added the dependencies to the module 1 and module 2 like:
<dependency>
<groupId>module1</groupId>
<artifactId>module1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>module2</groupId>
<artifactId>module2</artifactId>
<version>1.0</version>
</dependency>
However, "main project" cannot see the beans of module1 and module2. Any idea what could be missing ?
main project must be packaging pom and have modules element with the others.
Or add a main pom
sample here http://svn.apache.org/repos/asf/maven/indexer/trunk/
In your parent project POM...
<modules>
<module>child1</module>
<module>child2</module>
</modules>
And your folder structure should look something like this...
parent/proj/folder
- pom.xml
parent/proj/folder/child1
- pom.xml
parent/proj/folder/child2
- pom.xml
EDIT:
Also, in case you didn't know, in your parent pom you declare all the versions of your dependencies, but when you include them in you child poms you shouldn't include the versions
Related
I'm new to using IntelliJ. I have a project named X which has 5 dependencies a, b, c, d, e. These dependencies are linked as follows:
a->b->c
while c, d and e are independent.
Currently, when I'm seeing the project structure under
File->Project Structure->Project Settings->Modules, these dependencies source are pointed to .m2 directory. Since they are just imported and not built yet, so their output is not available in .m2 directory, hence not available for main project.
I want to know, in IntelliJ, how to import all dependencies with main project and build the main project, so that it also builds the dependencies first? Any guide or article which I can refer?
Can you show your pom.xml?
It sounds like your dependencies are sub module of your project.
You can add dependency from your modules like you add all the other dependencies, so you should add something like that in your pom.xml:
<dependency>
<groupId>com.example</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>d</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>e</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
I have created a maven archetype from a project, in this project's pom file, there's an dependency demo-admin
<dependency>
<groupId>com.demo</groupId>
<artifactId>demo-admin</artifactId>
<version>${demo-admin.version}</version>
</dependency>
this dependency is installed in my local repository.
But when I checked the generated archetype files, the pom.xml file in the archetype-resources folder, the dependency looks as below
<dependency>
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}-admin</artifactId>
<version>${version}</version>
</dependency>
so every times I create a new project from the archetype, the maven coordinates of this denpendency will change.
Anybody has the same issue?
EDIT:
This issue could be reproduced as below steps:
create a project which GAV as below
<groupId>com.demo</groupId>
<artifactId>abc-admin</artifactId>
<version>1.0.0</version>
create a project which GAV as below
<groupId>com.demo</groupId>
<artifactId>abc</artifactId>
<version>1.0.0</version>
the second project contains a dependency
<dependency>
<groupId>com.demo</groupId>
<artifactId>demo-admin</artifactId>
<version>1.0.0</version>
</dependency>
create an archetype from the second project using the command below
a. cd abc
b. mvn clean
c. mvn archetype:create-from-project
go the "abc/target/generated-sources/archetype/src/main/resources/archetype-resources" folder, you can see a pom file, in the pom file, the dependency looks as below
<dependency>
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}-admin</artifactId>
<version>${version}</version>
</dependency>
so, if I create a new project based on the abc archetype, when I input different GAV, the dependency will also changed based on the input values
I guess this is the automatic replacement of your of the groupId and artifactId of your demo project by placeholders.
Either give you demo project some name that never appears anywhere else or edit the resulting archetype by replacing the placeholders with the correct values.
I have two projects. Project B is maven dependency in project A.I have to use a pojo class of project B in project A
Note:- I don't want to add the jar in build properties because in production it will be a issue
Its simple, you can packaging the project A as a jar and add this dependency as a provided scope in project B.
For example:
pom.xml (Project A):
<project>
...
<groupId>com.myproject.easy</groupId>
<artifactId>commom-lib</artifactId>
<version>0.1</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
</project>
pom.xml (Project B - Needs to use some Pojo Class from Project A):
<project>
...
<dependencies>
<dependency>
<groupId>com.myproject.easy</groupId>
<artifactId>commom-lib</artifactId>
<version>0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
It won't throw exception on your application server, cause provided scope means the jar used as a dependency in project B going to be on classpath during runtime.
I have created 5 or 6 Java projects in Eclipse by now and will be creating some 20 more projects. I have to add the TestNG library and another library (including some specific jar files) in the project.
Is there any way such that the Eclipse will automatically include both of these libraries at the time of creating every new project?
I don't want to add these libraries on my own by navigating to ADD BUILD PATH -> ADD LIBRARIES.
First, you shouldn't use Eclipse dependency management (add libraries manually to build path using Eclipse) if you're already using Maven.
IMO, you should only rely on Maven dependency mangement.
I suggest you to create a Maven parent project that will handle your dependecies used across multiple projects as follow.
Project structure
- maven-parent-project
|-- project-a
|-- project-b
|-- ...
Define Maven parent project
I suggest you used <dependencyManagement> (documentation) to manage the versions of your dependencies.
pom.xml
<project>
<artifactId>maven-parent-project</artifactId>
<modules>
<module>project-a</module>
<module>project-b</module>
</modules>
<dependencyManagement>
<dependencies>
<!-- Here you can define the versions of your dependencies used accross multiple project -->
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Here you can define the dependencies used accross multiple project -->
</dependencies>
</project>
Define Maven sub projects
Then, you can define in all your project the maven-parent-project
pom.xml
<project>
<parent>
<artifactId>maven-parent-project</artifactId>
<version>0-SNAPSHOT</version>
<groupId>group</groupId>
</parent>
<artifactId>project-a</artifactId>
<dependencies>
<!-- Here you can define the dependencies specific to the project a -->
</dependencies>
</project>
I hope this will help you.
Study about dependency management in Maven. That will solve your requirements. Read this thread to get the jist.
I ve got my maven web project and i want to add my ejb project (the same worksapce) as a liblary. How to make it in the pom.xml?
Do I think in a right way?
Assuming the MyEjbProject is not another Maven Project you own or want to build with maven, you could use system dependencies to link to the existing jar file of the project like so
<project>
...
<dependencies>
<dependency>
<groupId>yourgroup</groupId>
<artifactId>myejbproject</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>path/to/myejbproject.jar</systemPath>
</dependency>
</dependencies>
...
</project>
That said it is usually the better (and preferred way) to install the package to the repository either by making it a maven project and building it or installing it the way you already seem to do.
EDIT: If they are, however, dependent on each other, you can always create a separate parent project (has to be a "pom" project) declaring the two other projects as its "modules". (The child projects would not have to declare the third project as their parent). As a consequence you'd get a new directory for the new parent project, where you'd also quite probably put the two independent projects like this:
parent
|- pom.xml
|- MyEJBProject
| `- pom.xml
`- MyWarProject
`- pom.xml
The parent project would get a "modules" section to name all the child modules. The aggregator would then use the dependencies in the child modules to actually find out the order in which the projects are to be built)
<project>
...
<artifactId>myparentproject</artifactId>
<groupId>...</groupId>
<version>...</version>
<packaging>pom</packaging>
...
<modules>
<module>MyEJBModule</module>
<module>MyWarModule</module>
</modules>
...
</project>
That way the projects can relate to each other but (once they are installed in the local repository) still be used independently as artifacts in other projects
Finally, if your projects are not in related directories, you might try to give them as relative modules:
filesystem
|- mywarproject
| `pom.xml
|- myejbproject
| `pom.xml
`- parent
`pom.xml
now you could just do this (worked in maven 2, just tried it):
<!--parent-->
<project>
<modules>
<module>../mywarproject</module>
<module>../myejbproject</module>
</modules>
</project>