Jersey Test Framework - jersey

I have a non maven project. I would like to test my jersey rest services using the Jersey Test Framework. The jersey docs only relate to maven for the jersey test framework. Is it possible to add a jar or library to the project to use this framework?

Using Jersey client instead of Jersey Test Framework have two advantages:
It's well documented and only needs the jersey-client JAR
The written code is standard and can be use by the Java clients of your services

I would suggest you to add Maven to your project for some reasons
ability to use and helpful dependencies
having mechanism to create a build of you application with one command like mvn clean package
If you use Ant scripts you can easily call old Ant scripts from Maven with Apache Maven AntRun Plugin without significant Ant scripts rebuilding.

Related

How to bundle war file containing rest code with jax-rs dependencies so that it runs on Tomcat?

I'm using a Gradle based-setup to build a REST web service (with Jax-Rs and glassfish.jersey dependencies). I'm using the Gradle-tomcat plugin (bmuschko-gradle-tomcat-plugin) to deploy it on tomcat during runtime. I'm pretty new to this, and I've read that tomcat doesn't support Jax-Rs features on its own. So how do I make my REST code work on tomcat? Should I bundle Jax-rs/jersey jars along with my war? I won't be able to copy-paste those jars anywhere (few tutorials have the jars pasted under web-inf/libs module), I want it to be automated during the build with Gradle.
PS: I'm using #ApplicationPath (mandated by my company) in my code, which overrides servlet-mapping in the web.xml, so I won't be able to modify that.

Is there any particular reason why Spring boot starters using Maven? Is it straightforward to use gradle for custom starter with artifactory?

I am trying to balance time and avoid stepping on mines, on one side we have artifactory which is gradle based and need corresponding work to integrate with maven/gradle plugin(preferably with latter as most of our projects are gradle based) on another side all spring boot default starters in source are pom.xml + I only found single gradle custom repo:
https://github.com/web3j/web3j-spring-boot-starter in several pages of search results which uses gradle. But the build file looks pretty convoluted and includes a lot of maven parts.
I am happy to invest time into gradle if someone gives a green light with example/guide/share experience. Thanks. Just to understand if there is some particular reason why the situation is like that or I am afraid of ghosts?
A Spring Boot starter is a jar file containing some compiled classes and, typically, a META-INF/spring.factories file that lists some auto-configuration classes. As such, they can be built equally well with Maven or Gradle. Spring Boot's own starters are built with Maven purely because that's the build system that the whole project uses. If we were starting again from scratch now, we'd probably chose Gradle over Maven.
Some of the third-party starters listed here are build with Gradle, for example:
azure-application-insights-spring-boot-starter
charon-spring-boot-starter
session-couchbase-spring-boot-starter

Spring Boot Maven plugin - spring-boot:run and production

Is it a good idea or practice to start a Spring Boot application at production with a following command of Spring Boot Maven plugin ?
mvn spring-boot:run
No, this is a bad idea.
You would re-build your project on every run which means that you would pull all needed dependencies on each new VM / container.
Also using the spring-boot-maven-plugin in conjunction with the dev-tools for example would lead to options that you don't want in production.
This ranges from using other database settings to disabled caching mechanisms for your templating engine.
Use the executable jar instead.
If you want to run the application with the Maven JVM this is fine.
It is just an alternative way to run your application instead of using the executable jar.
As an alternative you could also start your application with gradle
gradle bootRun
Which is best depends on your circumstance. For live production code I would use a versioned executable jar always.

Using spring loaded with spring boot and maven

I'm creating an extremely simple Spring example as described here: http://spring.io/guides/gs/rest-service/ and I'm running it with mvn spring-boot:run. Now I want to add Spring Loaded plugin in there so that I as soon as I compile a java file, it should be compiled and reloaded. Hewever,
I don't want to use Gradle
I don't want to use Eclipse or Idea
Is there a simple way to set up Spring Loaded in Maven so that I can use it from command line?
You just have to add the springloaded jar as a dependency in the plugin configuration, e.g. as in the JPA sample.
Here's a link to the plugin docs: http://docs.spring.io/autorepo/docs/spring-boot/current/maven-plugin/run-mojo.html#agent

Is Spring tightly coupled with maven

Is Spring tightly coupled with Maven ? Most of the examples in the internet shows Spring and Maven to configure spring dependent jars, this post explains so many cons of Maven. All commercial projects are should to be using only this combination ?
Please explain
Thanks
Both of them serve different purposes, Spring examples use Maven because maven is highly adopted as a build, dependency management framework. That has nothing to do with Spring coupling with Maven. Spring is a framework to build enterprise applications and Maven is a build and deploy tool.
You can use Gradle, ivy or even manually download the libraries instead of relying on Maven as the dependency management framework.
No. You can use whatever you want to build your Spring-based app. BTW, all the Spring tutorials show examples using Gradle (that Spring also uses internally).
What is true, though, is that Spring jars are available from the Maven central repository and the Spring repository, and that their dependencies is thus described in a Maven pom.xml file. But nothing prevents you from downloading the required jars manually and add them in the classpath.

Resources