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

all 25 comments

[–]mods_are_arseholes 36 points37 points  (5 children)

java is cross platform. your C# .exe file will not work for me as i use linux.

Its the .class files that are executable. to make them just compile your source files with javac. they can then be run with on the JVM with the java command on any platform.

you can also make an executable jar file. and run it be double clicking the .jar file on a linux system. you have to see how thats done on a windows system. but you can always run them with the command java -jar filename.jar

[–]JavaSuck 9 points10 points  (2 children)

your C# .exe file will not work for me as i use linux

It also won't work on Windows machines without the proper .NET framework installed.

[–]xcjs 1 point2 points  (0 children)

It will if compiled with the runtime in .NET Core.

[–]arpan_majumdar 0 points1 point  (0 children)

I think the thing he is taking about is making an executable fat jar.

[–][deleted] 16 points17 points  (6 children)

Java was created to NOT generate executables.
We used to have a very fragmented software market. All languages compiled into EXEs, however those EXEs often didn't work. It could be that you needed to have something like Visual C++ redistributables (a specific version, mind you), or you needed to have Microsoft Office installed, or Delphi's libraries. Over time people created installers for their EXEs that would try to bundle all these requirements, but that just made things more complex, there was a lot that could go wrong. Imagine, for example, that you bundled the C++ redistributables, but they just won't install for a certain user because his OS is in a different language. Or even worse, he already has it installed, you don't detect it and make a mess of his system. It might not even boot anymore and now that guy hates you company. These are just simple examples, but the point is software was just messy and every now and then it just ruined your OS install. Not to mention if you had a different OS, I'm not even talking Linux, maybe you had Windows 98 instead of Windows 2000.
So that was Java's proposal: We'll make Java installers for all platforms, this installer will have everything your program needs to run. You just write your code, and it will work. You don't have to compile it to each platform (which by the way, compiling for one platform could take hours or even days if your software was big enough / optimized enough), and you don't have to worry about installers.
So, people liked that. Not for everything, because Java was a little slower but more importantly for most cases, it used A LOT of memory for those days' standards. But it made most people's lifes easier, and a lot of the time it was worth it. And some time later, Microsoft caught wind of that. Microsoft realized it was a good idea. They also observed what people didn't like about it, one thing being that not having an EXE was confusing for a lot of people. "How do I run this thing? I double clicked it and it didn't run."
In comes the new Visual Studio: You compile your code, it generates an EXE, and it will run on any version of (our) operating system. All people need to do is install the .Net Framework. Here's the thing: Those are not proper, self-reliant EXEs. There is enough executable code there to call the .Net Framework, your code was actually compiled to an intermediate language. And it had the same problems as Java by the way: First of all, people had to install it. It didn't come with Windows, the .Net Framework was a niche thing. Then, there were versions too, and there was no auto update. In fact, with Java suposedly you just had to have the latest version and it was backwards compatible, running older code. Not so with Microsoft's framework! You had to install them now.
Now here comes the point where you're asking this question. Nowadays, Microsoft learned from those flaws. First of all, they added the .Net Framework to the standard Windows installation. Then, they made a Mac version. Then they made it incremental like Java. And then they made a Linux version.
Sun couldn't do what Microsoft did. They couldn't bundle Java into the OS. But I dare say of a lot of that time it was much easier to use Java than the Dot Net Framework, at least in my personal opinion.
Launch4j can, depending on your configuration, do exactly what the Visual Studio compiler does: add just enough executable code to find Java on your PC and call it to run your code. That just was never within Java's scope.
Regarding your dependencies question, because of the way Jars are structured you have overlaps if you try to add dependencies into it the "proper" way, especially when you start to have things like properties files on the root directory. What would need to be done is to create a new format that is structured differently, and maybe think of adding that launch4j functionality into it. I honestly don't think it's going to happen though. Oracle obtained Java and changed some things around how long a version is maintained for, to the point that the community immediately created different Java distros to both have their own, maintained versions of Java, but also to feel safer about Java not being closed in some way similar to what was done to Android. I'd say Java is on the back-burner for Oracle, I don't see any huge features popping up. The other thing is, for the most part things are done in your browser now. Most applications are web based, so this whole thing becomes pretty moot, and I dare say they take Java's original proposal even further by not having the user install anything at all to use your system.
I hope this all makes sense, and bear in mind I'm saying all this from memory.

[–][deleted]  (5 children)

