Java Micro Frameworks
blog.takipi.com
blog.takipi.com
Spark is a Sinatra-inspired micro-framework built on the familiar 'call me when this HTTP verb happens' pattern. It does little beyond that but is quick and easy to get up and running.
Despite the forks and stars, it's also probably the least mature of the three - it's not hard to run into a bug or a wart. Those are usually easy to find and fix since it's pretty small. On the other hand, the maintainer has been busy with other things for quite some time and it takes a very long time for PRs to get much attention. The testing setup is an ugly mess so adding a test for your fix is also unpleasant.
A couple of other constraints are that it requires Java 8 and, while it theoretically supports running in an arbitrary servlet container, it's really happiest living in embedded Jetty.
Why use Spark?
If you're a Java developer with neither the urge nor time to learn
a new programming language, and you're not planning to build a
super large web application that scales in all directions,
then Spark might be a great web framework for you.
Maybe they're just being honest, but "use Spark if you're stuck with Java and can't be bothered to learn something else" is a bit off-putting.I think a better angle looks something like "use Spark if you want a simple, minimal Java microframework" and "if you're coming from Sinatra/Flask/Express and you want something more statically-typed".
That's very common, and it's usually easier to get approval for a new framework than a different language.
At some point I just give up and start copy pasting source files; Java's whole environment is too painful for me to want to spend my free time on it, and too complex to learn it in passing at work. It's a lose-lose situation, and I just end up avoiding Java where I can. (Which imo is a shame, because JBoss e.g. turned out to be surprisingly neat once I wrapped my head around it.)
I've only ever heard that of Java and C++, and it seems it's always the stuff I cannot avoid because I need it for work.
Beyond that, a container, such as jboss, is free define how its things work. One of my favorite things to come out of the Java ecosystem is OSGi, which does dependency management in a very sane way.
[1] http://docs.oracle.com/javase/8/docs/technotes/tools/finding...
[2] https://maven.apache.org/guides/introduction/introduction-to...
Do you think it's better than the likes of npm, bower, or composer? where you just say: give me all these things, with at least these versions, and could you please run these scripts also --all at once, in about 30 lines
Every time I want to use mvn I need to start for google .. which was the archetype parameter that I needed?
or so let's run this not-so-common target, no problem I have 5 minutes for a coffee while it downloads all the requirements .. then 5 minutes later says "missing parameter"
Yes. "Run these scripts" leads to snowflake builds: every project ends up slightly different from every other, no-one can resist putting a little "magic" in their build that then goes on to confuse future developers. Requiring every build step to be encapsulated as a plugin, so that there's one and only one way of putting the scm version in your build, one and only one way of bundling your app into an executable, and so on, makes everything much more maintainable.
> Every time I want to use mvn I need to start for google .. which was the archetype parameter that I needed?
You don't need archetypes if you find them problematic. Just start with a minimal pom: groupId, applicationId and version. That's not so hard is it?
> or so let's run this not-so-common target, no problem I have 5 minutes for a coffee while it downloads all the requirements .. then 5 minutes later says "missing parameter"
Either you share your build steps, which means downloading them sometimes, or you copy/paste them everywhere. I know which I prefer. Maven caches quite aggressively (if anything too aggressively), I'm not sure what more it could do.
It's all about the quality of the developers.
Good developers can make good things with bad tools and bad developers can make bad things with good tools yes, but even so, tooling and defaults are extremely important.
And I'll throw in my personal experience too, which is the opposite: I've never seen any team that used Maven and had the discipline to manage it properly.
Anecdotes don't really get you too far.
Anyone remember using Ant with Java? Same thing I would say. Maven is convention over configuration for a reason.
"Better" is a word I don't like, but NPM failed to learn lessons from some of the aspects of dependency management that Maven nailed, e.g. support for standard HTTP caching proxies, immutable versioning.
NPM ran for many years before they switched off the ability for module publishers to overwrite an already published version number with new code.
That's not the reality. The reality is plugins which are java code - and if you're developing a java program you ought to be capable of debugging java code.
> It also improperly mixes compiling and downloading dependencies into a single tool
"improper" is like "unprofessional" - it's not a real criticism. Having a single command to build is very valuable.
being a safe, rigorously tested, backwards compatible
language is making some sacrifices around agility and
streamlining.
Yet there is nothing in Java as a language that prevents agility and streamlining. It's not a consequence of Java the language it is purely a consequence of Java's community.It's true that there are a lot of people who when doing java are starting to change the community from the inside and this is good. But pretending like you are fighting the language when doing this is counterproductive.
However, while I can see it taking some getting used to if one comes from a different background, I personally find Java to be nicely self-documenting when using the conventions on display in the standard libraries. Lines are long and sometimes a statement spans multiple, but in many Java libs/apps things do exactly what they're named.
That said, badly written code will suck in either language.
Coming from a C++ background, I consider Java's policy on operator overloading to be positively enlightened. There's plenty to complain about in the language, but this isn't one of them. I don't want to program in an ascii-art language.
If you want to play with it it is pretty simple to install it in the community (free) version of Intellij and marginally more difficult use without an IDE (you can get the compiler for the command line if you want). It is interoperable with Java so i recommend you try porting one of your existing classes (IntelliJ is supposed to be able to do that for you, but I haven't tried that so far).
It's really quite good. Provides integrated, configured libraries for REST, JSON, health checks and metrics. Even supports shaded fat jars (which provide a true single "java binary" you can execute with java -jar). It's really quite nice.
The first wave was around lightweight Java frameworks (a few of which we wrote about: Dropwizard vs. Springboot). These delivered lightweight, modern frameworks for Java and helped cut down development time. Now there’s a second wave that’s been recently hitting the scene. That wave is Java micro frameworks.
It's basically DropWizard reimagined with dependency injection. Thanks to Guice, there's surprisingly little code involved.
(I'm the primary developer)
Then again, I sometimes wonder myself if the definition blurs over the age and maturity of the project. If you look at Flask's ecosystem, there are extensions for nearly everything, making it so that ecosystem as a whole does just as much as a full-featured framework, but you have greater choice as to what components to include (and there's not One True Way to do anything in particular--there's just extensions that are more well-supported than others, well-maintained, and more popular).
I suppose this means that the better analogue is that micro frameworks give you greater control over lower level aspects and make fewer decisions for you (e.g. Django more or less expects you to do things Django's way; Flask has fewer such expectations). Given some of the micro frameworks I've seen, though, I think it's a definite spectrum, not an absolute, and probably depends just as much on the ecosystem and culture surrounding the language as it does on the intent of the creators. Silex (the PHP framework) does very few things, for instance, but it seems that you ought to include healthy chunks of Symfony if you really want it to be usable.
That said, I did stumble across something called "sinetja" [1] which I'd bill as an absolute micro-framework in Java in that it provides a fairly bare bones RESTful router/API and not much else. Think of it as another data point on the spectrum of micro-frameworks but much closer toward the bring-your-own-everything-else half.
So, if you want to roll your own bits to interface with 3rd party libraries or handle common tasks, use a micro-framework. If you want these decisions made for you, don't!
Oh, and logs. Nobody knew what happens there. Some alien life chatting about something. May be A.I. was about to born there. Don't think about logs. Use your own files.
And that thing actually worked and was useful to some people.
EDIT: Oops! See my reply below.
http://www.ninjaframework.org/documentation/getting_started/...
As I had previously recalled, Ninja's SuperDevMode involved a bunch of bytecode manipulation or something, but that was obviously incorrect.
Re Maven vs. Gradle, I HATE XML with a burning, undying passion. It's just my personal holy war, and while I quite like Maven, I moved to Gradle a while ago to cut out the main source of XML anguish in my life.
Of course, a quick google indicates that that is changing too:
http://www.infoq.com/news/2015/03/maven-polyglot
I do like me some YAML. Realizing that my early-morning phone comment was from half-memories and out-of-date information? Not so much :).
What about all those scripting language for java?
Jruby, Jython, Rhino, Nashorn....
For instance CDI for injection and inversion of control, plain JDBC, JAX-RS for RESTful API's on Tomcat or Wildfly app server. Not always necessary to use the more heavy weight technologies such as EJB, JMS, JPA (particularly the last one should be avoided, in my opinion).
Admittedly the concept of an app server can seem antiquated to some, but it's not necessarily a negative thing either.
They do bring useful things to the table, and can be used to build powerful and scalable apps - microservices as well even if they run within a container.
I'm no Java lover, but for some purposes (some non-technical) it's the only real option. These seem like great ways to cut the bloat and still get stuff done.
Several years ago I faced a problem that was extremely computationally intensive, basically the travelling salesman problem [0]. So I wrote the solution in c, fully documented it with a nice config file for all the knobs and the most beautiful makefile I've ever seen. When I presented the work it was as if I had brought a dead cat into the office. They ended up using it as a reference implementation and rewriting it in java, because "We are an Oracle shop" after all. Unsurprisingly the java version didn't work so great, not because java is a bad language, but because it wasn't well suited for the specific problem - it is much more difficult to write java code that can exercise the processor cache the was c code can.
[0] http://en.wikipedia.org/wiki/Travelling_salesman_problem
I still <3 you guys.
Heck, even Spring is looking good now. Many smaller projects, not a huge jar.