dimanche 28 décembre 2014

Error upon execution of JDK 8 java class file: "Error: Could not find or load main class in TicTacToeRandom"


Vote count:

0




I've been trying all sorts of stuff for quite some time now. I'm trying to run java applications from the terminal in Linux Mint. I think it may be related to two different java installations.


I began doing tutorials with JDK 7 and an old Eclipse build, but had to upgrade both to JDK 8 and Eclipse 4.4.4 for javafx, and in the process I went from using a folder called Java to a folder called Java2. Everything in the Java folder will run from the terminal, but nothing in the Java2 folder will.


The error boils down to this:


This works:



dalsgaard@dalsgaard $ pwd
/home/dalsgaard/Skrivebord/Java/tutorials/bin
dalsgaard@dalsgaard $ java Welcome
Hej med dig!


This does not:



dalsgaard@dalsgaard $ pwd
/home/dalsgaard/Skrivebord/Java2/tutorials/bin/application
dalsgaard@dalsgaard $ java helloWorld
Error: Could not find or load main class helloWorld


As you can see, I have a main class:



package application;

public class helloWorld {

public static void main(String[] args) {
System.out.println("Hello StackOverflow!");

}

}


I have tried the following:



dalsgaard@dalsgaard $ javapackager -createjar -appclass Application.TicTacToeRandom -outdir . -outfile outjar -srcdir . -v
dalsgaard@dalsgaard $ java -jar outjar.jar
Error: Could not find or load main class Application.TicTacToeRandom
dalsgaard@dalsgaard $


It compiles no problem, and javapackager finds all the right files! I still think it may be related to classpath issue and workspaces, though it doesn't make any sense to me. Since all I get when I echo $CLASSPATH is a blank line, I have tried to specify the path directly, but that doesn't work either:



dalsgaard@dalsgaard $ java -cp /home/dalsgaard/Skrivebord/Java2/ helloWorld
Error: Could not find or load main class helloWorld


Also, why would it give a "no main class" error, if classpath was the problem? In any case, I've tried compiling and running directly within the workspace folder too:



dalsgaard@dalsgaard $ pwd
/home/dalsgaard/Skrivebord/Java2/TicTacToeRandom
dalsgaard@dalsgaard $ java TicTacToeRandom
Error: Could not find or load main class TicTacToeRandom


That doesn't work either. Java version, linux version, etc:



dalsgaard@dalsgaard $ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
dalsgaard@dalsgaard $ uname -a
Linux dalsgaard 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux


asked 1 min ago







Error upon execution of JDK 8 java class file: "Error: Could not find or load main class in TicTacToeRandom"

Aucun commentaire:

Enregistrer un commentaire