Dannyboy
Dannyboy

Reputation: 2052

How do I add maven project into intellij idea if pom.xml is not in the root level

It's been 2 days and I'm pulling my hairs out at this point.
I'm new to java development - trying to get the project imported into intellij IDEA that has following file structure:

project_dir
  data_files
     file1.json
     file2.json
     ..
  doc_files
     file1.md5
     file2.md5
  java_project
     src/*
     pom.xml
  readme.md
  .git
  .gitignore

I don't understand how to import such project into intellij so it still compiles and I can still see non java directories like data_files and doc_files.

So here's what I've tried:

a) I can go into intellij => open => select project_dir folder. Then I can see all of the files but project doesn't compile. IDE complains that dependencies are not defined. If i right click on pom.xml and select "add as a maven project" -> intellij replaces project root with java_project directory ang I cannot see data_files and doc_files anymore.

b) intellij => open => select pom.xml file. I can see source files and project compiles, but I cannot see data_files and doc_files and cannot add them.

Any help is welcome. Thanks

Upvotes: 4

Views: 5163

Answers (3)

Nikolai
Nikolai

Reputation: 61

I don't think, it's possible. What you can do though is to add a fake aggregation parent module with the following POM:

<?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>qa</groupId>
    <artifactId>fake-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>java_project</module>
    </modules>
</project>

and import it instead of importing java_project's POM. You'll have the following files structure

Alternatively you might consider moving your doc_files and data_files into the java_project folder, it looks more natural to me.

Upvotes: 1

Nathanial
Nathanial

Reputation: 2257

Did you try

File -> 
New ->
Project from Existing Sources ->
select the pom ->
set the root directory to project_dir

fyi a more typical maven layout would be

project_dir
  data_files
    file1.json
    file2.json
    ..
  doc_files
    file1.md5
    file2.md5
  src/*
  pom.xml
  readme.md
 .git
 .gitignore

Upvotes: 2

fxrbfg
fxrbfg

Reputation: 1786

Your folders with json and md5 files must be in resources folder if you want them present along with class files after compilation. maven layout

Upvotes: 0

Related Questions