Dans mon programme Java, je fais un usage intensif de l'implémentation Suns du moteur de script Rhino. Très récemment cependant, mon JDK ne semble plus importer automatiquement le fichier rt.jar lors de la compilation. Ce qui est étrange, c'est que NetBeans signale 0 erreur en direct, ils n'apparaissent que lorsque vous effectuez un nettoyage complet & Build. Cela ne se passait pas avant quand j'importais NativeArray, donc je suis vraiment confus sur pourquoi tout d'un coup cessé de fonctionner.Impossible d'importer sun.org.mozilla.javascript.internal dans NetBeans
Spécifications:
- OS - Windows
- version Java - java version "1.6.0_20"
- Version Javac - javac Version 1.6.0_20
- NetBeans - 6,9
Vérifiez s'il n'existe pas:
C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src>javap sun.org.mozill a.javascript.internal.WrappedException Compiled from "WrappedException.java" public class sun.org.mozilla.javascript.internal.WrappedException extends sun.or g.mozilla.javascript.internal.EvaluatorException{ static final long serialVersionUID; public sun.org.mozilla.javascript.internal.WrappedException(java.lang.Throwa ble); public java.lang.Throwable getWrappedException(); public java.lang.Object unwrap(); }
Ok, il existe, donc voici un code de test:
package testapp;
import sun.org.mozilla.javascript.internal.WrappedException;
public class Main {
public static void main(String[] args) {
WrappedException e = new WrappedException(null);
}
}
Netbeans sortie:
init: deps-clean: Updating property file: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\built-clean.properties Deleting directory C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build clean: init: deps-jar: Created dir: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build Updating property file: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\built-jar.properties Created dir: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\classes Created dir: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\empty Compiling 1 source file to C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\classes C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp\Main.java:8: package sun.org.mozilla.javascript.internal does not exist import sun.org.mozilla.javascript.internal.WrappedException; C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp\Main.java:16: cannot find symbol symbol : class WrappedException location: class testapp.Main WrappedException e = new WrappedException(null); ^ C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp\Main.java:16: cannot find symbol symbol : class WrappedException location: class testapp.Main WrappedException e = new WrappedException(null); ^ 3 errors C:\Documents and Settings\LordQuackstar\Desktop\TestApp\nbproject\build-impl.xml:528: The following error occurred while executing this line: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\nbproject\build-impl.xml:261: Compile failed; see the compiler error output for details. BUILD FAILED (total time: 0 seconds)
sortie de ligne de commande:
C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp>javac Main.java Main.java:3: package sun.org.mozilla.javascript.internal does not exist import sun.org.mozilla.javascript.internal.WrappedException; ^ Main.java:7: cannot find symbol symbol : class WrappedException location: class testapp.Main WrappedException e = new WrappedException(null); ^ Main.java:7: cannot find symbol symbol : class WrappedException location: class testapp.Main WrappedException e = new WrappedException(null); ^ 3 errors
Alors, quelle serait la cause à l'échec tout d'un coup? Ça fonctionnait très bien hier. Je n'ai rien changé en plus d'importer 2 classes de plus du même paquet. Aucune de mes dépendances n'a changé.
Test dans Linux pour voir si le problème existe toujours.
Avant de le dire: Non, je ne suis pas télécharger rhino séparemment, Non, je ne change pas IDEs,
Alors, comment comptez-vous être en mesure d'accéder à javascript tableaux de java sans la syntaxe ridicule de 'java.lang.reflect.Array.newInstance (java.lang.String, 5);'? Comment auriez-vous accès aux objets JSON? Tu ne peux pas. javax.script n'est rien de plus qu'une couche d'abstraction. Il n'y a rien qui m'empêche d'utiliser l'espace de nom de Sun, et interne est juste une étrange gestion du soleil (Il n'y a pas de classes entre org.mozilla et org.mozilla.rhino.internal.) – TheLQ
si l'abstraction ne suffit pas, utilisez l'implémentation brute directement - téléchargez rhino et utilisez-le. – Bozho
La mise en œuvre de Suns fonctionne très bien. Je préférerais ne pas ajouter encore une autre dépendance à une liste déjà grande pour un framework quand il y en a une par défaut parfaite. – TheLQ