Hacker News new | past | comments | ask | show | jobs | submit login

Lightweight Java has always been a thing for those who appreciate Java-the-language but despise Java-the-ecosystem.

You don't need to fool with Gradle or Maven or Ant if you'd like to incorporate third-party or your own custom dependencies in single-file "Java scripts".

Just copy some .jar files into ~/lib, and in your `.bashrc`:

  export CLASSPATH=~/lib;$CLASSPATH



I use Java extensively for my personal work and never use Gradle/Maven/Ant. I run Python scripts that marshal javac and java calls, it works great. I do cute tab completion tricks that examine the class layout and extend based on what it finds. I even have a "SmartCompJava" script that finds .java files that have newer modtimes than their corresponding .class files and just compiles them - a bit dangerous if you're not careful, but it's super-fast!


Ah.. the old days of java programming - set up your CLASSPATH and done.. Nowadays; however, most libraries have tons on other dependencies and doing this manually is tedious and a pain in the neck - download the wrong version of the dependency, and you are in for a rabbit-hole trying to figure out the compilation errors. Do not get me wrong, Maven is ugly and disgusting(so are the other dependency managers for java), but gone are the days of CLASSPATH.. unless you avoid using libraries bloated 3rd part libraries at any cost.


If you like to have most of the simplicity of just setting classpath, but still have convenient dependency resolution, I highly recommend checkig out coursier: https://get-coursier.io/

Its a cli based artifact fetching tool for the JVM ecosystem, and you can have it just make up classpath strings for you, i.e., to use some Apache dependencies with the single file simplified java running you could just:

java --enable-preview --class-path (cs fetch --classpath org.apache.commons:commons-collections4:4.4) program.java

Also, maybe do have a look at scala-cli: https://scala-cli.virtuslab.org/ It does work just fine with Java files, and allows you to write single-file programs that include dependencies as special comments. The tool has some idiosyncrasies (like a background compiler server), but overall works extremely well if you need some of the power of a build tool, but without having a complex project structure.


Also, see this project that is in a similar space as Coursier:

https://github.com/bowbahdoe/jresolve-cli

https://github.com/bowbahdoe/jresolve


>Lightweight Java has always been a thing for those who appreciate Java-the-language but despise Java-the-ecosystem.

I always disliked Java until I was converted by some developers of that group in a past job. I suppose it is fair to judge a language by the overall flavour of its ecosystem, but it is a bit disappointing. I wish more people could see how simple and _good_ it can be when you use the JDK itself, and not go through other overcomplicated systems to use it. For example, Spring Boot is basically a massive pile of hacks (regardless of whether you consider it good or bad), and Java only really serves as an underlying support technology for it.


java -cp .:* OneOffTestCase.class




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: