how to fix imports?

Hello,

I just migrated from netbeans to intellij recently. Trying to fix imports by using the short key of 'optimize imports'. It never worked for me. No matter I use key shortcuts, set the 'auto imports on the fly' in preference or use the menu bar. So frustrating. I have manually reimport for maven and set 'automatic import' for maven in preference. Seems no impact at all. In netbeans, I just add the dependency to my pom, then after 5 min or so, I can just use automatic imports to fix the 'cannot find symbol for ...'

Also, I'm using the dark theme, called darla or sth. Even though in the preference dialog it says the error will be red with wavy line underneath, I don't see a wavy line under any of my compilation errors. They are just red.

And what is even more pathetic is, the usage of imported class is marked red, while the import statements i manually added is all in grey, as 'unused imports'

I'm using intellij 13 on MAC. Can someone please give me some help here? thanks a trillion

gigi

13 comments

Can I have some help here? I googled around and has run out of possible options. It is
just so odd. Thanks


0

Hello.

On import problem. Am I right, that you type a class name in the editor, and the import is not generated?

Well, if you type a non-ambiguous name of JDK class, like "HashMap" or anything: does it work?

Regards,
Alexander.

0

thank you for reply. That works. But I have added the dependency to my pom.xml and
rebuild it in my MAC. I've checked that the maven repos used by my intellij is the same as my maven directory in MAC

0

Make sure the updated pom.xml (with required dependency) is imported by IDEA. (You referred to reimport actions, so I assume you have already imported pom.xml to IDEA.)

After that please check Project Structure dialog / Modules / the module with your source / Dependencies tab. Is the library defined by Maven dependency there? Then open its definition (Edit or F4 on the library entry). Is required jar(s) there? No unresolved red Classes path? (Sources and Javadoc paths do not matter now).

Regards,
Alexander.

0

Thank you for the reply. You are right. The 'dependencies' tab of my module is almost all
empty. But do I have to manually add the dependency by 'Libraries' 1 by 1? Shouldn't
it be automatically loaded by my pom.xml?

if I go to project structure ->  'Library' -> '+', it asks if 'from Maven', which I choose, then a 'Download library from Maven Repos' dialog pops out and ask me if I want to download it to a /lib dir in my git repos. I'm not sure if I want to add dirs to my git repos as it will complicate my changes. I've downloaded to a separated dir of mine before but I guess intellij is not looking there to find the dependencies?

0

Of course, this is done automatically, and the fact that it does not work to you is the problem, possible bug.

Can you show the dependency you have added to the pom.xml? Is it just in project/dependencies, or inside some profile, or some custom repository required?

Thank you,
Alexander.

0

it is
<dependency>
          <groupId>com.rabbitmq</groupId>
          <artifactId>amqp-client</artifactId>
          <version>3.2.3</version>
      </dependency>

do you think my downloading libraries to a custom dir of mine is a problem? Also, when I type in my pom.xml, before in NetBeans, it has auto-completion of artifactId, version to use, etc. Does Intellij also have that?

I have set the conf of the maven used by intellij to be the right one

0

Completion works for items downloaded into local repository. I.e. if version 3.2.3 is in ~/.m2, completion should suggest it.

"Custom dir" - do you mean your local repository is not ~/.m2? Then adjust the paths in Settings dialog / Maven.

Regards,
Alexander.

0

wouldn't it work for any artifacts in my mvn repos? Cuz usually the dependency I add to my pom are those that are not yet in my local repos, right?

0

On adding new dependency and reimport the artifact is downloaded into local repository and "indexed" by IDEA, so then it should be visible from the IDE.

For a case it's not evident: "reimport" does not mean that re-creating of IDEA project is required, it's an action in Maven tool window.

Just to check one suspicion: when you open the pom.xml in the editor, what is its tab name: "pom.xml" or "your-project-name"?

Regards,
Alexander.

0

it is my project/module name, with a little blue 'm'  before it


0

thank you. Really appreciate it

0

Please sign in to leave a comment.