Creating an Executable JAR for Unix and Linux

Published at 20:46 on 21 March 2022

One of the annoying things about any JVM language is that to run the result of compiling your code, you have to type something like:

java -cp somefile.jar domain.name.name2.SomeClass arg1 arg2 …

Or at best:

java -jar somefile.jar arg1 arg2 …

Wouldn’t it be great if you could just type the command name followed by arguments, like you can do with a compiled C or C++ program? The normal way to do this is to write a shell script and make it executable, but this is a tad clunky (now there are two files, the shell script and the JAR that it invokes). It would be nicer to have just a single executable.

Well, you can!

echo "#!/usr/bin/env java -jar" > somename
cat somefile.jar >> somename
chmod +x somename

And that is it! You now have an executable binary that is an archive of Java bytecode instead of native machine code. (Of course, it requires a suitable java interpreter to exist on your PATH.)

Best of all, while all of this sounds hackish, it is not just luck that a JAR file with some leading junk tacked on to it is still treated as a valid JAR file. No, this is basically guaranteed to work. You see, JAR files contain their header data at the end, not the beginning, and Java simply ignores all data earlier than what is described in the header.

And since the Macintosh is just a UNIX system under the hood, this trick works for Macs.

The War is Unpopular in Russia

Published at 10:19 on 12 March 2022

Some people are claiming Russians support Putin’s war, citing polling data to back this up, but let’s think about what those polls are saying for a moment in the broader political context.

That context is the polling taking place in a country with basically no freedom of expression, a country where opposition media is banned, a country where peaceful protesters are arrested and tortured, a country where people are randomly accosted by police on the street so that messages on their smartphones can be checked for anti-Putin sentiments.

Imagine that you are a Russian. You know the risks involved in opposing the government. A random stranger approaches you on the street, or calls your phone, and claims to be an opinion researcher. S/he asks you if you support or oppose the most significant policy the government is currently engaged in. For all you know, he or she may in fact be a member of the FSB, Putin’s secret police. How do you answer?

It’s pretty obvious that all answers to any poll about issues of consequence in a country like Russia are answers given under significant duress.

As such, anything less than overwhelming support for the government is basically meaningless for purposes of concluding actual support. By “overwhelming” I mean 95% at minimum. Lukewarm support in the 60–70% range probably means significant overall opposition to the issue being polled about (and is probably as opposition-y as one can reasonably hope to see).

And the actual level of professed support for Putin’s war shown in that poll is… 58%!

Mark my words, the “majority” opinion expressed in that poll says the exact opposite of what a majority says in more normal circumstances.

What is the Endgame?

Published at 08:22 on 10 March 2022

That is easy: Russian forces slink back across the border in defeat and leave Ukraine, much like they did some decades earlier with respect to Afghanistan.

How do we get there? Most likely, same way we got to the Afghanistan endgame: a long, brutal, bloody process that the Russians eventually tire of.

It’s all genuinely horrible, particularly for the people of Ukraine.

The only practical alternative, because we can only control our reaction to Putin and not Putin himself, is to relax the sanctions, stop aid to Ukraine, and let Putin have what he wants. Of course, that teaches Putin the lesson, par excellence, that he can get away with grabbing whatever he wants, because the West really is weak and timid and will just let him have it. It is, after all, precisely what Putin learned from the generally non-confrontational responses to his invasions of Crimea and Donbas. And that, in turn, merely paves the way to even worse bloodshed later.

Well, there is also the alternative of dramatic escalation, i.e. entering the conflict and having NATO face Russia directly. In other words, World War III. We have seen over the past two weeks the quality of the Russian military, so it is pretty clear that Russia would start losing such a war, badly. At that point Russia will turn to its nuclear arsenal, and we all know where things end up from there. Note that a no-fly zone is such an escalation, because it will result in NATO shooting down Russian planes.

So the only other class of alternative is so dramatically worse than the other alternatives, that no sane person would want to consider it. This is why even hard-headed military types like the head of NATO want nothing to do with a no-fly zone in Ukraine.

This lack of any good response, and the resulting certainty of a period of prolonged bloodshed and suffering, is in fact what upset me the most when I heard the news that Putin had launched a full-scale invasion. When I have talked earlier about the responses being as good as I could have imagined, I meant they were so given the overall circumstances, which are pretty bleak.

So make no mistake: what the West is doing is definitely going to prolong an already bloody war, and guarantee a huge amount of civilian deaths and utter destruction for the infrastructure of Ukraine, and cause no shortage of misery throughout Russia as well. Yet it is simultaneously the best response possible.

