I have servlet-api 2.5 provided, but want to use it during integration tests. Is this possible? - maven-2

I am using the Jersey Test Framework, that includes servlet-api 2.5 in the test scope. Unfortunately, I have also written my own custom filter that requires me to have access to servlet-api at compile time. I don't want to elevate the scope to "compile" though, because I still don't want it in the war file. Is there any hope?

It is supposed to just work. To quote the reference:
This is much like compile, but
indicates you expect the JDK or a
container to provide the dependency at
runtime. For example, when building a
web application for the Java
Enterprise Edition, you would set the
dependency on the Servlet API and
related Java EE APIs to scope provided
because the web container provides
those classes. This scope is only
available on the compilation and test
classpath, and is not transitive.
Maven downloads the thing, adds it to test and compile classpaths, but does not include it in packaging.

Related

How to distribute and swap business logic at runtime?

I have experience in swapping business logic in .NET by loading assemblies, and using reflection to find an implemented interface. This enabled behaviour composition at runtime, by simply distributing and placing DLL files into its working directory. How can I achieve the same in Clojure?
I have been informed I could compile my Lein project without AoT compilation, with dependency on a class which the JVM will search for I assume from sibling JAR files? I've also seen Java 9 has a solution called "Jigsaw", and there other projects such as lein-jlink too. I'm unsure if those are suitable.
I'd really appreciate an article/tutorial, working example, or a good few hints on how to do this as I'm new to JVM also.
My project in particular would involve a business logic model "module" loaded at startup, consuming messages and producing messages in return. It's meant to be somewhat a blackbox.
An alternate route I'd like to avoid is an MQTT-style approach where distributed modules are relatively heavy standalone programs.
Thank you for your time.
In plain Java you can have use same approach as you did in C#: you develop a core and provide interfaces that can be used for extensions, then you inspect (using reflection) the Java CLASSPATH for implementations of the interface in Jar files (this is the same idea of DLLs), but the Java CLASSPATH is either an environment variable or a command-line parameter with a list of paths where to search for Jar files.
In Clojure, you have the advantage that you can distribute libraries either as compiled code or as source code which the Clojure runtime will load. I'd recommend looking into the Deps and CLI guide because it will give you good guidance into how to:
add dependencies on a configuration file through various means, including loading dependencies from private repos, or even a dependency in a git repo at an exact commit
launching you code with the various switches or configuration you might need, so that you can change behaviour by editing a config file

What is Java EE Endorsed API?

See here.
There are three different Java EE related API:s available in the Maven repository.
Specification APIs (Maven artifact: javaee-api)
Web Specification APIs (javaee-web)
Endorsed APIs (javaee-endorsed-api)
I know the specification API (the full blown suite of Java EE API:s) and the web API (a subset of the former, implemented by some application servers).
But what is the "endorsed API" and do I need to care?
Note: I did find this link but it tells me nothing.
I was having problems running a project because of this dependency in NetBeans. Installing "EJB and EAR" plugin solved it for me.
Looks to be GlassFish related. Download the jar and execute:
jar -tf javaee-endorsed-api-7.0.jar
Actually, if you look at the table in the "Standalone Technologies" section of that link you referenced, there seems to be a very good correspondence between the classes included in the javaee-endorsed-api-7.0.jar and the items in the table. I would say it seems that the jar is bundling up these for GlassFish so that the jar can be dropped into
<java-home>/lib/endorsed
And then become available to applications deployed on the GlassFish server.

OSGI aware IDE at development time

I'm starting development using OSGi but when one of my concerns is about the lack of support at development time, meaning that commonly IDEs (started using Intellij IDEA) don't use OSGi for class discovery but classpath search IDE managed (I'm in search for one that uses OSGi instead).
The main concern here is to prevent classpath issues at execution time by suing the same OSGi mechanisms at development time.
Does any IDE work this way ?
update: added link to blog post with my experience with IDEA
OSGi is a runtime technology, therefore there is no such thing as an OSGi mechanism at build time. Also bear in mind that ultimately all Java code must be compiled by a Java compiler, usually javac. The javac compiler does not use package dependencies like Import-Package, it always uses JARs or directories on the classpath.
Having said that, Bndtools uses package filtering at build time, based on the exported and private packages of the dependencies. This is a special feature of Eclipse and it does not work when you compile outside of the IDE, e.g. with Ant or Maven. However it may still be useful because if you try to use a non-exported package from another bundle you will get a problem marker with a red X in the Eclipse IDE.

Mocking framework for osgi/eclipse applications?

I am looking for mocking framework to use in my osgi/eclipse test fragments. I have looked at:
http://www.jmock.org/download.html
but since its not osgi I need to convert it manually. I have tried to google for some mocking frameworks that works with osgi out of the box but have not been able to find any, does osgi developers not use mocking?
One solution will be to create mock objects of OSGi objects (like BundleContext and ServiceReference). You can use any mocking framework for this and of course you don't have to run the test in an OSGi container. This will be OK for simple scenarios.
If you want to test inside a container, you have the following options:
Pax-Exam
Spring DM Testing facilities
Actually Mockito works quite good with OSGI applications, since it has OSGI manifest. You can simply add it to your target platform from the latest orbit repository. I managed to make Powermock also working for Eclipse Plugins and it is available as well as update site at https://code.google.com/p/powermock-osgi/

Ignore Sibling-Modules During Maven Javadoc/Site Compilation

I have a Maven-managed project which contains a few modules, one of which is the actual library of interest. The other modules are just add-ons or examples that build off of the library. I'm looking to generate the Maven site for this library and have it automatically deployed (as a standalone site and not as part of a multi-module site) but I am having trouble with the Javadoc plugin.
When executing the javadoc:javadoc goal, the javadoc plugin is attempting to access the jar for the other modules causing a failure.
I have created a simple example which demonstrates this phenomenon. Make sure you run the clean goal before any others so that the flaw be shown. Though executing the packaging first would solve this error, this cannot be done because the use case occurs during the Maven-managed release process which starts from a clean state.
Is there a way for me to disable this functionality in the javadoc plugin so I only get the documetation for the library module?
I can think of two options depending on your preference. Both include using profiles. If you want the default build to create the javadocs for your library of interest. Make the other modules use a property inside of the default profile in order to skip the javadocs.
If you are okay with passing in a profile, just have the javadocs only run in the profile.