2015-08-22 1 views
0

Je suis nouveau sur Maven. Je dois utiliser la classe sun.security.tools.JarSigner dans mon projet.Im essayant d'ajouter tools.jar comme dépendance.J'ai procédé par Maven's FAQ, d'autres articles de stackowerflow et google mais sans quelques résultats positifs.Maven: JAVA_HOME/lib/tools.jar en tant que dépendance

Mon NetBean peut "voir" la classe JarSigner avec pom beloow.

Je peux compiler le projet sans erreur ou avertir mais je ne peux pas l'exécuter.

pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.mycompany</groupId> 
<artifactId>Experiments</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>jar</packaging> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <maven.compiler.source>1.7</maven.compiler.source> 
    <maven.compiler.target>1.7</maven.compiler.target> 
</properties> 

<dependencies>   
    <dependency> 
     <groupId>com.sun</groupId> 
     <artifactId>tools</artifactId> 
     <version>1.6.0</version> 
     <scope>system</scope> 
     <systemPath>${java.home}/../lib/tools.jar</systemPath> 
    </dependency> 
</dependencies> 

<profiles> 
    <profile> 
     <id>default-tools.jar</id> 
     <activation> 
      <property> 
       <name>java.vendor</name> 
       <value>Sun Microsystems Inc.</value> 
      </property> 
     </activation> 
     <dependencies> 
      <dependency> 
       <groupId>com.sun</groupId> 
       <artifactId>tools</artifactId> 
       <version>1.4.2</version> 
       <scope>system</scope> 
       <systemPath>${java.home}/../lib/tools.jar</systemPath> 
      </dependency> 
     </dependencies> 
    </profile> 
</profiles> 

journal après mvn exec:java -Dexec.mainClass="com.mycompany.Main"

[INFO] Error stacktraces are turned on. 
[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Experiments 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ Experiments --- 
[WARNING] 
java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.NoClassDefFoundError: sun/security/tools/JarSigner 
    at com.mycompany.experiments.Main.main(Main.java:8) 
    ... 6 more 
Caused by: java.lang.ClassNotFoundException: sun.security.tools.JarSigner 
    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:425) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    ... 7 more 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.217s 
[INFO] Finished at: Sat Aug 22 18:04:28 CEST 2015 
[INFO] Final Memory: 10M/310M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project Experiments: An exception occured while executing the Java class. null: InvocationTargetException: sun/security/tools/JarSigner: sun.security.tools.JarSigner -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project Experiments: An exception occured while executing the Java class. null 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152) 
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555) 
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214) 
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) 
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null 
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) 
    ... 19 more 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.NoClassDefFoundError: sun/security/tools/JarSigner 
    at com.mycompany.experiments.Main.main(Main.java:8) 
    ... 6 more 
Caused by: java.lang.ClassNotFoundException: sun.security.tools.JarSigner 
    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:425) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    ... 7 more 
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 
+0

Pouvez-vous spécifier la valeur de votre variable JAVA_HOME? –

Répondre

0

changement <systemPath>${java.home}/../lib/tools.jar</systemPath>-<systemPath>${java.home}/lib/tools.jar</systemPath>. Par ailleurs, savez-vous que vous faites une séparation avec la version JDK? le profil default-tools.jar sera activé pour jdk 1.6 et inférieur (selon la propriété java.vendor) et puisque je vois que vous utilisez jdk 7, je suppose que c'est redondant.

+0

J'ai défini ' /opt/jdk1.7.0_67' et j'utilise ' $ {java.home} /lib/tools.jar' même résultat en acier. – Krakonos

+0

J'aurais essayé d'enlever la section et mettre 1.7.0_67 pour voir ce qui se passe. –

0

Ma solution: J'extraire le paquet sun.security.tools de tools.jar et cette copie compilée de sources au dossier src. À la phase de compilation, je copie les classes compilées en target.

 <plugins> 
      <plugin> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>2.7</version> 
       <executions> 
        <execution> 
         <id>copy-resources</id> 
         <phase>compile</phase> 
         <goals> 
          <goal>copy-resources</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${basedir}/target/classes/sun/security/tools</outputDirectory> 
          <resources>   
           <resource> 
            <filtering>false</filtering> 
            <directory>${basedir}/src/main/java/sun/security/tools/</directory> 
            <includes> 
             <include>*.class</include> 
            </includes> 
           </resource> 
          </resources>    
         </configuration>    
        </execution> 
       </executions> 
      </plugin>