Open michaelkrog opened 6 years ago
package dk.codezoo.meerkat.model does not exist
Can you check this? Is it only happening with those JDKs?
That package does exist. I have tried to unpack the jar just to check it, and it is there. The two classes are both in the package. One works the other does not.
I just tried to force our build process to update the docker image it uses(openjdk:8-jdk), and that changed the JDK to this:
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-1~deb9u1-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
But to no avail. It fails with the same exception.
But I am only seeing it when I run it on OpenJDK.
Okay. I just extracted the Jar built for production and ran that locally... And it fails...
So its not only OpenJDK.
Weird. If I built it with maven locally on 1.8.0_121(mac) and run it locally, there is not issue. If built it with 1.8.0_161(linux) and I run that locally, then it fails.
I upgraded my mac to JDK 1.8.0_161 and still I am unable to reproduce it when I build i locally.
I then tried to login to our build server(JDK 1.8.0_161 linux), checked out the code, did a fresh build(mvn clean install) and copied the jar-file to my local machine and it fails.
So weird... I'll try to setup a virtual linux locally and reproduce it there.
Yes please do, I can't fathom where it would go wrong but can go right in some cases. So I'd like to hear any progress!
I think I found the source of the issue: classpath.
This is the start of the resolved classpath when I run the project via spring-boot:run from intellij:
/Users/michael/Development/meerkat/meerkat/target/classes:/Users/michael/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.5.3.RELEASE/spring-boot-starter-web-1.5.3.RELEASE.jar:/Users/michael/.m2/repository/org/springframework/boot/spring-boot-starter/1.5.3.RELEASE/spring-boot-starter-1.5.3.RELEASE.jar:/...
And this is the start of the classpath when I run the final artifact locally from the commandline (java -jar meerkat.jar):
/Users/michael/Development/meerkat/meerkat/file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/classes!:/Users/michael/Development/meerkat/meerkat/file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/lib/spring-boot-starter-web-1.5.3.RELEASE.jar!:/Users/michael/Development/meerkat/meerkat/file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/lib/spring-boot-starter-1.5.3.RELEASE.jar!:/Users/michael/Development/meerkat/meerkat/file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/lib/spring-boot-1.5.3.RELEASE.jar!:...
/Users/michael/Development/meerkat/meerkat/file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/classes!
looks a bit weird, doesn't it?
It comes down to https://github.com/querydsl/codegen/blob/60b65f97c1cfcd0a0ec073b7eadd40cdcbfb06b0/src/main/java/com/mysema/codegen/SimpleCompiler.java#L71-L72
The first URL retrieved in my case is jar:file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/classes!/
At line 71 it is being decoded to file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/classes!/
At line 72 the absolute path becomes /Users/michael/Development/meerkat/meerkat/file:/Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/classes!
I am unable to make it work.
SimpleCompiler.getClassPath(parent);
at https://github.com/querydsl/codegen/blob/master/src/main/java/com/mysema/codegen/JDKEvaluatorFactory.java#L57 returns a classpath that does not work when the application is run as an executable jar built with Spring Boot (https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html).
The classloader is a TomcatEmbeddedWebappClassLoader which resolves jars in the executable jar(Fx. /Users/michael/Development/meerkat/meerkat.jar!/BOOT-INF/lib/spring-boot-starter-tomcat-1.5.3.RELEASE.jar!
). But the classpath returned from SimpleCompiler is then broken and classes can then not be resolved.
My knowledge about JavaCompiler and the codegen project is to sparse. I have been unable to create a fix.
Yes the issue is known, I'll continue with my fix
Thanks for looking into it though, much appreciated!
@Shredder121 I just created a PR to add the support for Codegen to generate code when running in a fat JAR. It should fix this bug and others related to this. I'm using this fix and it works for me with Spring Boot, Spring Data Key Value, spring-data-hazelcast and QueryDsl Collections. The PR is: https://github.com/querydsl/codegen/pull/43 If you can, please review it and let me know if there are possible improvements to do.
This issue is indeed fixed by #43.
Is there any solution in sight or is building a custom jar still the only viable solution in order to use this with spring boot?
Any updates here?
@michaelkrog do you how to build custom jar to make it work on ubuntu/macos?
I am having an issue wen running my application with QueryDSL on OpenJDK.
I have 2 classes that I generate QueryDsl classes for. One(
Project
) is a MongoEntity class that I annotated with @QueryEntity and the other(Service
) is a POJO also with @QueryEntity.I use
com.querydsl.apt.QuerydslAnnotationProcessor
for generating the classes.When I compile and run it locally everything works fine. This is using the following JDK:
But when built for production using this JDK:
...and then run in a container with this JDK:
...then I get this exception for the
Service
class, but not theProject
class: