Code not compiling (Eclipse Scala IDE) - scala

If I create a new Scala project in the Eclipse Scala IDE, my code compiles and runs. However, when I import an existing project, my code doesn't compile (no class files are generated) and I get a NoClassDefFoundError in the console. Any ideas what could cause this? Do I need additional software?

As mentioned in comments, this is often the symptom of missing dependencies in your imported project, either jars or other projects (which should be imported and buildable in the IDE).

Related

Issue with importing Custom Scala Jar

I have few Scala projects which uses some common functionalities.
So for better maintenance, I have create a common project P1 with all the common functionalities and created the jar.
Then I have added the jar as external dependency to my all other projects.
After importing the necessary classes from the jar, in my class, I see no error in eclipse.
But when I am trying to build the Jar for these other projects, it throws error saying : class/object that I am trying to import not found.
Surprisingly, when I am pointing the mouse to the functions that I am using from that external jar, it shows me the function signature accurately.
But somehow, the jar building is failing.
Any help?
I am using Eclipse Luna for Scala, Scala 2.11.8 in Windows 7 .

Scala-SBT - How can I remove all 'class not found' issues in imported project in IntelliJ IDEA

I am new to IntelliJ IDEA. I am importing my Scala-SBT project for the first time.
After import, it showing lot of Class Not Found problems. But in IntelliJ SBT console, clean, update, compile everything working fine. Because it is not a startup project, it is running project, lot of other people are already working.
Now, clone seperately and imported as local Scala SBT project still it not recognising my dependenty jar. Still, Class Not Found in all classes.
But I don't know, how to make automatically consider my dependencies from by build.sbt.
Also should I need to import in project settings as third party jars?
Check if there is no errors during import. If they are disable "download source" checkbox in project import settings.
You can always reimport project in IntelliJ from SBT panel
I found solution finally,
I imported as Scala SBT project and i selected build.sbt file in the root folder instead of project root folder.
Downloaded exact Scala version of my project and put in project settings.
Refresh Project - It downloaded all needed jars and took 15mins to complete.
Anyway, All class not found errors thank God.

Kotlin And Java In The Same Project Using Eclipse IDE

I posted a similar question regarding gradle but this question is without gradle or maven.
I can not get Kotlin working properly using Eclipse IDE. This works great using IntelliJ, however many developers still use Eclipse. I have installed the Kotlin Eclipse plugin and does not work. I have downloaded the Kotlin standard library and runtime library and added them into the project. Still not working. All I get in eclipse when I have Java and Kotlin is cannot be resolve to a specified type.
I'm not using maven or gradle because I couldn't get it working with those two either.
If I mix Java and Kotlin in the same source folder I get this error.
"The type error.NonExistentClass cannot be resolved. It is indirectly referenced from required .class files"
I'm using Eclipse Neon. If anyone can help me that would be awesome, I've been trying for quite some time now and not getting anywhere. :(
Add Kotlin Nature fixes the issue. Click on your project and Configure
Kotlin -> Add Kotlin nature
This partially fixes the issue, though eclipse plugin is still buggy and auto import function still doesn't work for me.
If you're having any issue, make sure you have kotlin_bin folder added in your project. Also make sure that ALL kotlin files have the correct package name sometimes when you rename packages or move files around kotlin classes may not get updated.
Got similar issue solved by adding a new Kotlin file to a Kotlin/Java mixed project. Adding the file caused Eclipse 2018-09 (4.9.0) to add kotlin-stdlib.jar and kotlin-reflect.jar to classpath and everything started working.
Add Kotlin Nature fixes the issue. Click on your project and Configure Kotlin -> Add Kotlin nature
As of the current Eclipse version (2019-09):
You can't add Kotlin to a Java project, but you can add Java to a Kotlin project.
The procedure to accomplish a mixed Kotlin/Java project was roughly:
Install Kotlin plug-in
Create empty Kotlin project
Move the Java code into the Kotlin project
Delete the original project
Fix project references
I'm working on a project with Spring Boot and Kotlin (some controllers/mappers/classes in Java and others in Kotlin) and after trying a lot of approaches, the only that worked was to use Eclipse 03-2020 and Kotlin Plugin for Eclipse V0.8.19.
https://dl.bintray.com/jetbrains/kotlin/eclipse-plugin/0.8.19/
Before everything, close your project and uninstall the previous version of Kotlin Plugin for Eclipse.
Go to Help/Install New Software.
Copy the link of Eclipse Plugin and continue with the installation (do not forget to check all the options to install).
After the installation restart the IDE and try compile again.
If your project was like mine, it has .kt files in /src/main/kotlin, some missing references in Java. I tried compiling them but nothing worked. It turns out that my project didn't have an Eclipse Source Folder associated with the kotlin code. There were the usual ones for "src/main/java", "src/main/resources" but not one for "src/main/kotlin".
So, I created a source folder for the kotlin files.
Right click the project
New "Source Folder"
Specify folder name: "/src/main/kotlin"
This doesn't create anything in the file system but just creates a logical container for Eclipse to work with the contents. In this case, Eclipse recognized the .kt files, compiled them and all the missing references issues all cleared up.

Scala in IntelliJ error

I just downloaded the plug in for Scala in IntelliJ and have created a project but now have various errors I read that the problem can be that I am missing a library. But when I try and go to project structure -> dependencies to add a library I have no clue where in the files to look for a library.
The errors are really simple but I can't seem to figure it out.
Any suggestions would be helpful :)
Here's everything you need to properly set up Scala plugin in Intellij. Furthermore your code has several errors:
Are you sure you created a Scala project (when you did File->New->Project)? This looks to me like a Java project? That class file looks to me like a Java class not a Scala class (that's why you're getting compilation errors on def but not public class).
1) value is not defined anywhere, of course it will throw a compilation error
2) classes in Scala are by default public, you do not (cannot) mark them as such
You can save yourself a lot of trouble by creating a simple SBT project that specifies all of your dependencies, etc. and then just pointing the IDE at that. Then when you change build.sbt, IntelliJ IDEA will notice that and update itself automatically. Plus, your build.sbt gets checked into your code base so that anyone you are collaborating with sees your changes to the dependencies. And the project can be built in batch mode using sbt compile and friends.
The following page talks about IntelliJ IDEA's "SBT Import" feature:
https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT
Scala source files end in .scala, not .java. Try renaming Counter.java to Counter.scala. This should improve things a lot.

Eclipse plugin to detect jars only needed for Test classes

I have 10 projects with each having 20 dependencies. Is there an Eclipse Plugin to detect jars only needed for Test classes?
This way I can exclude them from production.
I don't know such a plugin and static code analysis will only help you if you never use reflection or things like JDBC (which map Strings to Java types).
A good tool to clean the classpath is Maven. Maven (unlike Eclipse) keeps separate classpaths for the main code and unit tests. After migrating your build to Maven, simply set the scope of all dependencies to test.
Compile and the compiler will print the missing symbols. Remove the <scope> element for those and compile until Maven is happy.