I'm having trouble compiling my Java source file on Linux. My source file (PetersTeam.java) imports classes from a jar stored in the same file location as the source. I'm getting errors stating that the packages containing the classes do not exist. I've tried many different variations of the command below I found online, but none seem to work. Any help would be greatly appreciated.
javac -cp testjar.jar PetersTeam.java
Here are my imports which match the package structure in the jar:
import org.gamelink.game.Cram;
import org.gamelink.game.Algo;
Here are the errors:
PetersTeam.java:1: error: package org.gamelink.game does not exist
import org.gamelink.game.Cram;
^
PetersTeam.java:2: error: package org.gamelink.game does not exist
import org.gamelink.game.Algo;
^
UPDATE: with the jar tvf testjar.jar command I am only getting:
0 Tue Jul 14 11:17:46 EDT 2015 META-INF/
68 Tue Jul 14 11:17:46 EDT 2015 META-INF/MANIFEST.MF
so I'm assuming I did something wrong when making the jar here is the command I used , Is there something wrong with it?
jar -cvf testjar.jar *.class
It sounds like the problem is with the way you created your jar file - assuming you did it at the root of your class hierarchy (which you should) you should have used:
jar -cvf testjar.jar org/gamelink/game/*.class
... as there shouldn't any class flies in the directory in which you're running jar
.
See more on this question at Stackoverflow