using QueryDSL in osgi - osgi

I have been trying to use querydsl in a project which is an osgi bundle.
my pom.xml has the following dependencies:
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>2.5.0</version>
</dependency>
As well as the plugin
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>0.3.2</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.ops4j</groupId>
<artifactId>maven-pax-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<!-- | the following instructions build a simple set of public/private
classes into an OSGi bundle -->
<configuration>
<instructions>
<Import-Package>com.mysema.query.jpa,*</Import-Package>
<Export-Package>com.mypackage.package.*;version="${project.version}"</Export-Package>
</instructions>
</configuration>
</plugin>
Still when I try to start the bundle I get:
Error executing command: Unresolved constraint in bundle com.mypackage.package [163]: Unable to resolve 163.0: missing requirement [163.0] package; (&(package=com.mysema.query.jpa)(version>=2.5.0)(!(version>=3.0.0)))
I was using an older version of querydsl but apparently they fixed some stuff about osgi recently so I upgraded. The problem persists.
What I am missing for querydsl to work inside osgi?

Installing each dependency by hand will be a pain, but AFAIK there's nothing that will take a maven artifact and chain back of all dependencies - this would fail as where would it stop?
You could end up with every version of every logging framework (even if you had pax-logging installed), or the wrong implementation.
Alas in maven's case there's currently no way of applying semantic versioning or higher level requirement and capability. (Though BND (maven-bundle-plugin, bndtools) makes some sensible assumptions at a code level)
Karaf features (see the PDF manual in distribution's ${KARAF_HOME}) can do a lot to alleviate this but it can take some work to setup. There's a(t least) couple of ways to generate features files;
Use the features-maven-plugin
Use the maven-build-helper plugin to publish an XML file that you handcraft (laborious but you can maintain versions using resource filtering).

Related

Migrating AppEngine application to Java 11 runtime - [http://java.sun.com/jsp/jstl/core] cannot be resolved

So I have an AppEngine application that I'm working on migrating to the Java 11 runtime, and am using the appengine-simple-jetty-main artifact, as outlined in https://cloud.google.com/appengine/docs/standard/java-gen2/war-packaging, to replace the built-in Jetty server of the old Java 8 runtime.
Now if I use mvn jetty:run to bring up my application locally, everything works fine. But when I try to run the appengine-simple-jetty-main wrapper via mvn exec:java -Dexec.args="<my application directory>/target/<application>.war", I hit an issue.
The server starts up fine, and executes various ServletContextListeners that use outside dependencies declared in my pom.xml. I'm also able to navigate to static HTML. When I try to navigate to a JSP Servlet, however, I'm getting the error
HTTP ERROR 500 org.apache.jasper.JasperException: The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be resolved in either web.xml or the jar files deployed with this application
And likewise, I get this same error when I actually deploy to AppEngine.
As mentioned before, this works just fine when I bypass appengine-simple-jetty-main wrapper using mvn jetty:run, and my pom.xml includes the dependency
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>2.0.0</version>
</dependency>
My build section looks like
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>11.0.11</version>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<deploy.projectId>contra-program</deploy.projectId>
<deploy.version>GCLOUD_CONFIG</deploy.version>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/appengine-staging</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
So I'm a bit flummoxed. Other maven dependencies seem to be getting brought in just fine. It's only the JSTL library that's having issues (so far, at least), and even then, only when I use the appengine-simple-jetty-main wrapper.
The nearest existing question I could find was cannot load JSTL taglib within embedded Jetty server, but I haven't had luck with the provided solutions (though I'm more than happy to admit the possibility that I'm just not applying one or more of them correctly).
Any pointers would be greatly appreciated :-)

Simple Java Mail dependencies not in the jar file

I used simplejavamail in my maven project. The program can send out the email if I run it from Intellij IDE. But when I create a jar file, and run it from the jar file, then I got class not found for all the simplejavamail classes. And I open the jar, I find out that they are not included in the jar. But all the other dependency classes are there. Any one have meet this issue before?
parts of my pom.xml
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>6.4.3</version>
</dependency>
<build>
<finalName>my-project-name</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I'm having the same problem. It appears that the dependencies (Ex. Email, Mailer, EmailBuilder, etc) appear in the org.simplejavamail.api repository. I'll update you if I find a working solution with v6.4.3 but I have a feeling we may need to include additional dependencies.
Edit: To at least patch your problem,
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>5.5.1</version>
</dependency>
The 5.5.1 version still has the classes in the jar. You can reference this for yourself here:
https://www.javadoc.io/doc/org.simplejavamail/simple-java-mail/5.5.1/index.html
Then click on the different versions to see what classes exist.
I think something went wrong in their builds since v6.
Let me know if this helps!

swagger-codegen-maven-plugin best practices

I'm using the swagger-codegen-maven-plugin within my pom to generate a client. Here is my plugin info:
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.9</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.json</inputSpec>
<language>java</language>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Using:
java version "1.8.0_221"
Apache Maven 3.6.1
I had many errors when running mvn compile, as the package names could not be found in my repo e.g.
[ERROR]
//target/generated-sources/swagger/src/main/java/io/swagger/client/model/.java:[18,23]
package com.google.gson does not exist
To overcome the errors and enable a successful mvn compile, I have had to name the missing packages within my pom's dependencies e.g.
<dependencies>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
I don't believe this is best practice, as I have to specify the version myself without knowing the actual version that the source has used.
My question is, what is the best practice for generating a client using maven when there are packages which can't be resolved by the swagger-codegen-plugin? Alternatively, please advise if the resolution I have found to overcome the issue is actually the best practice in this scenario?
Thanks.

How to run XJC with Java 11 and maven?

To generate java classes from XSD (for reading XML files), we used jaxb2-maven-plugin and Java8.
For java 11, we get many issues...
What libraries and plugins do work (today), allowing to generate java code from XSD using java 11 and maven? If possible point out different solutions, such as with cxf-xjc-plugin, jaxb2-Maven-Plugin and others.
I've just investigated the same topic. The best way for Java 11 is to use cxf-xjc-plugin. It's a Maven plugin. No other Maven plugin is able to work under Java 11 without annoying workarounds.
I've published a complete example with cxf-xjc-plugin here: https://artofcode.wordpress.com/2019/02/28/generating-classes-from-xsd-under-java-11-the-right-way/
I was able to get Jaxb2-maven-plugin to work with Java 11. By default the generated classes will be created in the generated classes package. My only gripe is that it doesn't implement toString methods. If I ever figure that out i'll update this.
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc-foo</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<!-- if you put path only, it will read any wsdl or xsd file -->
<!-- if you have xsd that is imported in wsdl, then make sure you point it wsdl file -->
<source>${project.basedir}/src/main/resources/schemas/foo.wsdl</source>
</sources>
<clearOutputDir>false</clearOutputDir>
<packageName>foo</packageName>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation.api</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</plugin>

maven/apt generated classes in eclipse

Using following configuration in master pom, some classes (metamodel FYI) are generated for all child projects having jpa entities under target/generated-sources, as expected.
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.10.Final</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
This works perfectly from Maven and Netbeans.
Some team members still use Eclipse. There, generated classes aren't found automatically. They can be opened if added manually to the "build path" (whatever it means as this is redundant to pom.xml). However, that's not stable and will be reset whenever they "update the project" (shouldn't even be needed but...) to reflect project's maven configuration.
My question is, how to configure Eclipse to use this project's configuration automatically? I don't want to change the project's pom.xml too much, as they are perfectly legal and work well outside of Eclipse, which I just want to be taught to behave correctly.
UPDATE: M2Eclipse is installed and doesn't solve this, which is basically our problem.
There ist a project/Eclipse-Plugin called M2Eclipse (link).
The plugin includes the following feature:
Dependency management for Eclipse build path based on Maven's pom.xml

Resources