java - IntelliJ can't find package imported via New Module feature, then automatically deletes import statement? -


i'm new intellij project. here intellij version info:

intellij idea 2017.2.1 build #iu-172.3544.35, built on july 31, 2017 subscription active until april 3, 2018 jre: 1.8.0_152-release-915-b6 amd64 jvm: openjdk 64-bit server vm jetbrains s.r.o linux 3.13.0-128-generic 

i running on linux ubuntu 14.04.

i had 2 separate projects. wanted import code resides in jar file first project second.

i tried using "new module -> import existing sources" option, , did add entire first project second project's source structure. still can't import classes found in jar file used first project, second project. when try, intellij gives me "cannot resolve symbol" error. more annoyingly, after length of time or when try compile project automatically deletes import statement(s). (is "auto-remove unused imports" feature biting me here?)

for example, following import statement can found in first project , considered valid intellij (no warnings or errors):

import com.github.**messenger4j**.messengerplatform; 

but when try use same import in file in second project "cannot resolve symbol" error "messenger4j , import statement gets auto-deleted @ point. note, file i'm trying use import statement in groovy source file resides in second project, in case matters.

also, if @ repo repository intellij maintains in "~/.m2" directory, see jar file. here can see can navigate ".m2" repository tree messenger4j package:

/home/user9/.m2/repository/com/github/messenger4j$ 

how can import , use github.com.messenger4j jar file in second project?

update: following appears give me access desired jar resides in "~/.m2" directory:

file ->  project structure ->  dependencies (tab) ->  "+" sign in right hand border -> library 

i see jar file in library list , adding it, no longer unresolved symbol error. is correct way use intellij/maven use external jar file?

is correct way use intellij/maven use external jar file?

no, not maven way.

if both projects use maven both have pom file defining couple of things. let's have following setup:

project a

<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>com.example</groupid>   <artifactid>projecta</artifactid>   <version>1.0-snapshot</version>  </project> 

project b

<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>com.example</groupid>   <artifactid>projectb</artifactid>   <version>1.0-snapshot</version>  </project> 

if want use classes project in project b, need add project dependency of project b. change pom file of project b to:

<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>com.example</groupid>   <artifactid>projectb</artifactid>   <version>1.0-snapshot</version>    <dependencies>     <dependency>       <groupid>com.example</groupid>       <artifactid>projecta</artifactid>       <version>1.0-snapshot</version>     </dependency>   </dependencies>  </project> 

but that's not thing. project b use project a, maven needs know can find it. solved installing project in local maven repository running mvn clean install command in root directory of project a.

after that, intellij's maven able find dependency without manually importing project a.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -