Same jar (name + version) but different code by maven - spring-boot

I have run into a really frustrating bug.
I have a dependency in my pom.xml file -> cd.connect.openapi.gensupport:openapi-generator-support:1.4
I have two completely different project.
Each having its own pom.xml and both require this dependency.
Now one project works fine.
But in another project, while debugging, I found that this exact same dependency has buggy code in this project but not in another.
In this project, this jar has a class called ApiClient.java, which uses a static initialiser block to populate a Map for exception handling. This block uses some constants define in Response.java. But there are to constants which it uses in ApiClient.java and these 2 dont exist in Response.java. Hence when I run the code, I get error NoSuchFieldError and sometimes I get NoClassDefFound.
I tried reloading maven project, deleting .m2 folder so that the dependency gets downloaded again, but no luck.
Any suggestions are welcome.
UPDATE
In Project that is not working
ApiClient.java -> cd.connect.openapi.gensupport:openapi-generator-support:1.4
Response.java -> javax.ws.rs.jsr-311 api
In Project that is working
ApiClient.java -> cd.connect.openapi.gensupport:openapi-generator-support:1.4
Response.java -> jakarta.ws.rs:jakarta.ws.rs-api:2.1.6
UPDATE-2
In project that is working, jakarta jar is present and javax is not. So ApiClient is using jakarta.
But in project that is not working, both jakarta and javax are present and it is using javax, hence the problem.
So question boils down to how can I make it to use jakarta one.
Will try deleting javax one, hopefully it wont break anythin else.

Related

Really removing a package from a Spring Boot / Maven / IntelliJ project

I'm building a web server using Spring Boot, Kotlin and IntelliJ and am learning a lot. I added Thymeleaf but decided later than it didn't meet my needs, removed it from the POM and rebuilt the project.
On startup, Thymeleaf was still looking for the /templates/ folder (which I'd also removed), even though Thymeleaf was no longer a part of the project, supposedly. A project-wide search (shift-ctrl-F) for thyme, case-folding, found nothing, so I closed the project and used the GNU find command-line utility to search for thyme in the project hierarchy. That found references in project.iml and some .xml files under .idea/libraries. I removed those, re-opened and rebuilt the project, and it no longer mentioned /templates/ or Thymeleaf on startup.
So my question is: what would have been the 'official' non-hacky way of removing the Thymeleaf package from my project? I am now wondering what other unwanted libraries are in the project, and how I should remove them.

Import jar file to kotlin + spring boot + gradle

please help, I have two spring boot projects with Kotlin + DSL + Gradle, but, I need to import one of them into the other, but, it doesn't work. This is what I have tried:
Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
How do you add local .jar file dependency to build.gradle.kt file?
and googling there are many variations of the previous two posts that I have also tried and it just doesn't work. Also, I tried importing the generated ".jar" files, but, in a non-spring boot project (simple console app) and there it works, i can see the classes from this external projects.
Thanks in advance!
Additional data:
Kotlin: v. 1.5.30
IntelliJ IDEA: v. 2021.2.1 (Community Edition)
Gradle: 7.1.1
After 2 days wasted in this, I managed to fix the problem, I leave my solution hoping that it will help someone else:
Generate the projects from scratch with Spring Initializer (https://start.spring.io/) with the following characteristics:
1.1. Project: Gradle Project
1.2. Language: Kotlin
1.3. Spring Boot: select the version that suits you best
1.4. Project metadata - It is very important that you do the following:
Group: this must be the same in both the parent project and the child projects. Example: com.company
Artifact: this should be the name that will differentiate each project (you can put any one as long as it is not assigned to an existing project). Example:
api (parent)
-> auth (child)
-> security (child)
Package name: after filling in the above data, your "package name" for each project should look like this:
com.company.api (parent)
com.company.auth (child)
com.company.security (child)
Import the projects normally into IntelliJ IDEA and wait for Gradle to builds the projects.
Very important !!! do not change the names of the classes that Spring Initializer generates, this was one of my biggest problems.
In child projects, always builds the jar with the following command:
gradle clean build
Note: the .jar file is generated in / build / libs / and you will find two files, for example for project "auth":
auth-1.0.0.jar (large size)
auth-1.0.0-plain.jar (small size)
The first contains all the dependencies so it is larger, the second only contains the classes written by the programmer.
At the root of the parent project ("api"), create the folder "libs" or whatever you want to call it and put all the .jar files that you have previously generated here of child projects.
Import the previous files (contained in the "libs" folder) into the parent project as follows and in the build.gradle.kts file (dependencies section):
dependencies {
implementation (fileTree (mapOf ("dir" to "libs", "include" to listOf ("*. jar"))))
}
That is all. Incredible that such a simple process causes such a headache.

Maven JavaFX Cannot find Main Class

I have some problems running my JavaFX8 Project with Maven. Here is the situation:
I create a Maven Java FX application within Netbeans (File --> New Project --> Maven JavaFX Application). Netbeans creates the packages and also creates a MainApp.java file.
Even if I don´t edit anything in this project, I get an error/warning within the properties.
Location: Right-Click Project --> Properties --> Run
Message: One of Run/Debug/Profile Project actions has been modified and the Run panel cannot be safely edited
The project can be built and run for some time, but after I create more packages, classes and stuff like that, I can´t run the application anymore.
It tells me, that it can´t find the Main class.
Message: Error: Could not find or load main class
I found some entries at stackoverflow and google, but none of the solutions seem to work for me.
I read this Topic for example.
One of the solutions is, to set the main class at the properties (Run), but all the fields are disabled. I also deleted the Cache, which didn´t solve the problem. I also checked the typing.
Some other sites stated, that it seems to be a bug, but they had older Netbean Versions. I updated my Netbeans version to 8.2 today.
The only solution at the moment is to create a new Maven JavaFX project and refactor the files to the new project. This works for a couple of hours but in the end the error occurs again.
Does anybody know a solution?
Use Run from the Project, not Run File from the main file. The latter can work on other setups, but not straight out of Maven.

Update dependencies while in hosted mode in GWT

I have a GWT webapp split into two Maven projects where one is a dependency to the other. Each time I change something in the dependency and I'm running webapp in hosted mode I have to rebuild the subproject and restart hosted mode for changes to apply. It takes a lot of time so I'd like to ask you if there is any way to make GWT using "live" version of the dependency?
There are 2 cases:
for server-side code, assuming you use the DevMode's embedded server, rebuilding the app and then refreshing the server should be enough
for client-side code, AFAICT, you have to use the source and output directories of the dependency module rather than the JAR containing them (GWT will load the source from the classpath, but apparently it'll only see the modified sources if it comes from a folder rather than a JAR; at least that's what I found in my tests). This goes against The Maven Way™ but the only solution so far is to use a special profile that will import the sources of the dependency project as sources of the project you're running. You can see examples of that in my archetypes.
There's actually a bug opened for the gwt-maven-plugin, MGWT-332, to do that automatically when running a reactor build. I also mused about what's really needed, for the forthcoming official gwt-maven-plugin (rewritten from scratch, independent from the CodeHaus Mojo plugin).
If your dependency does not come from a reactor build, then you're out on your own: you chose to make it totally distinct, so that's how it'll behave: you'll have to release it (even a snapshot) each time you make a change to it, and use the new version in your app (which means re-launching the DevMode).
This can be circumvented by running DevMode on your own, without the help of the gwt-maven-plugin. You're left on your own managing the classpath though (using the Google Plugin for Eclipse, I suppose you could simply edit the launch configuration to add the source folders of your dependency project to the classpath, before the classpath provided by Maven, that would reference the JAR).
Remove the dependent other application jar file from the primary application lib folder under webapp.
Eclipse should then resolve the dependency using the other project in the workspace if you have added it to your primary application classpath.
As GWT build takes ages, we invested some money in a JRebel license. We have two separate Eclipse projects for our back-end and our GWT front-end. JRebel reloads the classes automatically and I never need to restart my local server while writing code. It proved to be a wonderful time saver. Definitely worth the investment.

Spring Core Course solution exercises not working anymore

Last year i did the core course from Spring. At that course i received a very good book named "Core Spring Student lecture manual" + exercises book. The problem is that after houres of suffering i still not managed to get the examples(solutions) runnable.
I have two options:
-First i tryed to import all the projects into STS and intellij and i try to build them with Maven.
I also added all the dependency's manualy to my local repostirory but i get two errors
This repository does not exist anymore:
Code:
<url>https://tbits.springsource.com/repository/snapshot</url>
and when i remove that repository in the pom.xml maven it complained that he can't find the parent project.
<parent>
<groupId>com.springsource.training.common</groupId>
<artifactId>abstractContainerProject</artifactId>
<version>1.1.7.RELEASE</version>
</parent>
-As second i tryed to remove all the maven part and i just added the library's one by one manually to the projects the code compiles fine than but the problem is that the unit tests are nut running i get a stack trace "java.lang.exception" no runnable methods found.
For me i doesn't mather if it works with maven or manually as long as i can run the tests / compile its ok.
Is there anyone who also had problem with this?
Thanks anyway!
As far as I know, you're not supposed to import them to any local IDE, you're supposed to use the STS provided in the material. Same goes to the repository - repository is provided in the training material. That's the same thing they've adviced in the spring forums as well.
Once you have installed course from Spring, go to the directory where it is installed. There is a folder called repository. For e.g on mac /Applications/core-spring-3.2.1.RELEASE/repository.
Here you will find all dependencies which you can then add to the classpath manually (add external jar).
Or in case of maven: just copy the whole folder ...repository/com/springsource into .m2 folder.

Resources