2016-07-08 63 views
16

Ho un progetto di maven con alcune dipendenze di libreria (.dll) (che ho inserito in una cartella "lib"). Posso eseguire il progetto senza problemi Netbeans, ma quando provo a fare funzionare il costruito .jar al di fuori di Netbeans, ottengo l'errore seguente sul caricamento della libreria:Che tipo di stregoneria sta facendo Maven per eseguire questo progetto, quando non posso?

Can't load this .dll (machine code=0xbd) on a AMD 64-bit platform

ho solo uno esempio di Java installato sul mio computer, dovrebbe essere la stessa JVM utilizzata da Netbeans/Maven per eseguire il progetto. Quindi non riesco a capire come Netbeans/Maven è in grado di eseguire questa applicazione su una piattaforma diversa da me? Ho provato a guardare il comando di Netbeans esegue (dall'uscita) per eseguire il progetto e penso che sia questo:

cd C:\Users\Birger\Workspace\myproject; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_91" cmd /c "\"\"C:\\Program Files\\NetBeans 8.1\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-Djava.library.path=lib\\ -classpath %classpath com.mysite.myproject.Main\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_91\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.1\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\"" 

ho provato questi due comandi

"C:\Program Files\Java\jdk1.8.0_91\jre\bin\java.exe" -Djava.library.path=lib\ -jar myproject-1.0-SNAPSHOT.jar 
"C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" -Djava.library.path=lib\ -jar myproject-1.0-SNAPSHOT.jar 

ho aggiunto System.out.println(System.getProperty("sun.arch.data.model")); per ottenere il mio applicazione per stampare l'architettura della cpu. Stampa 64 in entrambe le occasioni.

Ho cercato nel file "mvn.bat" in C:\Program Files\NetBeans 8.1\java\maven\bin\mvn.bat ma non sono riuscito a trovare alcun indizio su ciò che Maven sta facendo per eseguire la mia applicazione.

Qualcuno può aiutarmi su questo?

Birger

EDIT

Ecco il codice sorgente completo del mio progetto di test. Il mio progetto di 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.mysite</groupId> 
    <artifactId>myproject</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <maven.compiler.source>1.8</maven.compiler.source> 
     <maven.compiler.target>1.8</maven.compiler.target> 
    </properties> 
    <repositories> 
     <repository> 
      <id>repo</id> 
      <url>file://${project.basedir}/temp-repo</url> 
     </repository> 
    </repositories> 
    <dependencies> 
     <dependency> 
      <groupId>jni4net</groupId> 
      <artifactId>jni4net.j</artifactId> 
      <version>0.8.8.0</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.10</version> 
       <executions> 
        <execution> 
         <id>copy</id> 
         <phase>package</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
         <configuration> 
          <outputDirectory> 
           ${project.build.directory}/lib 
          </outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>3.0.2</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>com.mysite.myproject.Main</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>3.0.1</version> 
       <executions> 
        <execution> 
         <id>copy-resources</id> 
         <phase>validate</phase> 
         <goals> 
          <goal>copy-resources</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${project.build.directory}/lib</outputDirectory> 
          <resources>   
           <resource> 
            <directory>lib</directory> 
            <filtering>true</filtering> 
           </resource> 
          </resources>    
         </configuration>    
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

classe di mio progetto

package com.mysite.myproject; 

import java.io.File; 
import java.io.IOException; 
import net.sf.jni4net.Bridge; 

public class Main { 

    static { 
     String libDir = System.getProperty("java.library.path"); 
     System.loadLibrary("jni4net.n-0.8.8.0"); 

     if (System.getProperty("sun.arch.data.model").equals("64")) { 
      System.loadLibrary("jni4net.n.w64.v20-0.8.8.0"); 
      System.loadLibrary("jni4net.n.w64.v40-0.8.8.0"); 
     } else { 
      System.loadLibrary("jni4net.n.w32.v20-0.8.8.0"); 
      System.loadLibrary("jni4net.n.w32.v40-0.8.8.0"); 
     } 

     try { 
      Bridge.init(new File(libDir)); 
      System.out.println("Initialized!"); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) { 
     new Main(); 
    } 

    public Main() { 
     System.out.println("Hello world!"); 
    } 
} 
uscita

Netbeans durante l'esecuzione del progetto (aggiunto --debug opzione per l'output dettagliato):

cd C:\Users\Birger\Workspace\myproject; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_91" cmd /c "\"\"C:\\Program Files\\NetBeans 8.1\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-Djava.library.path=lib\\ -classpath %classpath com.mysite.myproject.Main\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_91\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.1\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 --debug org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\"" 
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts. 
C:\Program Files\Java\jdk1.8.0_91 
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100) 
Maven home: C:\Program Files\NetBeans 8.1\java\maven 
Java version: 1.8.0_91, vendor: Oracle Corporation 
Java home: C:\Program Files\Java\jdk1.8.0_91\jre 
Default locale: en_US, platform encoding: Cp1252 
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos" 
Populating class realm maven.ext 
    Included C:\Program Files\NetBeans 8.1\java\maven-nblib\netbeans-eventspy.jar 
