Running Liberty server as embedded from maven using maven dependencies - java

IBM Liberty documentation claims that it is possible to start/stop/manage Liberty server using SPI directly from the code. I'd like to use such functionality to create integration tests for my REST services.
Reference on original article:
http://www.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_extend_embed.html?lang=en
I want to create integration test that:
1) Start Liberty server with my own 'server.xml'. I want to provide specific DataSource and security here.
2) Deploy an EAR application on Liberty server.
3) Run REST-Assured tests on Liberty server.
4) Undeploy application and shutdown Liberty server.
Basically I stuck on 1st stage - I can't start server because I am getting 'NoClassDefFoundError: com.ibm.ws.kernel.boot.EmbeddedServerImpl' exception. The link above describes that 'ws-server.jar' from Liberty installation must be used, but what about referencing it from maven dependencies? I suppose that I could specify some artifact from IBM maven repo 'https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/' and use it to start Liberty as embedded server directly from my unit tests, but I can't find what that artifact should be.
So, to rephrase myself: what would be maven artifact in IBM's repository that contains EmbeddedServerImpl class? And is it enough to include that artifact or there are more of them required for liberty embedding?

You can't reference it from the Maven repository because it must be part of the Liberty installation that you want to start as it uses it's location to work out what it is starting.
I wrote an article and sample a little while ago outlining different techniques for writing functional/integration tests against Liberty including using a JUnit Rule with the Embedded Server starting and stopping the server:
https://developer.ibm.com/wasdev/docs/writing-functional-tests-liberty/
https://github.com/WASdev/sample.functionaltest
This was using Gradle to do the build script part so I included the launch JAR with:
fvtRuleCompile fileTree(dir: "${libertyRoot}/bin/tools", include: 'ws-server.jar')
The same can be achieved in a Maven build environment by using a System Dependency:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies

I don't think the ws-server.jar is provided in the IBM Maven DHE repository, only Liberty API's and SPI's and some packaged runtimes are provided to the user as Maven dependencies.
By the way, if you're using artifacts from the IBM Maven DHE repository, you may want to change them for the ones that are now provided in Maven Central, see:
http://mvnrepository.com/artifact/com.ibm.websphere.appserver

Related

How to debug Tomcat source code with an application which uses embedded tomcat server?

I am working with a full-stack application(JSP and Java,Spring based). It is having an embedded tomcat server. Suppose I made some changes in the tomcat source code relevant to the embedded tomcat server(same tomcat version) which I use in my application.
I need to debug the tomcat source code when upping my application with the embedded tomcat server.
Is there any way to achieve this?
Note: I use Apache ANT as the build tool.
To achieve what you want you need to substitute the jar file with embedded tomcat (I guess this is org.apache.tomcat.embed:tomcat-embed-core). Please follow these steps:
First of all you need to build the jar from sources that you've modified locally by running e.g. mvn clean install. This would install the jar built locally into your local maven repository. Pay attention, that in order to distinguish your build from the rest you need to specify your custom version in pom.xml of Tomcat sources (e.g. you specify 9.0.0-my-custom-build)
As soon as your custom build is now in m2 it can be used by your main application. In <dependencyManagement> section of your pom.xml you need to specify this:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.0-my-custom-build</version>
</dependency>
This declaration forces maven to use tomcat of your custom version i. e. 9.0.0-my-custom-build.
Build your application and run it. At debug time you'll be able to see and debug your changes.
P.S. No matter what is your building system, the clue is the same: jar built from modified sources must substitute the default one in classpath of your application.

Where can i find the maven dependencies for Webshpere eXtreme Scale?

I have been googling for some days now about this. I am trying to develop a spring boot application (which is going to be deployed into a Websphere Liberty Profile Server), and is going to connect to Websphere Extreme scale for caching. I went through several documentations and guides, but none of them provide an actual source of where to find the dependencies for connecting to wxs from a maven built application.
I had assumed that the required jars should have been bundled along with the wxs liberty feature installation. But I could not find it in the lib directory of the server either.
I believe I am looking for
file=objectgrid.jar,groupId=com.ibm.websphere.objectgrid,artifactId=objectgrid,version=8.6.0.2
Any links towards a sample java maven application that connects to wxs will also be helpful.
Thanks in advance
The required jars are indeed included in the WXS Liberty installation. However the namings were'nt objectgrid or ogclient as stated in different docs.
The only required client jar for developing a wxs client application is sized at 15MB, named com.ibm.ws.xs.client_1.1 and in the directory [WASDir]/dev/ibm-api.
You can add this jar to your applications build path and develop wxs client applications.
If you are using maven, (I was), you could install the above jar in your local maven repository with a mvn install:install-file -Dfile=? -DgroupId=? -DartifactId=? -Dversion=? -Dpackaging=jar and use the installed dependency in your project.
Note that, these are only for development purposes.(as are all the Liberty Features)

