[Dúvida] Javac -classpath especificar mais de um arquivo .jar

3 respostas
rafaelob

Pessoal,

Tava tentando compilar um exemplo do caelum stella validator, utilizando o “javac” e não estou obtendo sucesso, isso aí veio uma curiosidade de como eu conseguir adicionar mais de um .jar no -classpath do javac:

Já tentei assim: javac -classpath “stella-hibernate-validator/caelum-stella-hibernate-validator-1.2.jar;stella-hibernate-validator/caelum-stella-hibernate-core-1.2.jar” Usuario.java

e ele não encontra a lib do caelum-stela-hibernate-validator.

tentei assim também:

javac -classpath stella-hibernate-validator/caelum-stella-hibernate-validator-1.2.jar;…/caelum-stella-1.2/stella-hibernate-validator/caelum-stella-core-1.2.jar Usuario.java

bash: …/caelum-stella-1.2/stella-hibernate-validator/caelum-stella-core-1.2.jar: Permissão negada (Tou executando como root…)

Essa classe tá um nível acima das libs, sei que se eu colocasse no mesmo nível funcionaria, mas tenho essa curiosidade de saber como poderia resolver isso.

Tou usando linux.

Att,

Att,

3 Respostas

L

No linux, o separador é :

No Windows, é ;

rafaelob

Entendi,

Quando eu adiciono -classpath ele adiciona o que eu coloquei na variável de sistema ClassPath, ou seja, além do que eu já tenho no ClassPath vou ter aquelas lib? ou ele vai utilizar só o que passei ?

L

Não lembro ehhe!

Ele vai usar o que você passou, ou o que tiver na variável, eu ACHO. Alguém pode dar uma luz aí…

Dando uma googleada…

The class path is the path that the Java runtime environment searches for classes and other resource files. The class search path (more commonly known by the shorter name, “class path”) can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.

Multiple specifications
To find class files in the directory /java/MyClasses as well as classes in /java/OtherClasses, you would set the class path to:

% java -classpath /java/MyClasses:/java/OtherClasses …
Note that the two paths are separated by a colon.

Specification order
The order in which you specify multiple class path entries is important. The Java interpreter will look for classes in the directories in the order they appear in the class path variable. In the example above, the Java interpreter will first look for a needed class in the directory /java/MyClasses. Only if it doesn’t find a class with the proper name in that directory will the interpreter look in the /java/OtherClasses directory.

Criado 26 de maio de 2011
Ultima resposta 26 de mai. de 2011
Respostas 3
Participantes 2