Cannot build/run Scala project in IntelliJ after packaging with Maven - scala

So my Scala project was working perfectly fine in IntelliJ, then I tried to run package in Maven to obtain a .jar file, which was not working because I was missing a dependency. So I tried to edit pom.xml however reverted it back shortly.
Anyhow, thereafter, without any changes I tried to run my Scala project normally locally and it doesn't work anymore. I get the error:
Error: Can not find or load main class Name.Name
I double checked Edit Configurations in IntelliJ and the main class is specified.
What went wrong? There has been no changes at all except that I tried to package my project using Maven, and then my normal program stopped working.

Solved it by recreating the project from scratch, however I'm still unsure what the cause was.

Related

Weird Build issue with Intellij, Maven, Scala pulgins

I am facing really weird build issue with Intellij, Maven and Scala.
We have scala project, when I package it into jar by running mvn clean, mvn scala:compile and mvn install or package, it generates jar file perfectly but when I deploy this jar to our AWS EMR ec2 instance and when I run that jar with spark-submit command sometimes it complains about
"Error: Failed to load class com.OUR_PACKAGE_NAME.ScalaMainClass"
So I tried to check my code which looks perfectly fine, it complies fine, also it runs fine in my local machine. But sometimes that same generated jar works fine and sometime it does not in AWS EMR ec2 instance. It is not consistent.
So I reverted back my code to previous working stage and started adding my code one by one untill I get this "Failed to load class" problem. Then I encounter that one of the scala class having some issue. Visually code looks fine also it compiles great, but somehow that scala class creates problem when mvn creates jar file and when we run it to EC2.
The weird part is that, when I hit enter and add new blank line before or after problematic line of code, maven generated jar works fine. So I believe there is some hidden character which maven does not like or intellij is not able to uncode properly. And when I takeout that blank line that error appears again.
Could you help me on that?

Invalid error messages in Spring Tool Suite

I am running into a problem when trying to duplicate a project in STS.
I am getting lots of error-messages of type
"Import XY cannot be resolved..."
in my code which runs and builds completely fine with maven and which is a more or less exact copy of the original project (with different artifact ID a.s.o. in the corresponding pom) which is shown as error-free.
What I did until now:
I wasn't sure how STS-duplicate works and thought that some configuration may have been duplicated but would have needed some changes, so I created a new project and inserted the code manually in manually new created classes and added the needed dependencies to the pom.
Again this compiles and runs perfectly while still showing the import errors.
Did anyone run into similar problems and has a solution to this?
(I had something similarly strange in the past where STS showed an error on project-level but no file in the project would have an error-indicator.)
Run a Maven -> Update Project..., that should help... :-)

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.

Intellij Idea is loading *.class file instead of *.scala from library source

My problem is best described with a screenshot:
As you can see, there is a org.virtuslab:unicorn-core_2.11 dependency loaded in my SBT/Scala project. The jar file with corresponding sources is available as well. For some reason, Intellij Idea decided to ignore the available source file Table.scala and uses the .class file instead. Clearly, all other files are okay.
Obviously, without the information contained in the .scala file, Intellij is not able to properly analyze my code and I'm getting Cannot resolve symbol BaseIdRepository errors (and similar) all over my project.
I manually checked the source package and the Table.scala file is there and seems alright. Plus this worked flawlessly until two days ago. I don't know why it broke down. I tried to revert my project using git to an earlier version when this was still working, but no luck.
I tried to both downgrade and upgrade the library, I tried to remove it and add it again, I tried create a completely new project based on existing sources, but once again, no luck.
Just for the record, I'm able to compile and run my project. The only thing that might be related is this warning that I get when compiling the project:
[warn] /home/tobik/scala/payola-viz/src/app/model/appgen/repository/UsersRepository.scala:7: Could not find any member to link for "BaseIdRepository".
I got an update for the Scala plugin which seems to fix this issue.
In case you experience similar problems, this temporary solution worked for me: I added the unicorn sources directly to my code base and manually removed it from the project libraries. I got rid of the errors and it still compiles as the library remains as a dependency inside built.sbt. To avoid polluting my project, I added the included sources to .gitignore. The workaround broke after a while but all I had to do was repeat the procedure again.

Stop exiting Eclipse with Play 2.3.X

If I run my application (Play 2.3.2) while Eclipse is running I always have strange compilation errors, no class def found errors, class not found errors, etc...
If I exit Eclipse and run my application, everything is working fine. But sometimes it's also working fine while Eclipse is running.
Am I the only one to experience that ? What is the cause ?
I suspect something in Eclipse changes my source files but I can't find what.
Maybe Lombok ?
Thanks.
I have similar problems. Typesafe responded with a solution which I am currently trying out.
https://groups.google.com/forum/#!topic/play-framework/4RnbqEk-muM
Brief summary of the answer by #jroper :
Eclipse doesn't know
how to keep its dirty hands off the same build directory that Play is
using to compile your app - if you have both Play, and the IDE, trying
to compile the same code at the same time, what do you think will
happen? You will see random errors. You should configure Eclipse not
to automatically build your app, or configure it to have different
output directories.
The Play Framework compiles everything to the directory target/scala-2.11/classes. When changing some of these classes, especially any views, causes Activator to auto compile the classes creating new class files. Hitting refresh on the project in Eclipse will update the project and class files in the classes directory causing a rebuild. This should make your compilation errors go away. If you still have issues, take a look at your .classpath file and the Eclipse build path settings.