How to hot-reload resources inside jar with maven jetty plugin? - maven-jetty-plugin

I use the maven jetty plugin
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</plugin>
I have webapp with some other maven modules all in the same project.
When I do the mvn jetty:run all my ressources jsp, template are hot deployed once I save them. But this work only for the resources under the webapp folder.
Is is possible to include on the hot deploy the ressources contained in the other maven module/jar?

Related

Why is Checkstyle Not in Maven Central?

Why is it that I have to download checkstyle to get it to work? Why can I not just pop it in my build file as a dependency?
You do not have to download JAR in order to use Checkstyle
For Maven you can use: https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html or
For Gradle you can use: https://docs.gradle.org/current/userguide/checkstyle_plugin.html
Plugins come with ready Checkstyle configurations (based on Google and Sun Microsystems code standards), but you can use custom config file
Here (https://github.com/timurt/checkstyle-samples) you can find my old repository, how to use Checkstyle with Maven and Gradle

What is the trick for making jboss-client.jar available to the WAR applications in JBoss EAP 6

In JBoss EAP 6.1, there is a file
JBOSS/bin/client/jboss-client.jar
It contains all the client classes needed by web applications. However, when we install a WAR file, it is not seeing these classes available to it.
To work around this, we have been including a copy of this JAR in the war files WEB-INF/lib folder. These copies are a waste, but more importantly it means we have to have a different WAR file for every app server we want to install into.
Is there a trick to allow the applications in the WAR files to load and use the classes from this library where it is, without having to copy it into the WEB-INF/lib folder of the application? Alternately, is there a place we can copy this jar so that it would be available to all WAR applications?
The solution was to place a file named jboss-deployment-structure.xml in the WEB-INF folder. The contents of that file was:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<!-- Excluding conflicting JBoss-6 Implicit Modules so that jars bundled within war file is used. -->
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
</exclusions>
<!-- Defining additional dependencies for JMS usage in model API -->
<dependencies>
<module name="org.jboss.remote-naming" />
<module name="org.hornetq" />
</dependencies>
</deployment>
</jboss-deployment-structure>
This allowed us to use the JMS classes from JBoss without having a copy of the client library included with the application being installed. It seems that some time ago, a programmer ported the application to JBoss, and ran into a problem which was "solved" (hacked) by putting the client library in, but this is a far better solution.
Check Jboss Modules to make the lib available as an external module of Jboss.
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Development_Guide/chap-Class_Loading_and_Modules.html

Maven run docker image with java ee application

I have a running java ee application which is using wildfly and mysql. Now i heard that docker is using everyone and it is very productive so i decided to dockerize my development environment. Sounds easier than it is.
What i have so far:
Maven for packaging my app into a .war file
Arquillian unit tests which runs the test on my locally installed wildfly instance
What i want:
Using predefined docker images (jboss/wildfly,...) for running my application.
Also running my tests in the docker container.
I started out by building an docker image with the maven-docker-plugin:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>netbeans/sampleapplication</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.war</include>
</resource>
</resources>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</configuration>
</plugin>
Dockerfile:
FROM jboss/wildfly
COPY *.war /opt/jboss/wildfly/standalone/deployments/app.war
EXPOSE 8080 9990
Maven command: clean package docker:build.
I can reach the application server just with my docker-maschine url and not like previously with localhost.
In the end i just want to use a single maven command for:
Building the application
Building the docker images (wildfly,mysql...)
Run arquillian junit tests
Deploy the application and expose it via localhost:8080
Stop container if a new deploy is made
I am really struggling with that. Anbody an idea how to do this?
there is no straight forward way of doing this - since some of the docker tasks cannot easily be mapped to a maven phase. So you need to choose what a preferred way of working for you is.
So some thoughts that hopefully will lead to a solution:
The spotify-docker-maven plugin has no mojo's (maven goals) to run an image. Its main tasks are about creating and publishing the docker images.
So to run an image you can simply write some bash scripts (since they will be simple, they will run on linux and even windows using the git bash command line). You could execute those scripts using the maven-exec-plugin.
To properly map that to the maven lifecycle is a bit more tricky.
The phase that matches this the best (my opinion only) is the integration-test phase. This phase has a pre-integration-test phase, the integration-test phase and a post-integration-test phase. The idea is to startup the containers in the pre- phase. Then run the tests in the integration test phase using the failsafe-plugin (not letting the build fail!) and cleaning up the containers in the post- phase. It will be a good idea to cleanup the containers of that project in the pre- phase as well - just in case some zombie containers stick around.
These steps could be put into a profile. Since the integration-test phase is needed for integration tests as well, one would end up executing "maven verify" with different profiles (mvn verify && mvn verify -P docker-tests && mvn -P docker-other-tests).
Another approach would be using the maven plugin created by fabric8.
This plugin is a bit more complicated than the one created by spotify (again: my opinion only). But it comes along with more goals.
Using the provided <packaging>docker</packaging> of the plugin the docker run and stop goals are already mapped to the lifecycle.
Both plugins have in the end a similar complexity in the pom.xml - just its more reading with the fabric plugin. But there are some nice examples and a good user manual.
So those are the two options that came to my mind. Hope this will help :)
Alternatively to directly using a JBoss Wildfly container, you also might check out Wildfly Swarm. It's a separate distribution of Wildfly with even more goodies regarding docker.

Same jar Files in EJB & EAR project

How can I use the same jar files in EJB and EAR projects?
EJB ---> Jar files to add build path in Eclipse.
EAR ---> EJB project & jar files to add Java EE dependencies.
Otherwise I'm getting a class cast Exception for what seems to be identical classes.
Example:
com.sample.es.ra.EsCciConnectionFactory cannot be cast to com.sample.es.ra.EsCciConnectionFactory
In short: add the jar files as dependencies to your EJB project and the resulting EJB jar to your EAR project.
You can do it differently depending on the build management system. With ant, use depends attribute for your targets, with maven, define the EAR project as parent for your EJB project.
Ant example
Maven example
Jar files that are to be shared by all modules in an EAR archive can be placed in the \lib folder that's in the root of the EAR.
In Eclipse, using WTP's Enterprise Application Project it will look like this in project explorer:
foo_ear <--- the EAR project
EarContent
lib <--- Put your jars here
bar.jar
kaz.jar
foo_ejb <--- the EJB project
src
com.example
Something.java
EAR Libraries <--- lists libraries "found" in root EAR's /lib
bar.jar
kaz.jar

Headless integration tests of an eclipse plugin with maven tycho

I wrote some Junit tests for my eclipse plugin. If I start my test suite as a "JUnit Plug-in Test" from Eclipse, everything is working fine.
Now I want to run them from Maven Tycho.
So I put the following packaging : "eclipse-test-plugin", in the pom.xml and the integration tests start with a "mvn clean integration-test". So I think my maven configuration is quite OK.
But some tests are failing, and I suspect the headless build can't detect the IMarkers my tests are trying to detect, since IMarkers are UI components.
Am I right? Any idea to get my tests based on IMarkers running with Tycho?
You need to tell test plugin that you want to run the test with a UI, by default it will run with the headless runner.
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<useUIHarness>true</useUIHarness>
<useUIThread>true</useUIThread>
</configuration>
</plugin>