Error stacktraces are turned on. 
Reading global settings from C:\Program Files\NetBeans 8.1\java\maven\conf\settings.xml 
Reading user settings from C:\Users\Birger\.m2\settings.xml 
Using local repository at C:\Users\Birger\.m2\repository 
Using manager EnhancedLocalRepositoryManager with priority 10 for C:\Users\Birger\.m2\repository 
Scanning for projects... 
Extension realms for project com.mysite:myproject:jar:1.0-SNAPSHOT: (none) 
Looking up lifecyle mappings for packaging jar from ClassRealm[maven.ext, parent: ClassRealm[plexus.core, parent: null]] 
=== REACTOR BUILD PLAN ================================================ 
Project: com.mysite:myproject:jar:1.0-SNAPSHOT 
Tasks: [org.codehaus.mojo:exec-maven-plugin:1.2.1:exec] 
Style: Regular 
======================================================================= 

------------------------------------------------------------------------ 
Building myproject 1.0-SNAPSHOT 
------------------------------------------------------------------------ 
Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy] 
Lifecycle clean -> [pre-clean, clean, post-clean] 
Lifecycle site -> [pre-site, site, post-site, site-deploy] 
=== PROJECT BUILD PLAN ================================================ 
Project:  com.mysite:myproject:1.0-SNAPSHOT 
Dependencies (collect): [] 
Dependencies (resolve): [test] 
Repositories (dependencies): [libs-release (http://artifactory.osc.no:8081/artifactory/libs-release/, releases), repo (file://C:\Users\Birger\Workspace\myproject/temp-repo, releases+snapshots), central (http://repo.maven.apache.org/maven2, releases)] 
Repositories (plugins)  : [libs-release (http://artifactory.osc.no:8081/artifactory/libs-release/, releases), central (http://repo.maven.apache.org/maven2, releases)] 
----------------------------------------------------------------------- 
Goal:   org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) 
Style:   Regular 
Configuration: <?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <basedir default-value="${basedir}"/> 
    <classpathScope default-value="runtime">${exec.classpathScope}</classpathScope> 
    <commandlineArgs>${exec.args}</commandlineArgs> 
    <executable>${exec.executable}</executable> 
    <longClasspath default-value="false">${exec.longClasspath}</longClasspath> 
    <outputFile>${exec.outputFile}</outputFile> 
    <project default-value="${project}"/> 
    <session default-value="${session}"/> 
    <skip default-value="false">${skip}</skip> 
    <sourceRoot>${sourceRoot}</sourceRoot> 
    <testSourceRoot>${testSourceRoot}</testSourceRoot> 
    <workingDirectory>${exec.workingdir}</workingDirectory> 
</configuration> 
======================================================================= 
com.mysite:myproject:jar:1.0-SNAPSHOT 
    jni4net:jni4net.j:jar:0.8.8.0:compile 

--- exec-maven-plugin:1.2.1:exec (default-cli) @ myproject --- 
Created new class realm maven.api 
Importing foreign packages into class realm maven.api 
    Imported: org.apache.maven.cli < maven.ext 
    Imported: org.codehaus.plexus.lifecycle < maven.ext 
    Imported: org.apache.maven.lifecycle < maven.ext 
    Imported: org.apache.maven.repository < maven.ext 
    Imported: org.codehaus.plexus.personality < maven.ext 
    Imported: org.apache.maven.usability < maven.ext 
    Imported: org.codehaus.plexus.configuration < maven.ext 
    Imported: org.sonatype.aether.version < maven.ext 
    Imported: org.sonatype.aether.* < maven.ext 
    Imported: org.sonatype.aether.artifact < maven.ext 
    Imported: org.apache.maven.* < maven.ext 
    Imported: org.apache.maven.project < maven.ext 
    Imported: org.sonatype.aether.repository < maven.ext 
    Imported: org.sonatype.aether.impl < maven.ext 
    Imported: org.apache.maven.exception < maven.ext 
    Imported: org.apache.maven.plugin < maven.ext 
    Imported: org.sonatype.aether.collection < maven.ext 
    Imported: org.codehaus.plexus.* < maven.ext 
    Imported: org.codehaus.plexus.logging < maven.ext 
    Imported: org.apache.maven.profiles < maven.ext 
    Imported: org.sonatype.aether.metadata < maven.ext 
    Imported: org.sonatype.aether.spi < maven.ext 
    Imported: org.codehaus.plexus.util.xml.pull.XmlPullParserException < maven.ext 
    Imported: org.apache.maven.wagon.* < maven.ext 
    Imported: org.sonatype.aether.graph < maven.ext 
    Imported: org.apache.maven.rtinfo < maven.ext 
    Imported: org.sonatype.aether.installation < maven.ext 
    Imported: org.apache.maven.monitor < maven.ext 
    Imported: org.sonatype.aether.transfer < maven.ext 
    Imported: org.codehaus.plexus.context < maven.ext 
    Imported: org.apache.maven.wagon.observers < maven.ext 
    Imported: org.apache.maven.wagon.resource < maven.ext 
    Imported: org.sonatype.aether.deployment < maven.ext 
    Imported: org.apache.maven.model < maven.ext 
    Imported: org.codehaus.plexus.util.xml.Xpp3Dom < maven.ext 
    Imported: org.apache.maven.artifact < maven.ext 
    Imported: org.apache.maven.toolchain < maven.ext 
    Imported: org.codehaus.plexus.util.xml.pull.XmlSerializer < maven.ext 
    Imported: org.apache.maven.settings < maven.ext 
    Imported: org.apache.maven.wagon.authorization < maven.ext 
    Imported: org.apache.maven.wagon.events < maven.ext 
    Imported: org.apache.maven.wagon.authentication < maven.ext 
    Imported: org.apache.maven.reporting < maven.ext 
    Imported: org.apache.maven.wagon.repository < maven.ext 
    Imported: org.apache.maven.configuration < maven.ext 
    Imported: org.codehaus.plexus.classworlds < maven.ext 
    Imported: org.codehaus.classworlds < maven.ext 
    Imported: org.codehaus.plexus.util.xml.pull.XmlPullParser < maven.ext 
    Imported: org.apache.maven.classrealm < maven.ext 
    Imported: org.sonatype.aether.resolution < maven.ext 
    Imported: org.apache.maven.execution < maven.ext 
    Imported: org.apache.maven.wagon.proxy < maven.ext 
    Imported: org.codehaus.plexus.container < maven.ext 
    Imported: org.codehaus.plexus.component < maven.ext 
Populating class realm maven.api 
org.codehaus.mojo:exec-maven-plugin:jar:1.2.1: 
    org.apache.maven:maven-toolchain:jar:1.0:compile 
    org.apache.maven:maven-project:jar:2.0.6:compile 
     org.apache.maven:maven-settings:jar:2.0.6:compile 
     org.apache.maven:maven-profile:jar:2.0.6:compile 
     org.apache.maven:maven-plugin-registry:jar:2.0.6:compile 
    org.apache.maven:maven-model:jar:2.0.6:compile 
    org.apache.maven:maven-artifact:jar:2.0.6:compile 
    org.apache.maven:maven-artifact-manager:jar:2.0.6:compile 
     org.apache.maven:maven-repository-metadata:jar:2.0.6:compile 
    org.apache.maven:maven-core:jar:2.0.6:compile 
     org.apache.maven:maven-plugin-parameter-documenter:jar:2.0.6:compile 
     org.apache.maven.reporting:maven-reporting-api:jar:2.0.6:compile 
     org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7:compile 
     org.apache.maven:maven-error-diagnostics:jar:2.0.6:compile 
     commons-cli:commons-cli:jar:1.0:compile 
     org.apache.maven:maven-plugin-descriptor:jar:2.0.6:compile 
     org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile 
     org.apache.maven:maven-monitor:jar:2.0.6:compile 
     classworlds:classworlds:jar:1.1:compile 
    org.apache.maven:maven-plugin-api:jar:2.0.6:compile 
    org.codehaus.plexus:plexus-utils:jar:2.0.5:compile 
    org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:compile 
     junit:junit:jar:3.8.2:test (scope managed from compile) (version managed from 3.8.1) 
    org.apache.commons:commons-exec:jar:1.1:compile 
Created new class realm plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1 
Importing foreign packages into class realm plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1 
    Imported: < maven.api 
Populating class realm plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1 
    Included: org.codehaus.mojo:exec-maven-plugin:jar:1.2.1 
    Included: org.apache.maven.reporting:maven-reporting-api:jar:2.0.6 
    Included: org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7 
    Included: commons-cli:commons-cli:jar:1.0 
    Included: org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4 
    Included: org.codehaus.plexus:plexus-utils:jar:2.0.5 
    Included: org.apache.commons:commons-exec:jar:1.1 
    Excluded: org.apache.maven:maven-toolchain:jar:1.0 
    Excluded: org.apache.maven:maven-project:jar:2.0.6 
    Excluded: org.apache.maven:maven-settings:jar:2.0.6 
    Excluded: org.apache.maven:maven-profile:jar:2.0.6 
    Excluded: org.apache.maven:maven-plugin-registry:jar:2.0.6 
    Excluded: org.apache.maven:maven-model:jar:2.0.6 
    Excluded: org.apache.maven:maven-artifact:jar:2.0.6 
    Excluded: org.apache.maven:maven-artifact-manager:jar:2.0.6 
    Excluded: org.apache.maven:maven-repository-metadata:jar:2.0.6 
    Excluded: org.apache.maven:maven-core:jar:2.0.6 
    Excluded: org.apache.maven:maven-plugin-parameter-documenter:jar:2.0.6 
    Excluded: org.apache.maven:maven-error-diagnostics:jar:2.0.6 
    Excluded: org.apache.maven:maven-plugin-descriptor:jar:2.0.6 
    Excluded: org.apache.maven:maven-monitor:jar:2.0.6 
    Excluded: classworlds:classworlds:jar:1.1 
    Excluded: org.apache.maven:maven-plugin-api:jar:2.0.6 
    Excluded: org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9 
    Excluded: junit:junit:jar:3.8.2 
Configuring mojo org.codehaus.mojo:exec-maven-plugin:1.2.1:exec from plugin realm ClassRealm[plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1, parent: [email protected]] 
Configuring mojo 'org.codehaus.mojo:exec-maven-plugin:1.2.1:exec' with basic configurator --> 
    (f) basedir = C:\Users\Birger\Workspace\myproject 
    (f) classpathScope = runtime 
    (f) commandlineArgs = -Djava.library.path=lib\ -classpath %classpath com.mysite.myproject.Main 
    (f) executable = C:\Program Files\Java\jdk1.8.0_91\bin\java.exe 
    (f) longClasspath = false 
    (f) project = MavenProject: com.mysite:myproject:1.0-SNAPSHOT @ C:\Users\Birger\Workspace\myproject\pom.xml 
    (f) session = [email protected] 
    (f) skip = false 
-- end configuration -- 
Collected project artifacts [jni4net:jni4net.j:jar:0.8.8.0:compile] 
Collected project classpath [C:\Users\Birger\Workspace\myproject\target\classes] 
dealing with jni4net:jni4net.j:jar:0.8.8.0:compile 
Toolchains are ignored, 'executable' parameter is set to C:\Program Files\Java\jdk1.8.0_91\bin\java.exe 
Executing command line: C:\Program Files\Java\jdk1.8.0_91\bin\java.exe -Djava.library.path=lib\ -classpath C:\Users\Birger\Workspace\myproject\target\classes;C:\Users\Birger\.m2\repository\jni4net\jni4net.j\0.8.8.0\jni4net.j-0.8.8.0.jar com.mysite.myproject.Main 
Initialized! 
Hello world! 
------------------------------------------------------------------------ 
BUILD SUCCESS 
------------------------------------------------------------------------ 
Total time: 1.360s 
Finished at: Fri Jul 08 09:26:48 CEST 2016 
Final Memory: 5M/245M 
------------------------------------------------------------------------ 

uscita della riga di comando quando si cerca di correre il mio costruito .jar

C:\Users\Birger\Workspace\myproject\target>"C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" -Djava.library.path=lib\ -jar myproject-1.0-SNAPSHOT.jar 
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Birger\Workspace\myproject\target\lib\jni4net.n-0.8.8.0.dll: Can't load this .dll (machine code=0xbd) on a AMD 64-bit platform 
     at java.lang.ClassLoader$NativeLibrary.load(Native Method) 
     at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) 
     at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857) 
     at java.lang.Runtime.loadLibrary0(Runtime.java:870) 
     at java.lang.System.loadLibrary(System.java:1122) 
     at com.mysite.myproject.Main.<clinit>(Main.java:11) 

EDIT2:

per chi cerca di riprodurre questo errore, jni4net può essere trovato here. Ho installato il.vaso con questo file finestre batch:

set project_dir=YOURPROJECTDIRECTORYHERE 
set proxygen_dir=YOURPROXYGENINSTALLATIONDIRECTORYHERE 
set temp_repo_dir=%project_dir%\temp-repo 
call mvn install:install-file -DlocalRepositoryPath=%temp_repo_dir% -DcreateChecksum=true -Dpackaging=jar -Dfile=%proxygen_dir%\lib\jni4net.j-0.8.8.0.jar -DgroupId=jni4net -DartifactId=jni4net.j -Dversion=0.8.8.0 

Edit3:

ho installato a 32 bit JVM, e provato a fare funzionare l'applicazione con il seguente comando:

"C:\Program Files (x86)\Java\jre1.8.0_91\bin\java.exe" -Djava.library.path=lib\ -jar myproject-1.0-SNAPSHOT.jar 

Ora ho:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Birger\Workspace\myproject\target\lib\jni4net.n.w32.v20-0.8.8.0.dll: Can't load this .dll (machine code=0xbd) on a IA 32-bit platform 
    at java.lang.ClassLoader$NativeLibrary.load(Native Method) 
    at java.lang.ClassLoader.loadLibrary0(Unknown Source) 
    at java.lang.ClassLoader.loadLibrary(Unknown Source) 
    at java.lang.Runtime.loadLibrary0(Unknown Source) 
    at java.lang.System.loadLibrary(Unknown Source) 
    at com.mysite.myproject.Main.<clinit>(Main.java:19) 

Sto diventando piuttosto desp eRate qui (e un po 'frustrato con Java TBH)

edit4:

provato questi comandi, anche non funzionante:

"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Djava.library.path=lib\ -classpath C:\Users\Birger\Workspace\myproject\target\classes;C:\Users\Birger\.m2\repositor‌​y\jni4net\jni4net.j\0.8.8.0\jni4net.j-0.8.8.0.jar com.mysite.myproject.Main 
"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Djava.library.path=lib\ -classpath classes;C:\Users\Birger\.m2\repositor‌​y\jni4net\jni4net.j\0.8.8.0\jni4net.j-0.8.8.0.jar com.mysite.myproject.Main 
"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Djava.library.path=lib\ -classpath classes com.mysite.myproject.Main 
+1

Fai un piccolo esempio che riproduce il problema che altri possono vedere. –

+1

Prova ad eseguire Maven con l'opzione '--debug', che dovrebbe darti informazioni più dettagliate su ciò che Maven sta facendo esattamente. – Jesper

+1

L'esecuzione non sembra trovare una dll a 64 bit, ma invece viene data a 32 bit, forse NetBeans lo ha eseguito a 32 bit. 'System.getProperties(). List (System.out);' mostrerebbe quell'informazione. Scegliere "C:/Programmi (x86)/java/..." potrebbe aiutare. –

risposta

10

Ho affrontato questo problema molto tempo fa.

è sufficiente rimuovere lo <filtering>true</filtering>, per evitare di danneggiare i file durante la copia. (Bug !! ???).

Sono stato in grado di riprodurre il problema. questo risolverà anche il tuo problema

spero che questo aiuti.

+0

Sì, questo risolve l'errore. Grazie. Cosa sta "filtrando" nel mondo e perché sta distruggendo il .dll? Il filtro – gromit190

+0

consente di utilizzare variabili per le risorse. hier ha spiegato https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html –

+8

In particolare, il filtro delle risorse tenta di eseguire la sostituzione delle variabili sulle risorse gestite dal plugin .; cioè trova e sostituisce cose che sembrano '' $ {some.name} "' nella risorsa. Se lo fai su una risorsa non testuale, sei responsabile di corromperlo. Non è un bug ... è una caratteristica. –

0

A quanto pare, il dll copiato durante la compilazione sono inutilizzabili dal mio applicazione. Per farlo funzionare, devo caricare i file della libreria originale (non quelli copiati). Netbeans stava facendo esattamente questo, quindi la mia applicazione funzionava bene da Netbeans ma non quando cercavo di usare i file compilati (e copiati).

FIX: Nel mio pom.xml, il filtraggio delle risorse è impostato su true. L'ho impostato su false (o rimosso la voce), e ora la mia applicazione può essere avviata da netbeans esterni. Ecco la mia nuova 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.mysite</groupId> 
    <artifactId>myproject</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <maven.compiler.source>1.8</maven.compiler.source> 
     <maven.compiler.target>1.8</maven.compiler.target> 
    </properties> 
    <repositories> 
     <repository> 
      <id>repo</id> 
      <url>file://${project.basedir}/temp-repo</url> 
     </repository> 
    </repositories> 
    <dependencies> 
     <dependency> 
      <groupId>jni4net</groupId> 
      <artifactId>jni4net.j</artifactId> 
      <version>0.8.8.0</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.10</version> 
       <executions> 
        <execution> 
         <id>copy</id> 
         <phase>package</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
         <configuration> 
          <outputDirectory> 
           ${project.build.directory}/lib 
          </outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>3.0.2</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>com.mysite.myproject.Main</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>3.0.1</version> 
       <executions> 
        <execution> 
         <id>copy-resources</id> 
         <phase>validate</phase> 
         <goals> 
          <goal>copy-resources</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${project.build.directory}/lib</outputDirectory> 
          <resources>   
           <resource> 
            <directory>lib</directory> 
            <filtering>false</filtering> 
           </resource> 
          </resources> 
         </configuration>    
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 
+0

quindi il modo corretto dovrebbe escludere il jni anziché disattivare il filtro. Il filtraggio è un modo per "sostituire" "variabile" nel file di risorse con valore dal pom/maven. Utile per configurazione multipla. Ho il sospetto che nel file della libreria ci siano dei testi che hanno un formato variabile, qualcosa '$ {likethis}' – dieend

+0

vedo. Quindi sta sostituendo i nomi delle variabili riconosciute con i valori? Non penso di mettere nulla nella cartella 'lib' che sarebbe un argomento adatto a questa funzione. Ma posso vedere come sarebbe meglio abilitare il filtraggio ed escludere i file .dll per altri casi (cartelle delle risorse). – gromit190