2

I'm using IntelliJ IDEA13 for a MVC project using hibernate, struts, etc, but my Intellij doesn't detect any errors when i'm writing code for example when I make and object that requires a certain import, even if I do stupid things with the code it doesn't show at red any errors. I'm compiling the files with ant and not with IntelliJ, but an IDE it's very usefull specially to imports and autocomplete and I don't know why this is happening. Any ideas?

EDIT: This only happens in this MVC project (> 2.000 files), in a normal Java project everything is fine.

I have 1 folder with the name "project1", inside that folder i have other 2 folders: common has all the jars that i need and impl has all the files of the project.

enter image description here

So the way i did to put all of this in IntelliJ was to create a new project with the name "project1" so that IntelliJ got all the folders and files.

Maybe it's because of that and something is wrong in the configuration.

Just a quick example, if i call Query q = createQuery("select * c.name from c in class " + Category.class.getName() + " order by c.name desc"); I don't have the import for the class Query so IntelliJ should tell me to import that class and make Query red, but it doesn't and even when i click alt+enter in Query it doesn't show me the option to import that class, my IntelliJ doesn't know that are errors in the code.

EDIT2: I made a new module and everything seems to be working now. I had the wrong source folder in the module.

10
  • You need to be more specific. Why don't you attach a screenshot of a file where you're experiencing the problem? InteliJ will compile the files you give it on its own and show problems. I'm guessing it's a configuration problem. Commented May 13, 2014 at 20:03
  • That is weird. Can you give us a hello world example that fails for you? Also, try rebuilding the index. Commented May 13, 2014 at 20:03
  • I need to have 10 reputation to post images. I'll edit and be more specific. Commented May 13, 2014 at 20:06
  • There, you have 11 now! Commented May 13, 2014 at 20:08
  • 1
    You can't set your source folder as the project root -- it'll just confuse intellij even worse and lead to bad things. Your java files, and the packages (directories) they are in should be under a separate folder, and that should be marked as the source -- it is usually under the project root too. The compiled version of your files usually goes in a directory called target, but the name isn't so important, that too should be under your project root and IntelliJ should be told to build to there. Commented May 13, 2014 at 21:13

3 Answers 3

5

When you open a source file, does the icon for it have something like a blue circle with "C", green circle with "I", etc...? That indicates that the file is recognized as a source code file. Javascript files should show an icon that says "JS".

You can go to File > Project Structure > Modules. There, make sure that you have a Java module containing the folders with your source code.

You'll probably want to do File > New Module and create it for your project1 folder.

EDIT

If you like, you could use Maven; once you've created the pom.xml file, you can delete IntelliJ's project files, and do File > Import Project. Then just chose the pom.xml file. IntelliJ will set up the project and modules based on that. Also Maven's convention-over-configuration approach is nice (everything goes into standardized locations).

Sign up to request clarification or add additional context in comments.

2 Comments

When it doesn't detect errors the icon in java files are white with a red J. When it detects errors the java files are blue with a blue circle. Alse, it doesn't let me to add Java Classes, i have to make add-> file -> and manually put it as .java. i'll try that.
I cannot move any folders that already exists, only create new folders and files. Just like i told above, i founded a "solution", not a classy one but at least i can work with this now.
2

In my case, I've made a mistake by turn off the error highlight in IntelliJ.

In the top of the right bar of code editor, OFF => Highlight: All Problems

enter image description here

Comments

-4

These problems are all solved if you use maven rather than ant. This is one of the main reasons 99% of professional projects use maven. You must tell intellij where your source folders are: in the project settings select the folder where your source is, and mark it as source, then do the same for your tests. You must also assign a jdk.

11 Comments

Just curious... 99%? What is your source for that number?
@ElliottFrisch 99% of people will believe anything
@jgitter At least 60% of the time.
I already tried to mark src as root source but it merges a lot of folders (freaky!) and that ruins a lot of packages imports in files that i'm not supposed to put my hands on because of job is only to add some requirements to the system. Now i tried again and i noticed that even though the project became freaky by merging folders, now it can detect errors in java, so my solution will be, put src folder as source root when i'm writing code and unmark it when i want to compile lol. not classy but at least i can work.
@ElliottFrisch I love that site
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.