Comment puis-je obtenir la valeur actuelle de CLASSPATH
dans Groovy?Comment obtenir classpath dans Groovy?
Répondre
Cela ne fonctionne pas?
System.getProperty('java.class.path')
def classpath = System.properties["java.class.path"]
Malheureusement, il est vide lorsque j'utilise Groovy à l'intérieur [gmaven plugin] (http: //docs.codehaus.org/display/GMAVEN/Executing+Groovy+Code) – yegor256
Obtenez le CLASSPATH et les fichiers si vous voulez en ceux CLASSPATH si nécessaire, vous pouvez le consulter
System.getProperty("java.class.path", ".").tokenize(File.pathSeparator).each {
println it
}
Vous devriez être en mesure d'obtenir le classpath de la SystemClassLoader, à condition qu'il soit un URLClassLoader:
URL[] classPathUrls = ClassLoader.getSystemClassLoader().getURLs();
Même chose: à la fois la variable d'environnement 'CLASSPATH' et le' -classpath' dans la commande cette ligne n'a aucun effet sur cette liste, au moins dans mon cas, elle est identique à wha Je vois dans la propriété 'java.class.path'. – osa
Cependant, consultez http://groovy.codehaus.org/How+can+I+dynamically+add+a+library+to+the+classpath pour ajouter dynamiquement un chemin à classpath. this.class.classLoader.rootLoader.addURL (nouvelle URL ("file: /// d: /drivers/ojdbc14.jar")) – osa
java.class.path
ne fonctionne pas correctement, au moins dans Groovy 2.1.6 (Ma c OS X 10.6.8).
HelloWorld.groovy
:
public class HelloWorld {
public static void main(def args) {
System.out.println("Hello, world!\n");
System.out.println(System.getenv("CLASSPATH")+"\n");
System.out.println(System.getProperty("java.class.path"));
}
}
Puis
export CLASSPATH=/etc
groovy -classpath /usr HelloWorld.groovy
Résultat:
Hello, World!
/etc
/Applications/groovy-2.1.6/lib/groovy-2.1.6.jar
Maintenant, c'est HelloWorld.java
: (je devais changer un peu comme Groovy et Java ne sont pas 100% compatible):
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello, world!\n");
System.out.println(System.getenv("CLASSPATH")+"\n");
System.out.println(System.getProperty("java.class.path"));
}
}
maintenant:
javac HelloWorld.java
export CLASSPATH=/etc
java -classpath /usr HelloWorld
Résultat:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
etc. ...................
Puis:
java -classpath /usr:. HelloWorld
Résultat:
Hello, world!
/etc
/usr:.
Je mettrai à jour si je trouve comment le faire fonctionner dans Groovy ...
Shameless volé http://blog.blindgaenger.net/print_groovys_classpath_for_debugging.html Ce code remonter dans l'arborescence classloader et impression chaque classloader et le classpath associé.
def printClassPath(classLoader) {
println "$classLoader"
classLoader.getURLs().each {url->
println "- ${url.toString()}"
}
if (classLoader.parent) {
printClassPath(classLoader.parent)
}
}
printClassPath this.class.classLoader
- 1. groovy script classpath
- 2. Groovy ne peut pas exécuter classpath
- 3. Comment définir un classpath de scripts Groovy incorporés?
- 4. Groovlet classpath
- 5. invoquant groovy sans passer un classpath à chaque fois
- 6. Problème de classpath de script Groovy avec SystemClassLoader
- 7. Obtenir l'adresse Mac dans Groovy
- 8. comment obtenir la valeur d'eclipse .classpath classpathentry
- 9. Obtenir java.io.FileNotFoundException (classpath .jasper dans NetBeans)
- 10. Comment configurer grails classpath pour ajouter un dossier "src/groovy" (dans un environnement Linux)?
- 11. Apache ANT classpath classpath
- 12. Obtenir une erreur dans GEB + Spock + Groovy
- 13. Comment lister toutes les classes (groovy) dans JVM dans groovy
- 14. Geb groovy configuration simple, obtenir NoClassDefFoundError
- 15. Obtenir l'URL d'une chaîne groovy
- 16. Comment obtenir le chemin du répertoire dans groovy
- 17. problème Classpath
- 18. Groovy ne lit pas les fichiers jar dans .groovy/lib
- 19. java classpath dans unix
- 20. Comment obtenir le classpath d'un autre projet java?
- 21. Comment utiliser jcurses de groovy
- 22. Groove Spring Bean Classpath
- 23. obtenir le dernier mot dans une chaîne tokenized dans groovy
- 24. Ehcache.xml multiple dans classpath
- 25. Whitespaces dans CLASSPATH
- 26. Classpath dans le manifeste
- 27. Log4J introuvable dans classpath
- 28. Comment faire ceci dans Groovy?
- 29. Comment construire URL dans Groovy
- 30. Comment l'instruction GOTO dans Groovy?
Il est vide :(Est-il possible d'obtenir sous forme classpath chargeur de classe? – yegor256
Groovy semble faire des choses génial, et le java.class.path ne contient pas le classpath passé avec l'option de ligne de commande de -cp groovy. –
Cela ne fonctionne pas – osa