And that is the real tragedy of the current situation.

Freedom Fries All over Again

Published at 20:12 on 9 March 2022

People are talking about cutting Russia off from the Internet entirely. Talk about a special kind of stupid: we should want Russians to be able to easily access information from outside Russia. Sure, this means cutting deals with Russian Internet providers. So be it. The goal is to undermine Putin by weakening the economy that supports his war. It is not to isolate Russia completely. Providing accurate information to Russians about what their dictator is doing also helps undermine his regime.

Russian pianists are being banned from international competitions, not because of anything they personally did, but simply because they are Russian. Even Russian cats are being banned from cat shows. I guess some people think the cats voted for Putin in the last election.

Worse yet, here in North America, Russian restaurants are being boycotted and vandalized, even ones whose owners publicly oppose the war in the Ukraine and have organized benefits for the people of Ukraine. Because it doesn’t matter. They are of Russian ancestry, or exhibiting aspects of Russian culture, and therefore they are evil.

Frankly, this is freedom fries all over again. Yes, Putin is a dictator. Yes, he needs to be taught a lesson, lest he keep trying take neighbouring nations over. But there is standing firm against a dictator, and then there is Russophobia. The two are not one and the same.

So It’s Getting Real, Now What?

Published at 19:46 on 8 March 2022

Well, that didn’t take long, did it? The USA is boycotting Russian oil. The obvious conclusion is that this will just make the price of anything made from petroleum go up more.

At this stage it is worth keeping in mind how the US public reacted to the COVID pandemic. How likely are the people who couldn’t unite around wearing masks during a pandemic (to protect themselves and their own families) to unite around making some rather more expensive sacrifices (on the behalf of some other people many thousands of miles away in eastern Europe)? Not very likely, I’d say.

A Democratic president facing rising unpopularity due to rising inflation, in no small part due to rising energy costs. Welcome to the 1970’s. It’s looking more and more like Biden is a latter-day Jimmy Carter.

The one good thing about it all is that gasoline is finally starting to be priced rationally again. (When you hear random people, and not eco-activists, talking about doing things that minimize their carbon footprint, you know gasoline is being priced rationally, i.e. to encourage conservation.)

And yes, I know this is going to cause some folks genuine hardship. Based on personal experience, though, a lot of that is up to personal choices. For openers, it has always struck me how casual most people are about choosing to live in one place, work in another distant from it (with limited or no public transit options), and thereby commit to a lot of fuel consumption.

It Gets Real when Russia Turns off the Gas

Published at 22:30 on 7 March 2022

Europe is so addicted to Russian oil and gas, and Russia is so addicted to their last significant remaining export industry, that there is still a booming trade in fossil fuel exports from Russia to the rest of Europe. Yes, now, even with the sanctions.

That’s unlikely to last. Eventually, one side will decide to punish the other by cutting the flow off. Odds may well favour it being Russia that turns the taps off, for the simple reason that their authoritarian system means public opinion matters less.

Then comes the time of real sacrifice, when it actually will feel like a war. In World Wars I and II, there was widespread rationing in all belligerent nations. That has not been the case in the West for any conflict since.

Those of us in North America will be less profoundly affected, but we will still be affected. It is a global market, so a loss of supply anywhere will be reflected everywhere.

At that point, the question will be whether the public will be willing to put up with the sacrifice. How difficult it was to get people to cooperate during the COVID pandemic does not instill much optimism here. Perhaps this time will be different, but that is merely a vague hope.

And yes, that question applies in Russia, too. Even authoritarian systems depend ultimately on public support, and a sudden decline in the standard of living is an effective way to lose that support. Just ask General Suharto.

Three Items Re: Ukraine

Published at 07:49 on 6 March 2022

Was This All Intentional?

We are starting to see rumours circulate about the West quietly shoveling aid at Ukraine in the months before the invasion. During this same time, of course, the government of Ukraine was seriously playing down the possibility of invasion. This begs the question: was it all a deliberate trap for Russia? Did the West want Russia to invade, so Russia would get bogged down and humiliated, and such did the West deliberately provoke the invasion?

First such questions are not unaskable. We are dealing with empires here. Would an empire be willing to sacrifice a whole nation upon the pyre of greater power? Of course it would. As I have observed before, all empires are evil.

However, just because in general a certain class of question is quite plausible to ask, does not automatically mean that an affirmative answer is the only possible one. In this case, the question is coming from an obscure web site I had never heard of before. More damningly, when I type in quotes from the alleged Washington Post article it refers to, there are no matches in the Washington Post. When it comes to this particular accusation, there is no there there.

