4

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

Sylhare
  • 5,907
  • 8
  • 64
  • 80
Dannyboy
  • 1,963
  • 3
  • 20
  • 37
  • The first way you have done is correct. I think you have to build the project then it'll removes the missing dependence issue. If it continues i think you can try forcing to build the project by mvn. Let us know the results. – chathura rupasinghe Jun 14 '17 at 20:49
  • @chathura rupasinghe right - but when I click n build - it does'n build anything . IDEA seemingly simply doesnt understnad that source files are under project_dir/java_project. – Dannyboy Jun 14 '17 at 21:05
  • [have you tried it like this](https://stackoverflow.com/a/29765077/4192663) – chathura rupasinghe Jun 14 '17 at 21:10

3 Answers3

2

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
Nathanial
  • 2,177
  • 1
  • 15
  • 34
  • yeah - the moment I change root directory to project_dir iIDEA doesnt show e any pom.xml files to select anymore – Dannyboy Jun 14 '17 at 20:56
  • Did you try checking search for projects recursively? Your pom should show up. – Nathanial Jun 14 '17 at 21:00
  • Nathaniel - yes. Gues what happens than - java_project automatically becomes a root directory of the project an I cannot see my other directories. – Dannyboy Jun 14 '17 at 21:02
  • Yea, that makes sense. I would suggest changing the structure so that the pom is in the root like above, there's no reason not to have the pom in the same dir as data files. If you want your project to access them you'd need that anyway. Otherwise, there's no real need to be able to see them in intellij, and you could edit them with some other tool. It's also indicative that maybe your data files should be in a separate git project. – Nathanial Jun 14 '17 at 21:10
  • Nathanial ahh. I just had a brainfart. Yes - yes and yes. Ive just restructured my project the way you've advised adn everything is working and showing up as expected now. Thank you! – Dannyboy Jun 14 '17 at 21:11
1

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.

Nikolai
  • 61
  • 3
  • 1
    "moving your doc_files and data_files into the java_project folder" => omg. I don't know why I didnt think of that before. Done done and done. problem solved. – Dannyboy Jun 14 '17 at 21:10
0

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

fxrbfg
  • 1,756
  • 1
  • 11
  • 17