31
Cyanite
7y

I have Java 8 installed on both Windows10 and Ubuntu16

My (basic) app compiles fine in windows with javac, and when put into a jar works perfectly. But when cloned to my Ubuntu, javac fails to compile, and the jar fails to run.

Comments
  • 3
    I can't solve your problems but nice tags.
    Google is your friend (not really though) use it.
  • 0
    @treeroot
    Lol thanks. ^~^
  • 10
    check the Java version in Ubuntu, my guess you are using OpenJDK and not Oracle Java
  • 1
    @elgringo
    It was OpenJDK. I didn't know there was a difference. That's just what came pre-loaded.
  • 3
    Mcdonalds is always hiring. I keep asking that many times per month too. You.re safe
  • 2
    If you are using JavaFX, you have to install the OpenJFX package. For some reason it isn't part of the normal OpenJDK installation.
  • 0
    @elgringo
    How does one propperly install jre/jdk.. I tried tar, but it seems that I have to cd into the install dir to run the files.
  • 3
    @Cyanite I'm quite sure that you don't need to use the Oracle JDK. There are only minor differences and even those are mostly licensing and some other stuff only relevant in certain business environments. However, you aren't doing yourself any favours by manually installing some Java version and circumventing the whole package management system.
    If you really think you need the Oracle JDK (which I'm quite sure you don't), you can use the oracle-java8-installer package (there is a PPA for it).
  • 1
    @3141
    All I know is when i used the Oracle jre, the jar ran perfectly. Unlike with then Openjre even know they were both Java8
  • 0
    @Cyanite What exactly is the error message? And are you using JavaFX?
  • 1
    @3141
    It couldn't find my main class within my jar.

    With javac, any import that contained a * didn't work.

    And yes. Most of my code is JavaFX
  • 0
    @Cyanite
    sudo apt install openjfx
    should fix the problem with compiling. I guess the * imports don't work, because JavaFX is missing.
    The main class thing sounds like the main class isn't specified in the manifest. How are you building the jar?
  • 0
    @3141
    The jar works fine with the oracle java.

    I use:
    jar -cfve build.jar application.TestApp application/ src/ *.css *.jpg

    Edit:
    application/ contains the *.class files for two files of my application package.
    src/ just contains the *.java files, and a LICENSE file.
  • 2
    :facepalm:. native depenendencies for the fail. make sure you have the required .so files.
  • 1
    @Cyanite I just tried to replicate the exact problem. Apparently, not having openjfx installed, causes a jar using JavaFX to fail with the error message: "Error: Could not find or load main class"
    I assume that the problem isn't the finding part, but rather the loading (since your main class tries to import JavaFX, but it doesn't exist on your system).
    So just install openjfx and it will work.
  • 0
  • 0
    @3141
    I know that now.
    I'll need to figure something out..
  • 0
    @Cyanite missing natives is not the problem. take a look at the build logs for clues.
  • 0
    @Cyanite I don't understand. What exactly do you need to figure out?
  • 1
    @3141
    Well, if it's this complicated for me trying to run the damn jar.. Then end users are also going to have problems. So I need a work around.
  • 0
    @magicMirror
    I know exactly what the problem is thanks to @3141, I just need a permanent solution so this doesn't bother end users.
  • 5
    @Cyanite The easiest way would be to ship a bundled JRE. JavaFX offers a relatively easy way to do this via the javafx-maven-plugin. The build-native goal creates native packages (e.g. deb or rpm, or simply a folder containing the app) that can be run without having to install any Java related stuff on the target system.
    It does require some configuration effort, but I think something like this would be the best solution to your problem.
  • 0
    @Dav13 That answer is wrong on so many levels. I don't even know where to start…
  • 0
    @Dav13 That was about manually installing the Oracle JDK. There is literally no connection to any Windows environment variables.
  • 0
    @Dav13 @3141
    Adding the folder to path is actually what I might end up doing, but I'd rather find an alternative.
  • 1
    @Cyanite what about the bundled jre?
  • 1
    @jpichardo
    It's too early for that, also this is a private build. These commands that I actually use to compile and test my code.

    Though I will do that with public builds.
  • 1
    @Cyanite good, anyhow, you should consider using maven it'll ease the build, testing and deploying phase :);
  • 1
    @jpichardo i'd love to, if you will show me how.
  • 1
    @Cyanite are you using any ide?
  • 1
    @jpichardo
    For building? No. I use command scripts. Personal preference. I can change them on the fly very simply. I like to work from the terminal and having my scripts ready is a huge help.
  • 2
    @Cyanite good, well the you should check this: https://maven.apache.org/guides/...

    It explains how to configure a basic Maven project and in the Pom you can configure the steps, which is really useful
  • 0
    If you're using Ubuntu (or any distro with apt) you can use the apt made by webupd8team.
    They download the jdk from Oracle server itself, and I've read the installer source, no funny business :)
    This link is old, but it works. Just recently installed it on zesty based GNOME
    http://webupd8.org/2012/09/...

    Gud luck :)
Add Comment