Drools Kie application without Maven

As a developer I want to create a Maven project and build an executable standalone JAR application. (No Spring Boot)
During development and build processes I want to add a Drools Kie artifact as dependency
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>mydrools</artifactId>
<version>[1.0.0,)</version>
</dependency>
build my application as executable Jar and run it. My application has the code to call the Drools engine:
KieSession kSession = kContainer.newKieSession();
kSession.insert(myBean);
kSession.fireAllRules();
Above all, whilst I deploy my application on production:
I do not want to install Maven on my production server
I do not want my application to scan a local nor remote Maven repository
I want my application automatically scans periodically for a new version of my Drools Kie artifact without any reference to a Maven repository, just looking at the filesystem
I have tried with
String fileName = System.getenv("HOME") + "/libs/mydrools-1.0.0.jar";
File file = new File(fileName);
KieRepository kieRepository = ks.getRepository();
KieContainer kContainer = ks.newKieContainer(ks.newReleaseId("com.mycompany", "mydrools", "1.0.0"));
kieRepository.addKieModule(ks.getResources().newFileSystemResource(file));
KieScanner kScanner = ks.newKieScanner( kContainer );
kScanner.start( 10000L );
Loading the JAR works fine, but it seems that I am also forced to configure at least a minimal Maven repository (~/.m2 folder and a settings.xml). I get a heap of errors by the org.apache.maven plugin and related classes.
Of course I do not want my production environment to rely nor depend on any Maven configuration. I just want to run a JAR with another JAR (e.g. libs/mydrools-1.0.0.jar) as dependency and possibly dynamically reload that dependency whilst I update the libs/mydrools-1.0.0.jar.
Basically I need to set the internal Drools Kie Maven plugin completely disabled (offline).
How is it possible to do this with Drools 6.2.0.Final?
Update
This issue is strictly related with
Using Drools 6 Maven architecture completely offline
http://lists.jboss.org/pipermail/rules-users/2014-June/036245.html
The answer is you don't. KIE 6.* (and 7) has maven built into it, the KieScanner class uses maven to find updates.
The scanner will work better if in the ReleaseId you specify a version range e.g. [1.0.0,)
My company is in the process of deploying KIE based applications to production. We're setting up an Artifactory repository in PROD and there will be a maven repository as well.
You can essentially disable the maven part by not using KieScanner, instead use the getKieClasspathContainer() to get the KIE container. You won't be doing dynamic updates to rules though.
KIE also provides an Execution Server which pushes the Rules into a REST API. The Execution Server rules can also be updated via maven.
Architecturally speaking, you have three rule deployment models:
Model #1 is a dynamic rule updating mode. In 5.3 it pulled compiled classes over http, now in 6 & 7 it uses maven as the transport since it provides versioning and is by far the most prolific artifact versioning and transport tool. In this mode you have a production application (jar or war) which pulls rules (over maven aether through kie-ci) from a maven repo (you can have a dedicated maven repo for PROD if you like). If you use this model then you need kie-ci as a dependency and it will magically use maven under the hood.
You could use the scanner & have a maven settings.xml configured that has no <servers>, and therefor it should only pull from the production server ~/.m2 folder, allowing you to deploy to the server file system and use the OOTB scanner without any danger of it pulling externally.
Model #2 is a immutable rule model. So the concept is that you embed the rules in the application as a resource, they cannot be updated. This works well with immutable deployments such as CD pipelines and container/docker deployments that need to test the state of the app as it is right now. Having said that containers don't prohibit the option to dynamically update, I'm speaking from a pure architectural perspective. For this more omit kie-ci from the deps and use the 'getKieClasspathContainer()' (as whomer said) to load the rules from the resources folder and it will never attempt to update without redeploying the app.
Model #3 is a centralized "server" mode (and I'm only adding it for completeness due to it's limited use). It's where you centrally execute rules outside of your application's runtime, made popular by IBM's rule (and marketing) engine. However it is inferior for most use cases except in a managed service type application where you want to cross-charge. It doesn't scale naturally along with the app, entities have to be de/serialized over the wire so performance is poor etc.. however you do get central logging.

Heroku: Java/Maven build requires NodeJS