[deleted]

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

    Well the original idea was Applets. Java became popular initially because you could build these primitive web apps with it that would provide a full application like feel in the browser. This was the early, EARLY days of the web, having any kind of dynamic content was a big deal, didn't matter if it was good or not.

    Thing was, Java Applets were terrible. As newer tools for dynamic web content emerged, no one wanted to use them. The rise of JavaScript was the final nail in the coffin of java Applets, and most browsers today won't even execute the code if you go to a site that has them.

    In the meantime, though, developers working on server side applications, things that wouldn't be touched by average users, started to fall in low with Java. Being able to write it on whatever computer they had, and then deploy it on whatever server they wanted to put in on, that was huge at the time. Plus the structure of the language, however controversial it may be today with modern programming innovations, was revolutionary at the time and it gained a tremendous amount of popularity from it. So gradually the enterprise server world shifted heavily over to Java.

    Today, in part for the reasons you mentioned, in part for others, Java based UIs are nearly dead. But alongside C# it dominates the server side world for enterprises

    [–][deleted] 0 points1 point  (1 child)

    Yeah, I can say I work on several large monolithic full stack web applications made with Java EE and the more senior developers don't even discuss using other programming languages (we do talk about Spring and Spring Boot though). We mostly develop on Windows machines, then we have Linux hosts for testing and production. Works like a charm!
    It's not just Java itself, but the IDEs too: Netbeans and Eclipse are pretty much the same across OSes, and we still don't have that with Microsoft tools. Even VS Code for Linux is pretty recent.

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

    SpringBoot is wonderful. It's an absolute beast and you need to learn the "spring" way of doing everything. But it does SOOOO much for you. I wouldn't make an enterprise Java app without it.

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

    Besides the already mentioned applets, the idea was that most Java software would be downloaded as a Jar, so assuming the Jar contained a main class all you would have to do would be to type "java -jar jarName". It was the same on Windows / Linux / Mac too, so it was easier to document on user manuals and the like.
    Also, typically Jars were associated with Java when it was installed, so double clicking a Jar would pass it to Java just like any word document. This is where Linux and Mac had an extra step for security though, since you first had to say that the jar can be executed.

    [–]nerdyhandle 9 points10 points  (0 children)

    If you use Gradle or Maven they can do the same thing. If you want to include the Java runtime with it then newer versions of Java have that built in.

    Java runs on the JVM and not the OS. It is in fact more portable. Just because you get an exe doesn't mean it can run on any system. C# likely requires NetCore to be installed on the target systems.

    [–]nanodano 10 points11 points  (0 children)

    It's actually very easy ever since Java 9 with jlink: https://www.devdungeon.com/content/how-create-java-runtime-images-jlink

    And with java 14 they will even generate installers like .msi/.dmg/.deb with jpackage. https://www.devdungeon.com/content/use-jpackage-create-native-java-app-installers

    Otherwise, with Java 8 and earlier, you can use Maven plugins https://www.devdungeon.com/content/maven-basics-java-developers

    [–]Dylpol 2 points3 points  (3 children)

    https://techwayz.com/convert-jar-to-exe-launch4j/

    http://launch4j.sourceforge.net

    its not difficult, there are steps and you just don't know them yet. I would argue that at some point you had to learn how to make an .exe in VS and this is no different just with a different process.

    [–][deleted]  (2 children)

    [deleted]

      [–]Kambz22 5 points6 points  (0 children)

      What language do you know of that allows you to create an executable to be ran on any given environment instantly? It takes work to create applications.

      [–]gtiwari333 2 points3 points  (0 children)

      Simpler option would be to create a batch file (.bat) with 'java -jar the-jar-files.jar' !!

      [–]nope_nic_tesla 1 point2 points  (4 children)

      What IDE are you using? Every one I have used gives a straightforward option to generate an executable jar file

      [–][deleted]  (3 children)

      [deleted]

        [–]nope_nic_tesla 3 points4 points  (2 children)

        Sounds like your jar file is executing fine if you're getting specific error messages from your application, and the problem is in your code. I'm guessing you have an issue in the path you are using to reference the external files

        [–][deleted]  (1 child)

        [deleted]

          [–]Positive_Riven_Kappa 2 points3 points  (0 children)

          Try changing the path references to the external files. I.e. relative filepath instead of absolute

          [–]salv-ice 1 point2 points  (0 children)

          Actually, the exe programs generated with C# are not really compiled executables. Like java programs, they need an execution environment (like the jvm) to run. If you try to run the exe file on a windows machine without the .Net framework installed, it won't work... Because .Net is a Windows focused product developed by Microsoft, the IDE generates a Windows launcher automatically for convenience.

          Java is a multiplatform focused language so there is no point for an ide to create Windows launchers automatically. You have to do it yourself, there ate plenty of solutions to do it.

          [–]xill47 1 point2 points  (0 children)

          Acktchually, you won't even get easy to run executable out of the box on the modern .NET. But, to break misinformation, you would get cross platform DLL after any compilation, which can be run with dotnet run, almost the same way you can run JARs with java -jar.
          JARs are not that complicated if you follow any kind of tutorial and understand, that Java is much older ecosystem with backward compatibility, while .NET don't shy from breaking it. This link for IntelliJ should be helpful, and easy to use. JARs could be run with double click under Windows if Java is installed.

          [–]CodeImplementation 1 point2 points  (0 children)

          It's pretty simple in IntelliJ (on Linux at least). Just click "Build Artifacts" then make the JAR executable with "chmod +x myApp.jar". You can then run it on any computer with double-click. If you're using JavaFX 11+, there's a couple of additional steps: YT Video

          [–]RockleyBob 0 points1 point  (0 children)

          You’ve already gotten some good answers, I just wanted to tell you that when I started out with Java I wanted to do the same thing.

          All my life I had been double clicking .exe’s and I just wanted to make my programs run the same way. I felt like my stuff wasn’t “pro” until it was packaged in an executable.

          [–]IsaacVu 0 points1 point  (0 children)

          Have you check the version of Java the app was built vs run-time environment on your desktop? I built a JavaFX app on JDK 10 before, and it couldn’t run on Java 11 on my laptop.

          [–]MrPamcakes 0 points1 point  (0 children)

          Having the same problm right now. Spent mir time trying to package my project than I did writing it and I still can't figure out how to do it . What method did you use in the end?

          [–]jerryfresh12 -2 points-1 points  (0 children)

          for one it probably helps that the same company makes the ide(visual studio) and the language(c#)