More generally, suppose there was a conspiracy. It would be a fairly big operation. Lots of people in both the US and the Ukranian military would have to be involved in the transfer of aid. NATO partners might also have to be involved. Some of these people would lean left politically and be easily able to see the crass power calculus of it. Some would lean right politically and be easily able to see it from Putin’s side. Many would be Ukrainian, and their good old fashioned nationalism and concern for the friends and family they were putting at risk would get in the way.

The upshot is that there would be whistleblowers, and they would name names and cite facts in ways that made it clear their accusations were factual. Yet, there have been no whistleblowers. Absent that, therefore, the only logical conclusion is: no, this was not all orchestrated by the West.

Beware Both-Sides-Ism

Just because all empires are evil does not mean that all empires are equally or indiscernibly evil. The Russian position is that Ukraine has no right to choose its political system or its military alliances, because anything other than authoritarian protectorate within a Greater Russia is unacceptable. The NATO position is that Ukraine really should choose to be a Western-style liberal democracy and if it does is probably welcome to eventually become a member of its club.

One empire’s stance is distinctly better for the liberty of the people of Ukraine than the other empire’s stance. If you cannot realize that, you are simply not paying attention.

More practically, there is now a war on. The NATO countries, and those closest to NATO’s orbit, are the ones willing to furnish military aid to Ukraine. Nobody else is willing to do so in any significant amount. Ukraine desperately needs the aid in order to punish the Putin regime.

As such, yes, I will support NATO. Not because it’s NATO and NATO can do no wrong, but because in this case, NATO is on the right side of my own personal principles of greater freedom. The average NATO country is a much better place for liberty than the average country in Russia’s orbit. Again, if you can’t realize all of that, you are simply not paying attention.

Putin’s Phases of Grief

This latter one is telling. Even Putin is not thumping his chest and boasting about his army’s glorious victory. No, he is alternating in between ranting at the West for sanctioning Russia, and pleading with the West to pretty please stop sanctioning him. In other words, even Putin himself is publicly admitting that the sanctions are hitting him where it hurts.

Here are the five stages of grief:

  1. Denial,
  2. Anger,
  3. Bargaining,
  4. Depression,
  5. Acceptance.

Well, this is not taking long. Putin seems to be working his way through steps 2 and 3 in the process. Want Russia out of Ukraine? Keep calm, and stay the course.

More Chill Pills, Please

Published at 08:53 on 3 March 2022

OK, the first round of sanctions is in place. Can we step back and assess for a moment.?

Face it, Russia is not leaving Ukraine tomorrow. Or next week. We don’t get to decide when Russia leaves. Russia’s leader does, and right now that leader is Putin and Putin wants to stay in. That sucks, but that’s also the way it is and it’s not going to change overnight, sorry.

“But this is unfair to the people of Ukraine!” Yes, it is unfair. Monstrously unfair. You think a nuclear war between the USA and Russia would be more fair? Go watch Threads and get back to me on that one. Sometimes there are no good options, only really bad and less-bad ones. This is one of those times.

What has been done in response so far is about as good as one could realistically expect to have been done. In international politics, that is close to a miracle.

To reiterate, now is the time to step back and assess.

For openers, hit the pause button on ideas like blocking all Russian addresses from the Apple app store. New sales of iPhones have been banned. What’s been sold in Russia cannot magically be unsold. Given that the phones are already there, might not it be useful to have some way of getting apps to them? Apps for things like secure, encrypted messaging that cannot be spied on by the increasingly repressive Russian government? Security updates for such apps already installed in Russia? Or how about an OS update that makes it easier to jailbreak Apple phones, in case Russia cuts off access to the Apple store and tries to control what apps its citizens can run?

If, on later reflection, there is a solid, strong argument for cutting off all access, an argument stronger than any compelling argument for maintaining access, then by all means cut it off. But do the reflection first.

Of Offramps and Legacies

Published at 08:10 on 3 March 2022

One of my theories is that Putin is doing this simply because he is a fascist. Like all fascist leaders, he wants to rebuild the nation he leads to some imagined past era or lost greatness, and he believes this is a task that he himself is uniquely qualified to perform.

He had a much more practical formula for rebuilding the Russian empire of old, and it was working: the play-it-slow approach. The world was letting him get away with whittling off chunks of neighbouring countries. This worked before, too: the Russian Empire of old was built incrementally, over centuries.

