how to setup swagger-jaxrs-maven? - maven

I am trying to use "swagger-jaxrs-maven" plugin to generate RESTful API docs from the source code.
I followed this web site:
swagger-jaxrs-maven
but maven complained that it can't find this plugin, so I searched it on
maven central repository
It only finds it under groupId com.greensopinion.swagger. So I changed it accordingly.
But now I get this error:
[ERROR] Failed to execute goal
com.greensopinion.swagger:jaxrs-gen:1.3.0:generate (default) on
project treaty: Execution default of goal com.greensopinion.swagg
er:jaxrs-gen:1.3.0:generate failed: Unable to load the mojo 'generate'
in the plugin 'com.greensopinion.swagger:jaxrs-gen:1.3.0' due to an
API incompatibility:
org.codehaus.plexus.component.repository.exception.ComponentLookupException:
com/greensopinion/swagger/jaxrsgen/SwaggerJaxrsGeneratorMojo :
Unsupported major.mi nor version 52.0
I cleaned all my local maven repository and re-tried, it doesn't work.
My maven is 3.2.3 and JDK is 1.7.
My RESTful framework is Jersey2.17 with Jackson.
Any suggestion on how to make it work?

This issue is not related to swagger or maven but to your JDK version (version 52.0 means a JDK 8 is expected).
See https://stackoverflow.com/a/35866015/779338 for mode details.
Furthermore, if you download the pom.xml of swagger-jaxrs-maven available in maven central repository, you can see that a JDK8 (maven.compiler.source=1.8) has been used to generate a java 8 package (maven.compiler.target=1.8), then it can't be used with a JDK7.

I have following Maven dependencies, it turns out fine.
For Swagger, Phillip project which just plug and play.
<dependency>
<groupId>com.github.phillip-kruger</groupId>
<artifactId>apiee-core</artifactId>
<version>1.0.8</version>
</dependency>
JAVA EE - JAX-RS api
<!-- Java EE -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
Use JDK 1.8 or above.
I use eclipse and wildly server.

Related

Dependency javax.mail:mail:1.4 not found

After I imported a maven project in IntelliJ IDEA, there are two errors in the pom.xml file:
"Failed to read artifact descriptor for javax.mail:mail:jar:1.4"
"Dependency javax.mail:mail:1.4 not found"
Does anyone know the reason behind these errors and how can I fix them?
Thank you and have a great day!
Due to license restrictions the older java mail classes are not in maven central or the java.net repository. usually companies host their own maven proxy and add these classes there.
Since around version 1.4.5 the dependencies are available in the java.net repository. Some later versions are also in maven central.
All other versions need to be downloaded from the oracle website and either added to a maven proxy or to your local maven repository - for example using the dependency plugin.
Change the pom.xml to include:
<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.6.3</version>
</dependency>
</dependencies>
Or if you have a build.gradle file in the dependencies section add:
compile "com.sun.mail:jakarta.mail:1.6.3"

Versioning issue when using jersey 2.9 with tomcat7 + java8

We have a maven project to develop a jersey 2.0 REST service, on Eclipse (kepler)
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.9.1</version>
</dependency>
In conjunction with:
java8
tomcat7
When deploying the web application (using $ mvn install && mvn -X tomcat7:redeploy) we get the below exception:
Caused by: java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/init/JerseyServletContainerInitializer : Unsupported major.minor version 51.0 (unable to load class org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2840)
I examined the MANIFEST file in the org.glassfish.jersey.containers jar, and (as suspected) it says build on 1.7 JDK
Tomcat logs confirm that it uses java8 itself
We cannot move back to java8. Is there a way/hack we can get past this error?
From tomcat 7.0.26, I upgraded to next version > Tomcat 7.0.47, to see if that helps.
Things started working magically. Deployed app successfully
Would be glad if someone can explain how the same plugin started to ignore jdk versions, just due to a change in tomcat version.

can't find valid maven repository for hibernate-search-4.2.0.Final.jar

I use maven.
I want to use the last version of hibernate-search : 4.2.0.Final
I was under 3.3.0.Final
I can't a valid maven repository for this version.
Which maven repository I have to use to get this version of hibernate search ?
Because if you go there :
https://repository.jboss.org/nexus/index.html#nexus-search;gav~org.hibernate~hibernate-search~~~~kw,versionexpand
You'll find the version I need, but when I download hibernate-search-4.2.0.Final.jar and I unarchive it, I see there is only META-INF folder but no class in the jar : the jar is invalid !
Thanks for your help !
The hibernate-search project changed their artifact structure to use hibernate-search-orm instead of hibernate-search. Hibernate-search is now just a jar that declares a dependency on hibernate-search-orm which maven will resolve transitively and include in your project.
See the upgrade notes here - https://community.jboss.org/wiki/HibernateSearchMigrationGuide
More specifically this note - https://community.jboss.org/wiki/HibernateSearchMigrationGuide#New_jars_Maven_modules_reorganization
If you look in the pom for hibernate search you will see the dependency - this should all be resolved from central without any additional repository.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>${project.version}</version>
</dependency>
The best repository for JBoss artifacts is: https://repository.jboss.org/nexus/content/groups/public-jboss/
The available repositories are explained in their wiki: https://community.jboss.org/wiki/MavenRepository
The group public-jboss contains all releases and third-party artifacts required to by JBoss artifacts.
Isn't maven central good enough ?
http://search.maven.org/#search|ga|1|hibernate-search
Since this is a JBoss project, you can get newest builds from our Nexus repository. Here is how to configure it in your ~/.m2/settings.xml. Your pom.xml then should contain this dependecy.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>4.2.0.Final</version>
</dependency>

