mafioso mafioso - 2 months ago 7
Java Question

Compiling java class with javac doesn't work

I want to compile my java class like that:

javac ResultSet.java


But I get the following error:

ResultSet.java:5: error: package data does not exist
import data.Spieler;
^
ResultSet.java:8: error: cannot find symbol
private ArrayList<Spieler> meineSpieler = new ArrayList<Spieler>();
^
symbol: class Spieler
location: class ResultSet
ResultSet.java:12: error: cannot find symbol
public native Spieler[] getSpieler();
^
symbol: class Spieler
location: class ResultSet
ResultSet.java:18: error: cannot find symbol
public ArrayList<Spieler> getMeineSpieler() {
^
symbol: class Spieler
location: class ResultSet
ResultSet.java:8: error: cannot find symbol
private ArrayList<Spieler> meineSpieler = new ArrayList<Spieler>();
^
symbol: class Spieler
location: class ResultSet


How can I import the
spieler
class? Should I set the classpath or is there a other way to fix that?

Answer

Go one directory up and then compile it with

javac data/JNIResultSet.java

Update: Ok, your class JNIResultSet is in package model and it uses other classes in package data.

Then your compile command should be as follows:

javac -cp . model/JNIResultSet.java

The -cp . part means, that your classpath includes the current directory. This is the root of your package hierarchy. So the compiler can find the *.java files in package data and compiles them also as needed.

You see, this can be very complicated. For more classes this will be nearly unmanageable. So you should really consider to use a build system like Ant, Maven or Gradle.