2017-10-18 31 views
0

Ici java9/com/vipin/exp/A.class est le fichier I vouloir utiliser avec jdk 9 et pour les autres versions java8/com/vipin/exp/A.class. Pour cela, j'essaye de créer un pot de sortie multiple mais en obtenant une erreur en dessous. Quel est le problème dans cette commande?Erreur lors de la création de l'entrée "release jar": A.class, contient une classe avec le nom interne com.vipin.exp.A, les noms ne correspondent pas "

[email protected]:~/javacode$ pwd 
    /Users/XXXX/javacode 
[email protected]:~/javacode$ javac --release 9 -d /Users/nitinkumarsharma/javacode/java9/ java9/com/vipin/exp/A.java 
[email protected]:~/javacode$ javac --release 8 -d /Users/nitinkumarsharma/javacode/java8/ java8/com/vipin/exp/A.java 
[email protected]:~/javacode$ jar -c -f vipin.jar -C java8/com/vipin/exp/ . --release 9 -C java9/com/vipin/exp/ . 

     entry: A.class, contains a class with internal name com.vipin.exp.A, names do not match 
     entry: META-INF/versions/9/A.class, contains a new public class not found in base entries 
     Warning: entry META-INF/versions/9/A.java, multiple resources with same name 
     invalid multi-release jar file vipin.jar deleted 

Ma structure de répertoire est:

[email protected]:~/javacode$ tree 
. 
|____java8 
| |____com 
| | |____vipin 
| | | |____exp 
| | | | |____A.class 
| | | | |____A.java 
|____java9 
| |____com 
| | |____vipin 
| | | |____exp 
| | | | |____A.class 
| | | | |____A.java 

Il fonctionne bien quand j'utilise un seul fichier de classe pour créer pot, comme ci-dessous

[email protected]:~/javacode$ jar -c -f vipin.jar -C java8/com/vipin/exp/ . 
[email protected]:~/javacode$ ls -ltr 
total 12688 
drwxr-xr-x 3 XXXX staff  102 Oct 17 18:02 java8 
drwxr-xr-x 3 XXXX staff  102 Oct 17 20:00 java9 
-rw-r--r-- 1 XXXX staff  968 Oct 18 17:05 vipin.jar 
[email protected]:~/javacode$ jar -tvf vipin.jar 
    0 Wed Oct 18 17:05:08 IST 2017 META-INF/ 
    61 Wed Oct 18 17:05:08 IST 2017 META-INF/MANIFEST.MF 
    430 Tue Oct 17 22:55:22 IST 2017 A.class 
    136 Tue Oct 17 22:49:20 IST 2017 A.java 
+0

Je pense que vous recherchez 'jar -c -f vipin.jar -C java8. --release 9 -C java9 .' - sinon les fichiers de classe seront copiés dans le répertoire de premier niveau ou dans le répertoire de premier niveau de la section versionnée. –

+0

@AlanBateman Après avoir exécuté votre commande "Erreur lors de l'analyse des arguments de fichier Essayez' jar --help 'pour plus d'informations. " – Vipin

+0

@AlanBateman Je ne comprends pas comment j'ai copié la mauvaise commande plus tôt, mais celle disponible là-bas maintenant travaillé pour moi. Ma compréhension de l'option -C était erronée. – Vipin

Répondre

0

Ma compréhension de l'option C a eu tort , J'aurais dû donner le répertoire de niveau supérieur après -C.

[email protected]:~/javacode$ jar -c -f vipin.jar -C java8 . --release 9 -C java9 . 
Warning: entry META-INF/versions/9/com/vipin/exp/A.java, multiple resources with same name 
[email protected]:~/javacode$ jar -tvf vipin.jar 
    0 Wed Oct 18 19:06:26 IST 2017 META-INF/ 
    82 Wed Oct 18 19:06:26 IST 2017 META-INF/MANIFEST.MF 
    0 Tue Oct 17 18:02:04 IST 2017 com/ 
    0 Tue Oct 17 18:02:04 IST 2017 com/vipin/ 
    0 Tue Oct 17 23:26:56 IST 2017 com/vipin/exp/ 
    430 Wed Oct 18 19:00:38 IST 2017 com/vipin/exp/A.class 
    136 Tue Oct 17 22:49:20 IST 2017 com/vipin/exp/A.java 
    0 Tue Oct 17 20:00:34 IST 2017 META-INF/versions/9/ 
    0 Tue Oct 17 20:00:34 IST 2017 META-INF/versions/9/com/ 
    0 Tue Oct 17 20:00:34 IST 2017 META-INF/versions/9/com/vipin/ 
    0 Tue Oct 17 23:27:04 IST 2017 META-INF/versions/9/com/vipin/exp/ 
    430 Wed Oct 18 19:02:04 IST 2017 META-INF/versions/9/com/vipin/exp/A.class 
    135 Tue Oct 17 22:49:26 IST 2017 META-INF/versions/9/com/vipin/exp/A.java 

La commande effectuées donnée en question une sortie erronée ci-dessus produit, corriger une serait ci-dessous et vous pouvez voir dans la sortie de TVF le fichier de classe est disponible dans la structure correcte com/vipin/exp/A.class

[email protected]:~/javacode$ jar -c -f vipin_test.jar -C java8 . 
[email protected]:~/javacode$ jar -tvf vipin_test.jar 
    0 Wed Oct 18 19:20:18 IST 2017 META-INF/ 
    61 Wed Oct 18 19:20:18 IST 2017 META-INF/MANIFEST.MF 
    0 Tue Oct 17 18:02:04 IST 2017 com/ 
    0 Tue Oct 17 18:02:04 IST 2017 com/vipin/ 
    0 Tue Oct 17 23:26:56 IST 2017 com/vipin/exp/ 
    430 Wed Oct 18 19:00:38 IST 2017 com/vipin/exp/A.class 
    136 Tue Oct 17 22:49:20 IST 2017 com/vipin/exp/A.java 

Quelques autres commandes pour montrer que cela a fonctionné parfaitement.

[email protected]:~/javacode$ java -version 
java version "9" 
Java(TM) SE Runtime Environment (build 9+181) 
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) 
[email protected]:~/javacode$ java -cp vipin.jar com.vipin.exp.A 
Inside java9 version 
[email protected]:~/javacode$ /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/bin/java -version 
java version "1.8.0_111" 
[email protected]r.local:~/javacode$ /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/bin/java -cp vipin.jar com.vipin.exp.A 
Inside java8 version