How can I add a JavaFX 2.0 class to an existing Maven project?

I have a Maven project that just displays a graph on the xy axis. I want to change that graph to a Javafx 2.0 linechart to display the same data. I tried using the FEST-javafx-maven plugin, but I still cannot compile the code; the compiler cannot find all of the javafx.xxx imports.
Any help would be appreciated.
Update (Oct 6 2015)
Modern JavaFX versions (shipped with Oracle Java 8+) do not require any additional class path to use JavaFX. The JavaFX runtime is on the default classpath Java uses for compilation and execution. This means that a plain maven pom.xml file, with no additional dependencies, will build a JavaFX application.
However, if you wish to use additional packaging features for your application, such as the ability to deploy it as a self-contained application, then I advise using the (third party) JavaFX Maven plugin.
Previous Answer
The following information in this answer is now mostly old and outdated.
The link to the fest maven plugin I found (http://fest.easytesting.org/javafx/maven/) is to a tool for building JavaFX 1.x script projects, which is a completely different and incompatible beast to JavaFX 2.0 - I'm not sure if there is an updated version of the fest maven plugin which supports JavaFX 2.0.
There is currently no official support for Maven from Oracle, nor a version of JavaFX 2.0 in a publicly hosted Maven repository.
However, I have successfully built JavaFX 2.0 projects using maven in the past by using a system scoped dependency on the jfxrt.jar and (optionally) invoking the JavaFX ant tasks from maven.
If you are embedding your graph in an existing Swing application via a JFXPanel, then you don't need to use the JavaFX ant tasks. Add jfxrt.jar from the JavaFX runtime as a system dependency OR manually install it into your maven repository to use a non-system scoped dependency.
An example of the command to manually install the required JavaFX 2.0 runtime jar is:
mvn install:install-file -Dfile="C:\Program Files\Oracle\JavaFX 2.1.0 SDK\rt\lib\jfxrt.jar" -DgroupId=com.oracle.javafx -DartifactId=javafx -Dversion=2.1 -Dpackaging=jar
After running the above command, add the dependency to the jfxrt.jar file to your maven pom and your project compilation should resolve all JavaFX API references:
<dependency>
<groupId>com.oracle.javafx</groupId>
<artifactId>javafx</artifactId>
<version>2.1</version>
</dependency>
If you extend the JavaFX Application class and you want your application packaged for deployment via webstart, browser embedding or as a JavaFX installation aware clickable jar, then you should adapt your pom.xml file to execute the relevant JavaFX 2.0 ant tasks - http://code.google.com/p/willow-browser/source/browse/pom.xml demonstrates such an adaption.
These threads discuss JavaFX 2.0 maven support and provide further background info and samples:
https://forums.oracle.com/forums/thread.jspa?messageID=9970002
http://mail.openjdk.java.net/pipermail/openjfx-dev/2011-December/000076.html
I had the same problem and here is my solution:
If using Java 7u7 (javafx is integrated into jdk/jre):
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx</artifactId>
<version>2.1</version>
<scope>system</scope>
<systemPath>${java.home}/lib/jfxrt.jar</systemPath>
</dependency>
For previous versions of java:
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx</artifactId>
<version>2.1</version>
<scope>system</scope>
<systemPath>${env.JAVAFX_HOME}\rt\lib\jfxrt.jar</systemPath>
</dependency>
And you have to set system variable JAVAFX_HOME to home dir of JavaFx.
You might try the JavaFX Maven plugin. This takes care of adding javafx to the classpath as well as building JavaFX apps and creating Windows/Mac/Linux executables, as well as double-clickable JARs and JNLP files.
Using JDK 1.7 you have to perform the following mvn goal.
mvn com.zenjava:javafx-maven-plugin:2.0:fix-classpath
This command will change the classpath of your JRE and copy the jfxrt.jar to the JAVA_HOME\lib\ext directory.
Take an additional look here for further information:
JavaFX Maven Plugin
Within your pom-file you have to add the following dependency configuration.
<dependency>
<groupId>javafx</groupId>
<artifactId>jfxrt</artifactId>
<version>2.2</version>
<!-- <version>${javafx.min.version}</version> -->
<scope>system</scope>
<systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
</dependency>

Maven - Java EE 6 Web Profile Javadocs

By declaring the following dependency:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
I can use about everything I need for a Java EE 6 Project (Servlet 3.0, JPA 2, EJB, CDI, etc).
The problem is: Maven can not download the Javadocs for the dependency (or at least m2eclipse "Download JavaDoc" feature don't work), so Eclipse don't show me the Javadocs when I use the very handy code completion feature.
I've found this post specific to Servlet 3.0 API, Maven dependency for Servlet 3.0 API?.
Can anyone kindly point to a solution that works for every API? Or, can anyone please provide a dummy guide to install Java EE 6 Javadocs and link it to javaee-web-api artifact in the local repository?
Assuming you have Java EE javadocs, you can install them to your local maven repository using the maven install plugin. Look at this usage link
You would use the -Dclassifier=sources to indicate you are installing sources. See this example for this.

Resources