How to import classes from another module in Intellij

ncbvs :

I am trying to write an import statement to access a scala class in another module in a java project in intellij.

I found this question which appears to be related:

Kotlin: How to import a class from another IntelliJ module?

I've followed the steps for grouping and flattening the modules; however, I cannot find an import statement that works. I am not using a Kotlin project, so perhaps that's the difference.

I was able to get an import statement to work when I included the scala project as a jar dependency(instead of as a separate module); however, doing it that way created problems with intellij not recognizing scala-specific portions of the code. I don't know much about building Jars in intellij, so it's possible I'm not building it properly - I am used to Eclipse where a jar is just a jar and you're done.

Here is the line I am attempting to use the import statement for:

public class Display {
    public static Screen screen = new Screen(Resolution.FULL_SCREEN(), Screen.DEFAULT_SCALE());
}

Path to dependency:

storm.screen/src/main/scala/Screen.scala

Path to working class:

storm.core/src/output/Display.java

Currently every import path I've tried gives an error message of 'cannot resolve symbol'.

Edit: I've now successfully added a module dependency from a different module which is a Java project - the issue here seems to be isolated to the Scala project module.

ncbvs :

I was able to resolve this issue by creating an entirely new maven project, manually copying the source files from the existing modules, and following the procedures in this post.

Oddly, as long as the scala classes are inside of a directory called 'java', they work just fine - but if the directory is renamed 'scala', the imports break.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=104958&siteId=1