But there was a huge problem for Putin. He is 69 years old. Time was (and is) running out for him to complete what he sees as his historic mission. Circumstances left him no choice: either dramatically speed up the pace, or give up on a cherished goal. For the past 20 years, he has gotten basically everything he wanted, and he has increasingly become isolated from reality and surrounded by yes-men, so of course he chose the former option.

If true, this means two things.

  1. Danger. He’s an old man with nothing to lose. (Who knows, he might even have recently been diagnosed with a terminal condition.) In his mind he has to complete his historic mission. He will risk a nuclear holocaust to do it. It will mean failure for him if it happens, but this would be no worse in his mind than dying without a nuclear holocaust and without having rebuilt a Russian empire. Either way, he will be dead and will have failed in his historic mission.
  2. He won’t take any offramps. Again, only one thing is acceptable to him and he is running out of time to accomplish it. Offering Putin offramps is likely to be pointless.

Instead, focus on offering Russia offramps, not Putin. Do things that encourage Putin’s overthrow. Attacking the Russian economy and in particular the foreign assets of the oligarch class is one such thing.

Putin’s claim to fame, the source of his popularity, is that he may be a corrupt authoritarian but at least the economy has grown and been relatively stable under his rule. During the Tsarist era, Russia was a backward outpost of feudalism. The Soviet Era was characterized by significant economic progress, but also significant economic chaos (there were literal famines), followed by a long period of stagnation, shortages, and decline. The immediate post-Soviet era featured an economic crash. The Putin era has been the most prosperous time in all of Russian history.

It is often the case that people will put up with a dictator as long as the economy continues growing. Taking away this trump card of a dictator can lead to his downfall. It happened to Suharto in Indonesia. Make it happen to Putin in Russia.

Suppose all of the above is wrong. Suppose Putin isn’t that crazy. In that case, Putin will take the offramp we offer to Russia. He will realize the source of his power, and act to try to avoid the fate other dictators in his situation. He will declare Ukraine “de-Nazified” by a “successful” mission and withdraw his troops.

Either way, offering Russia (and not just Putin) an offramp is the way to move forward.

Keyboard Warriors Need to take a Chill Pill

Published at 06:20 on 1 March 2022

Yes, there is a big, scary Russian convoy working its way to Kyiv.

No, NATO should not bomb it.

It’s sort of shocking I have to say it, but Twitter is full of idiots advocating just that, even though it is a direct violation of one of the unwritten rules of avoiding World War III: nuclear-armed powers should never directly fight each other.

The same goes for a no-fly zone. That also should be permanently off the table, for the same reason. Any NFZ would have to be enforced, and that would mean a direct military confrontation between NATO and Russian aircraft.

Also, Ukraine should not get express special-treatment entry into the EU just because they asked for it. Full EU membership is a long process (Turkey is still going through it, after decades.) It’s that way for a reason: it’s a very tight integrating of economies, and nations should be reluctant to do that unless all parties are certain they are compatible.

The EU is right now having no shortage of dealing with headaches involving Poland and Hungary, both of which have right-wing governments that are backsliding into authoritarianism and kleptocracy. Both were welcomed into the EU, and in hindsight this welcome seems to have been too hasty. Let’s not repeat that error.

Ukraine is not a first-world democracy. Its prewar GDP per capita is roughly ⅓ of Russia’s. That’s less than Bulgaria, currently the poorest EU member state. It’s Transparency International corruption perceptions index is 32, less than the Philippines and only one notch above Mexico. The Azov Battalion is not just Russian propaganda; Ukraine really does have a neo-Nazi regiment in its military. (Putin’s “de-Nazification” pretext was chosen for a reason; the best pretexts do generally have some truth to them.)

None of this means that Ukraine shouldn’t be helped. None of this means that Putin is not himself the worst fascist on the world stage, and that the problem he poses won’t only get worse if his regime is not made to pay for what it is doing in Ukraine. It just means that this must be done realistically.

Another place where we must be realistic is realizing, as I wrote earlier, that Russia (by virtue of multiple poor decisions on their part) is partly responsible for Ukraine’s success up to now, and that the Russians are almost certain to correct some of those errors and start faring better as a result. It still would be no big surprise if Russia ends up occupying Kyiv and most of the rest of Ukrainian territory.

That matters less in the long run than most keyboard warriors might think, because an outgunned insurgency can (and has many times in history) worn down a militarily superior occupying force over time. But the same well-meaning but ignorant individuals talking about NATO bombing Russian convoys probably aren’t aware of that, either.

Being realistic is always the best policy.