Why rebuild of Kotlin application removes target class files in Eclipse? - spring-boot

I'm trying to setup an app written in Kotlin, built on Maven and using Spring Boot in Eclipse.
I manage to run the application only if I do Maven build of the project which generates class files in target/classes dir. If I do clean the project then Eclipse rebuilds it automatically and removes all class files from target/classes dir.
I think that re-build of the project should re-compile class files in target/classes directory, not just to remove them. Otherwise it means that I need to re-build project as Maven on each code change which I seems to be a wrong way to go.
Please point me the correct way to setup a Kotlin - Maven - Spring Boot project in Eclipse.
My setup is:
Eclipse is 4.26.0.
Maven EMBEDDED 3.8.6.
Kotlin Plugin for Eclipse 0.8.24 (it causes intallation of Enhanced Kotlin for Eclipse plugin).
Spring Tools 4 - 4.17.2.RELEASE.
OpenJDK 11.0.2.
What I did:
Installed all the above (Eclipse, plugins, JDK and etc).
Imported the project as a Maven project in Eclipse: github link.
Import dialog
Right click on DemoApplication.kt -> Run As -> 1 Kotlin Application. I got an error:
Error: Could not find or load main class com.example.demo.DemoApplicationKt
Caused by: java.lang.ClassNotFoundException: com.example.demo.DemoApplicationKt
Right click on pom.xml -> Run As -> 2 Maven build...
Goals: clean install -> Run.
After that I see in {project dir}\target\classes\com\example\demo class files were generated.
If then I do right click on DemoApplication.kt -> Run As -> 1 Kotlin Application it runs OK.
If I click on Project -> Clean... (with Build Automatically ON) - all files from {project dir}\target\classes\com\example\demo got removed and I again start at point 3.
I tried couple configuration options, but they didn't help:
Making Window -> Preferences -> Java -> Compiler -> Building -> Output folder -> Scrub output folders when cleaning projects OFF doesn't help - class files still got removed.
In Package Explorer -> Kotlin Runtime Library there is a virtual directory kotlin_bin which has all class files. I tried to setup it as Dependencies:
Run Configuration dependencies setup
But it fails to run then with the below error:
Error when run it

Related

Maven doesn't recognize dependencies added in IntelliJ project structure

I need to use external dependencies for tomcat. I add them to project structures and project build fine. Compiler doesn't show any errors
project structure
The project works fine when i run it on IDE.
The problem starts when I try to build WAR file using Maven package :
package org.apache.catalina does not exist
package org.apache.catalina.connector does not exist
package org.apache.coyote does not exist
I've try with all different scope settings but jars aren't found

Intellij MavenWrapperDownloader.java: Can not resolve symbol error

Setup:
Intellij IDEA community edition 2020.2
Spring Bott starter parent: 2.3.5
Java 11
WRAPPER_VERSION: 0.5.6
mvn 2
Hi,
I googled a lot e.g. here but I just can't fix it.
I created a new mvn spring project with Intellij. When I commit the project I get errors detected by code analyses in class: MavenWrapperDownloader.java.
e.g. It reports:
Cannot resolve symbol String
I tried:
invalidate caches and restart
delete .idea folder and reimport
checked sdk setup
mvn reimport
mvn clean and then rebuild (while the build is always successful)
I'm pretty new to maven. I guess the scope of the mvn package might be wrong because the build process works as expected.
UPDATE:
I reinstallt my openjdk11. No success. Then I found out that my .mvn/wrapper dir is not set as source root. I know that was never the case in my other projects. As a trial I've set my .mvn folder as source root and now the MavenWrapperDownloader.java file is recognized as a java class and the compiler interprets the symbols. But now there is another error. It says I have to define a package name for that class because the class does not have one per default. It is pretty strange to me. I also tried to use another spring boot starter version but nothing changed
When I execute Analyze->inspect code I get the following:
I had the same problem and File -> Invalidate Caches/Restart fixed it - at least for now.
IntelliJ Ultimate 2020.3
Spring Boot Starter Parent 2.4.2
Java 15
Maven 4.0.0
Maven Wrapper 0.5.6
The easiest solution is to generate your project again with Spring Starter.
After you set up everything you need at pom file -> Generate -> Download it.
Open with your IDE and copy-paste all code sources which you have already written.

Intellij IDE not downloading dependencies after pom update

I'm using Intellij IDE for Spring projects. Whenever I add a dependency in pom file, it's not downloading it. In the case of Eclipse IDE, it automatically downloads the dependency whenever a dependency is added in pom.xml file.
I added the highlighted dependencies in the pom.file but it's not downloading. How to configure the IDE for auto-download dependencies whenever the pom.xml is updated?
You can tick the checkbox "Import Maven Projects automatically"
under "settings" -> "Build, Execution, Deployment "
-> "Build Tools" -> "Maven" -> "Import Maven projects automatically"
Usually, if do some modification in pom.xml, the Intellij will give always suggest you to enable Auto Import in a small pop-up(). I think it might have suggested you already. Anyways, you can do the above.
In Eclipse project build automatically it that option is enabled as build automatically
but idea we can not load maven dependency just by adding it in pom.xml but we can build the project by
IntelliJ Idea - Preferences
Select “Build, Execution, Deployment -> Compiler” -- build Project automatically
Above will build the project but it will not download the dependency
We have to click reload all maven project icon under maven tool window which can be activated by view - Tools Windows - maven

How do I run the Spring RESTful Web Service

I've installed the spring example RESTful Web Service. And I have it building fine in IntelliJ. But how do I get IntelliJ to create gs-rest-service-0.1.0.jar? There are menu commands to synchronize gradle & maven, but nothing to use them to build the jar.
A standard POM/Maven-based project can be built via the console by typing:
mvn package
the maven lifecycle, by default, will place the output artifact (i.e. JAR / WAR file) under the target folder.
Alternatively, since you are using IntelliJ, you can also use the IDE to run the build for you. The simplest way is to navigate on the right side tab
mvn > your_project > lifecycles > package
the output will continue to be placed in the same target folder.
Assuming the project has a pom file. And it was mentioned building fine in the post. Assumption: STS/Eclipse users
Right click on pom file -> run as maven build. In the console it displays where the jar file is created.
Go to: project folder -> target folder -> gs-rest-service-0.1.0.jar
file

Spring Boot Maven project giving error after importing on STS-4

I have the IDE Spring Tool Suite 4 and I imported the Spring Boot project generated by JHipster using the option "Import > Existing Maven project", however, the project show error in the first line which is just a comment in package-info.java and because of that the project not run when I try initialize by Boot Dashboard in IDE.
The IDE show this erros:
The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.ServletException. Fix the build path then try building this project;
The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files
I tried:
project > clean;
right click in project > Run > Maven clean;
right click in project > Maven > Update project;
Usually this steps work, but not in this project.
When i open the terminal and write mvn clean package and run the .war or execute ./mvnw the API works.
Why does this error occur in STS 4 if the terminal compiles without problems?

Resources