I've got a Java web application that builds with Maven. My project uses RequireJS. I use a maven plugin at build time to compress the JS artifacts (https://github.com/bringking/requirejs-maven-plugin). The plugin calls out to NodeJS (with the r.js compressor) to do the actual work.
Local builds work wonderfully.
On Heroku, however, NodeJS is not available using the Heroku Java buildpack (the default for Java/Maven applications).
For now, I run the requireJS maven plugin locally using an active Maven profile that isn't present on the Heroku server. This prevents the RequireJS plugin from running on the Heroku server. This is less than ideal because it requires me to run the plugin locally, then check in the resulting build artifact. It's far better to generate the compressed JS file at build time in the Heroku system.
I'm looking for a good solution. Thanks in advance.
The best solution is to use Heroku Multi Buildpack with the Node.js and Java buildpacks. This is described in an article using Grunt with Java and Maven but the same principles apply for Require.js.

Which Maven GlassFish plugin to use?

I've been trying to integrate deploying java .war's in GlassFish V3 through Maven. While I have found a few plugins, none of them look to be very active:
Maven Glassfish Plugin
Eskato's Wordpress Blog on Maven
And I got the most information out of Eskato's Blog, it was written March 2008, so I don't know what the state of GlassFish Maven integration is, nor can I find a suitable plugin to work with. With the Maven GlassFish Plugin I have had some success, but it still doesn't work entirely well for all goals it says it supports, which makes some of the commands ineffective.
Has anyone else been able to integrate Glassfish V3 and Maven successfully? If so, what resources did you use to get it done?
Update: CARGO-491 has been fixed and I've updated my answer accordingly. To summarize, there are now basically three options:
Maven GlassFish Plugin
A first option would be to use the Maven GlassFish Plugin. This plugin allows to interact with a local or remote GlassFish install and the management of Glassfish domains and component deployments from within the Maven build lifecycle.
Maven Embedded GlassFish Plugin
The second option would be to use the Maven Embedded Glassfish Plugin. As stated by its name, this plugin doesn't rely on an existing install but uses an embedded GlassFish, running in the same JVM as the plugin. This plugin is extremely nice if you want to keep your build portable (anybody can get your POM and run a build involving GlassFish without having it installed) with almost the same features as a normal GlassFish install, except clustering of course (you can use a preconfigured domain.xml if you want). See Testing with the GlassFish Maven plugin and JavaDB Embedded for an example.
Maven Cargo Plugin
The work initiated by Kohsuke Kawagushi as been finally integrated in Cargo and, starting with Cargo 1.0.1, GlassFish 3.x is now supported. Using the Maven Cargo plugin is thus a third option. This would be interesting for builds that want to interact with containers in an agnostic way. But I'm not sure Cargo allows all the flexibility of the GlassFish specific plugin(s) (e.g. deployment of JMS resources, etc).
maven-glassfish-plugin and maven-embedded-glassfish-plugin both have their pros and cons. The main difference is that the latter works with an Embedded Glassfish instance, as indicated by its name, i.e. the server is running in the same VM as the plugin.
So you cannot use maven-embedded-glassfish-plugin to deploy your WAR to a standalone Glassfish server, you need maven-glassfish-plugin to do that.
The main problem I had with the maven-glassfish-plugin is the fact that its interaction with the Glassfish server is stateful - I could not find a way to use it such that my WAR would get deployed to the server in any case, no matter whether the previous build succeeded or not.
glassfish:deploy does not work if the WAR is deployed already. glassfish:redeploy does not work if the WAR is not deployed. And Maven has no if-else logic...
I've blogged about how to configure Maven Embedded GlassFish plugin to work correctly with GlassFish 4.0 until there's a new release of that plugin.
https://blogs.oracle.com/brunoborges/entry/glassfish_4_beta_and_maven
Also, it is possible to configure a datasource in the glassfish-resources.xml and have it working correctly.
https://blogs.oracle.com/brunoborges/entry/configure_datasources_for_maven_embedded
These are useful tips to anyone that want to run Java EE 7 projects with Maven and GlassFish 4
You can use this one :
http://www.hascode.com/2011/09/java-ee-6-development-using-the-maven-embedded-glassfish-plugin/
https://github.com/andrzejsliwa/glassfish-maven-plugin/wiki
http://cargo.codehaus.org/Maven2+plugin
I use the glassfish plugin on maven-glassfish-plugin.dev.java.net and did some code changes to support v3 now. I requested committer status and wait for acknowledgement. Hopefully I can commit my changes.

Categories

Resources