Home > Back-end >  how .iml works in intellij
how .iml works in intellij

Time:02-02

I have a problem with .iml file in INTELLIJ IDEA. I'm using maven in my java project and i have dependencies by some libraries. I have two different cases:

1. First: i import my project into INTELLIJ and i use a classic .iml file that the ide creates for me, so i simply run my application. In this case i get always this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/upokecenter/cbor/CBORObject
at [email protected]/COSE.Message.DecodeFromBytes(Message.java:65)
at [email protected]/COSE.Message.DecodeFromBytes(Message.java:51)
at kapta.classes/kapta.VerifyGreenPass.verify(VerifyGreenPass.java:44)
at kapta.classes/kapta.DummyMainForVerifyGreenPass.main(DummyMainForVerifyGreenPass.java:6) 

2. Second: i paste the code of the .iml file from an application (with the same code of the not working, but its running configuration were setted properly in the .iml file) into the actual .iml file. In this case I have no runtime errors. So it seems that my run time exception is due to the format of the .iml file, but i don't understand why.

So i would like to understand how the .iml works and how i can share it with my team by using SVN, cause .iml file generally it is not included in the commits. Shortly,a version that works for me, doesn't work on my team mates' machine and the it doesn't work for me if i re-import the project. These are the dependencies in maven. enter image description here

CodePudding user response:

Your problem is not likely to be the .iml file. You should not be touching that file at all and do not need to share the .iml files. IDE will automatically generate them based on the configuration of your Maven project, e.g. dependencies, compiler settings etc in the pom.xml files.

It's far more likely that your Maven setup is wrong.

You should have a pom.xml that's validated by IntelliJ.

You should see a Maven tab on the right hand side of the IDE that shows your dependencies.

Your source and test code must follow the Maven directory structure.

I'd mark /src and /resource directories under /main and /test appropriately in IntelliJ using "Mark directory as..."

If any one of those pieces are incorrect your IntelliJ project isn't set up properly. You need not look at the .iml. The problem lies elsewhere.

Your error message is clear:

java.lang.NoClassDefFoundError: com/upokecenter/cbor/CBORObject

Is that class yours or part of a dependency you add with Maven?

You should run the Maven package lifecycle and make sure your code was compiled and added to the CLASSPATH.

Check your Maven tab to make sure the dependency with that class was added successfully.

How do you package your app? Is it an executable JAR? How do you create it? There's a Maven plug-in that will add all your dependency JARs into your executable JAR. Are you using it?

There should not be any JAR files added to your IntelliJ project. You'll find them in your local .m2 directory. It's better that way: you don't duplicate JARs in projects and they're all in a central place.

CodePudding user response:

The .iml file is just an auto-generated file that contains some configuration about projects. The file will create when you create a new project or when open a project if it doesn't exist. That's the reason that it typically ignores in git. The best trick is to remove the current file and let the IDE create a new one.

  •  Tags:  
  • Related