NoClassDefFoundError:/com / google/commune/base/conditions Préalables, mais les conditions Préalables est dans la .fichier jar dans mon runtime classpath

J'ai un projet qui utilise ImmutableList et ImmutableSet de Goyave. Il compile très bien, mais au moment de l'exécution, avec la même -cp, il donne ce message d'erreur:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Preconditions
    at com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:81)
    at BasicPoint.pointAsArray(BasicPoint.java:93)
    at BasicPoint.inflate(BasicPoint.java:134)
    at BasicEdgeLength.<clinit>(BasicEdgeLength.java:32)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Preconditions
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 4 more

Je le compiler dans le terminal avec la commande

javac -cp '.:/MYPROJECTDIRECTORY/guava-14.0.1.jar'  BasicEdgeLength.java

et il compile. Puis-je exécuter avec la commande

java -cp '.:/MYPROJECTDIRECTORY/guava-14.0.1.jar'  BasicEdgeLength

et j'obtiens l'erreur susmentionnée message. Il y a d'autres questions sur stackoverflow sur exactement le même problème, mais la réponse est toujours télécharger la goyave, les bibliothèques, dont j'ai déjà fait. En effet, quand j'ai fouiner dans guava-14.0.1.jar, je peux voir le fichier com/google/common/base/Preconditions. Le fait que je peux voir dans le .fichier jar le très classe mentionné dans le message d'erreur me fait penser que je ne peux pas résoudre ce problème juste en téléchargeant des fichiers supplémentaires. Donc je ne sais pas quoi faire, et toutes les suggestions que vous pourriez offrir serait grandement apprécié.

Je suis, y compris le code de BasicPoint ci-dessous, parce que c'est la classe qui appelle RegularImmutableList.get(i), même si s'il vous plaît être conscient que BasicPoint ne compile pas sans AbstractPoint, IntMatrix, Initializer, et peut-être quelques autres choses (et il ne contient pas la méthode principale, qui se trouve dans BasicEdgeLength). Je suis heureux d'ajouter le code à certaines de ces autres classes, si quelqu'un pense que c'est nécessaire.

Merci à vous tous pour votre temps!

/**
*    This class implements a point.
*    It uses a representation as a vector of integers.  
*/
import com.google.common.collect.*;
//import com.google.common.base.*; //same error occurs whether or not I include this line
final public class BasicPoint implements AbstractPoint<BasicPoint, BasicAngle> {
//static variables for all points.
private static final int length = Initializer.N - 1;
private static final IntMatrix ROT = Initializer.ROT;
private static final IntMatrix REF = Initializer.REF;
private static final IntMatrix INFL = Initializer.INFL;
//A vector identifying the point.  
private final ImmutableList<Integer> point;
//Constructor methods.
private BasicPoint(Integer[] vector) {
if (vector.length != length) {
throw new IllegalArgumentException("Point length is incorrect.");
}
this.point = ImmutableList.copyOf(vector);
}
private BasicPoint() {
Integer[] vector = new Integer[length];
for (int i = 0; i < length; i++) {
vector[i] = 0;
}
point = ImmutableList.copyOf(vector);
}
//public static factory method
static public BasicPoint createBasicPoint(Integer[] vector) {
return new BasicPoint(vector);
}
static final public BasicPoint zeroVector() {
return new BasicPoint();
}
static final public BasicPoint unitVector() {
Integer[] vector = new Integer[length];
vector[0] = 1;
for (int i = 1; i < length; i++) {
vector[i] = 0;
}
return new BasicPoint(vector);
}
//toString method.
public String toString() {
String outString = "(";
for (int i = 0; i < point.size() - 1; i++) {
outString = outString + point.get(i) + ",";
}
outString = outString + point.get(length) + ")";
return outString;
}
//equals method.
public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass())
return false;
BasicPoint p = (BasicPoint) obj;
for (int i = 0; i < length; i++) {
if (p.point.get(i) != this.point.get(i))
return false;
}
return true;
}
//hashCode override.
public int hashCode() {
int prime = 53;
int result = 11;
for (int i = 0; i < length; i++) {
result = prime*result + point.get(i);
}
return result;
}
//a private helper method to turn point into an array of Integers.
private Integer[] pointAsArray() {
Integer[] output = new Integer[length];
for (int i = 0; i < length; i++)
output[i] = point.get(i);
return output;
}
//Manipulation methods.  
public BasicPoint add(BasicPoint p) {
Integer[] q = new Integer[length];
for (int i = 0; i < length; i++) {
q[i] = this.point.get(i) + p.point.get(i);
}
return new BasicPoint(q);
}
public BasicPoint scalarMultiple(int c) {
Integer[] q = new Integer[length];
for (int i = 0; i < length; i++) {
q[i] = c * this.point.get(i);
}
return new BasicPoint(q);
}
public BasicPoint subtract(BasicPoint p) {
return this.add(p.scalarMultiple(-1));
}
public BasicPoint rotate(BasicAngle a) {
int i = a.getAsInt();
if (i < 0)
throw new IllegalArgumentException("You must perform a positive number of rotations.");
Integer[] result  = new Integer[length];
for (int j = 0; j < i; j++)
result = ROT.rowTimes(result);
return new BasicPoint(result);
}
public BasicPoint reflect() {
return new BasicPoint(REF.rowTimes(this.pointAsArray()));
}
public BasicPoint inflate() {
return new BasicPoint(INFL.rowTimes(this.pointAsArray()));
}
} //end of class BasicPoint
Ajouter le pot à votre build path.
Salut @Makky, merci pour la réponse. Est-ce différent de l'utilisation de ces deux commandes javac -cp '.:/MYPROJECTDIRECTORY/guava-14.0.1.jar' BasicEdgeLength.java java -cp '.:/MYPROJECTDIRECTORY/guava-14.0.1.jar' BasicEdgeLength
Pouvez-vous zip le tout (y compris votre copie de la Goyave jar) et l'afficher quelque part? Il semble que quelque chose d'étrange se passe.
Vous avez raison; le problème était avec un corrompu .fichier jar. Mon ami l'a souligné à moi, et un nouveau téléchargement (à l'aide de wget au lieu de mon navigateur par défaut) a résolu le problème.

OriginalL'auteur Gregory | 2013-08-02