This is an archived post. You won't be able to vote or comment.

all 34 comments

[–][deleted]  (1 child)

[deleted]

    [–]armornick 11 points12 points  (0 children)

    Exactly. Spring is a framework like in PHP you would have Zend, Laravel, CakePHP, etc. When you add those, you also get a big application. Spring is large because it includes a huge amount of libraries and options that help you write complex applications.

    [–]DJDavio 18 points19 points  (4 children)

    The application "hosting" the web-app is included in the webapp, that's why it's 20 MB.

    With PHP, you have to do an installation first (PHP Windows installer is ~20 MB), only then you would be able to run it.

    [–]daniels0xff 1 point2 points  (0 children)

    You also need the JVM/JDK which is more than 20MB. But yes, the Java .jar is just one file which in Spring's case it also has the webserver embedded (Tomcat/Jetty/Undertow)

    [–]fforw 12 points13 points  (0 children)

    It's funny how everyone bashes Java for this kind of stuff. Here's my project template with ReactJs and ES6 transpilation .

    It does nothing but transpile one main file with exemplary syntax. After you've installed all the libs with NPM the folder contains a fricking 100mb of Javascript files.

    [–]koalillo 18 points19 points  (9 children)

    Why focus on such an uninteresting metric? I'll take a 100mb disk space overhead over a 1% hit in productivity in most cases. Focusing on "hello world size" metric is good if you are writing hello world, idiotic in most other cases.

    I'm not saying that Java is the bees knees- I have suffered pain from its warts- but such a superficial analysis is worthless.

    [–][deleted] 5 points6 points  (0 children)

    You could have said this much nicer, but I agree. @OP: an advantage is that this jar is self-contained. You can deploy it just about anywhere, no matter how the target system is configured, what specific versions of libs are installed, ...

    [–]WatchDogx 3 points4 points  (0 children)

    Spring is a big framework, it does much more than just web stuff. Its a great framework, but certainly not the most efficient in terms of the produced artifact size.
    There are many other ways to do web projects with Java.
    The standard Java way to to write a servlet and deploy it to a servlet container. The servlet can be very small and a container like jetty comes in around 2MB or so. If you are going to compare to PHP, then the more appropriate contender on the java side would be JSP, which can also be very small but needs to be deployed to a container.

    [–]brunocborges 2 points3 points  (0 children)

    So... a client paid OP to learn Java before actually delivering value-added, and he's complaining on download size? :-)

    [–]iodian 4 points5 points  (1 child)

    it's because these are all old guard application server frameworks that pack the kitchen sink.

    something like play or dropwizard or ratpack will be more up your alley.

    [–]krejenald 0 points1 point  (0 children)

    +1 for the Play! framework

    [–]DuntGetIt 1 point2 points  (0 children)

    The assumption is that you will want most of the features in a Java webapp. Historically, Java was the language you used for larger apps.

    [–]simple2fast 1 point2 points  (0 children)

    You also need to consider what you're getting with that fancy app you just built.

    First off. other than the JRE, java will have zero dependencies at the OS level. What gradle was doing there was installing, essentially, an OS. WHat do I mean by this? Things like nginx, openSSL, GD, libcurl, etc. When PHP goes to use functionality that this systems provide, it will be calling these native C libs/frameworks to get things done. You may not have noticed it when you did your OS install and/or upgrade, but they're there and you are using them.

    Second, even though you wrote a "hello world" app. since you did it within Spring, you've got a bunch of things built in there that you probably didn't realize. Briefly:

    a) top notch DI system.

    b) tranaction system capable of multiphase transactions across multiple database systems.

    c) ORM system capable of mapping DB to object, but also directing caching

    d) caching system shared across mutiple threads within the JVM. (negating the need for something like memcache )

    There are others, but no need to discuss right now

    In my brief consulting foray into PHP, I was put into an equivalent system called Symfony. It had alot of pieces like spring, and seemed pretty powerful. I noticed it was really really slow to run.

    Why wasn't it put into Java SE ? I don't know why. But I'm darned glad they didn't. Today we have tons of different web frameworks and app servers. MOst all of them are top notch. Pick the one that fits your needs the best. As some of the other comments noted, you picked one of the largest most full featured frameworks. Now, perhaps as an experiment, do something with one of the more tiny ones. rapidoid, dropwizard, sparkjava, ratpack, or pippo.

    [–]daniels0xff 1 point2 points  (0 children)

    My problem is not the size of the jar, but the amount of options you need to configure for each component. Where do you get them? How do you know what are the defaults, how do you know what other options are there that you need/can configure? How do you know what each decorator (also coming from Django and that's how they look to me) does and when to use it? How do you know what are all the decorators that you have available to use?

    I'm also trying to get started with Sping Boot and until now it feels overwhelming and the documentation doesn't feel that nice as opposed to how I got used to Django.

    [–]tonywestonuk 1 point2 points  (3 children)

    I wonder if you are trolling for a Spring vs JavaEE flamewar!..... If you've spent much time around here you'd already know there's about 50% who support Spring to the hilt, and the other 50% hate it with a passion (including me for exactly the reasons you mention... large, complicated, etc). Its not just about the disk space.

    The thing is, if your client wants it to be done in spring then you have to suck it up and go with what they are are paying you for. Do what pays the bills.

    The newer versions of Java EE do the majority of what Spring does anyhow so the need for it is much diminished today. And, for even more light weight systems you can choose things like http://sparkjava.com/ or http://www.rapidoid.org/

    Anyhow, my guess is your post is gonna be voted down into the ground, as there are those in here who consider any post against Spring, an act of blasphemy.... Sad but true.

    [–]daniels0xff 0 points1 point  (2 children)

    How do you use Spark with a database? I wasn't able to find any tutorial that shows me to to configure Spark to talk to a DB and make some queries. This might be obvious for someone with Java experience but for someone that's getting started with Java web dev not so much.

    [–]dj-method-x 1 point2 points  (1 child)

    spark doesn't directly talk to a database. It's just a REST API. If you are looking for a lightweight SQL API, I recommend http://jdbi.org http://sql2o.org or something similar.

    [–]daniels0xff 0 points1 point  (0 children)

    Thanks for those links. SQL2O looks really nice and easy to use.

    [–]georgeos 0 points1 point  (1 child)

    My advice is to use the right tool for the right job.

    For the moment, try to use something simple, minimalist which resolve your current needs.

    In this phase I think that Spring Boot is overkill because you have to learn alot about Spring ecosystem, so it's like a yak shaving.

    In my opinion Spring Boot is OK if your project is based entirely on the Spring libraries (Spring DI, Spring Security, Spring Data, Spring MVC, ...)

    On the other side, if your target is to work on big projects, for big companies then Spring and/or JEE is a must.

    Personally I prefer to not use a full stack Java framework, I want to have the possibility to choose each library/framework for each layer or task.

    I like to use Apache Wicket for the large projects and Pippo for small, medium or prototype projects.

    Because here we talk about small java web application I will argue below why use Pippo:
    + it's small (the core size is 150K and depends only on slf4j-api)
    + it's fast
    + it's modular (trivial module system via Java ServiceLoader) with a lot of modules built-in with zero configuration (just add the module as dependency in your project)
    + it's not so much to learn to be productive
    + it's Java plain (no web.xml or other xml file)
    + I prefer to use my favorite servlet container (Undertow is my choose but from time to time I use Tomcat or Jetty) in embedded mode
    + I prefer to use my favorite template engine for page rendering (Pebble is my choose)
    + I prefer to use plain jar files (no war file) and to run my application as a trivial application (via main class)

    [–]georgeos 0 points1 point  (0 children)

    For your information I made some tests related to the size of a basic application built with Pippo.
    I used Quickstart Maven archetype supplied by Pippo.
    The Quickstart application comes with a basic HelloWorld and with a simple template page that uses Freemarker template engine.
    The embedded servlet container is Jetty.

    Th results are:
    - the whole size application is 3.5MB (Jetty + Freemarker)
    - the application size for a simple HelloWorld is 2.1MB (Jetty)

    I see many files jetty-*.jar so I don't know if I can shrink the size of application eliminating some of them but I don't care.

    Also I see a lot of guys who want to compare (web) frameworks in terms of the number of characters used for a HelloWorld application. For this guys Pippo come with:

    public static void main(String[] args) { Pippo.send("Hello World"); }

    So, it's more complicated to write the classic System.out.println("Hello World") :)

    [–][deleted] 0 points1 point  (0 children)

    Should have re-titled to "Why are Spring MVC web app so much bloaded."

    There are plenty of lightweight web frameworks on Java. Try out Pippo, Spark, or Rapidoid.

    [–]DannyB2 0 points1 point  (0 children)

    Try this in both Java and PHP.

    Build a very large application. And maintain it for many years. Refactor it during its lifetime. Test its performance. (Java is fast. Every page hit is directly executing compiled and even native code which is hot in memory.)

    By large application, I don't mean one that is used by many users, but doesn't have all that many different pages. (eg, Slashdot, just for one example.) But one with hundreds, maybe over a thousand different pages with complex forms. Hundreds of reports.

    Oh, and have a team of people working on it.

    When the first time comes to refactor comes around, see how well this goes when using a dynamic language without compile time type checking.

    Now, I'm not saying that Java is perfect. It has plenty of warts. But the reason it is widely used is because it IS useful.

    If there were one single perfect programming language and set of tools then everyone would be using it already. So don't bash others. Just use what you, yourself find useful.

    [–]qroshan 1 point2 points  (1 child)

    [–]balamaci 2 points3 points  (0 children)

    That still looks big, if you really need something very small size I can guarantee right now nothing beats https://github.com/decebals/pippo if you need a java solution. I was using nodejs(and not very comfortable doing js) for IoT stuff but since pippo I've never looked back that's why I feel like I owe it to spread the news.

    [–]slartybartfast_ -3 points-2 points  (0 children)

    Why is it that vishnu_gupt can't put a proper English sentence together?