JAR
- modified library loading - jar now is os indipendent (win11 only tested)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -399,4 +399,4 @@ FodyWeavers.xsd
|
|||||||
|
|
||||||
# CUSTOM
|
# CUSTOM
|
||||||
target
|
target
|
||||||
jsmile*
|
*jsmile*
|
||||||
|
|||||||
64
pom.xml
64
pom.xml
@@ -46,7 +46,7 @@
|
|||||||
</activation>
|
</activation>
|
||||||
<properties>
|
<properties>
|
||||||
<nativeSuffix>macos</nativeSuffix>
|
<nativeSuffix>macos</nativeSuffix>
|
||||||
<smileFile>jsmile.jnilib</smileFile>
|
<smileFile>libjsmile.jnilib</smileFile>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
<profile>
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
</activation>
|
</activation>
|
||||||
<properties>
|
<properties>
|
||||||
<nativeSuffix>linux64</nativeSuffix>
|
<nativeSuffix>linux64</nativeSuffix>
|
||||||
<smileFile>jsmile.so</smileFile>
|
<smileFile>libjsmile.so</smileFile>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
@@ -92,7 +92,47 @@
|
|||||||
<artifactItems>
|
<artifactItems>
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>com.bayesfusion</groupId>
|
<groupId>com.bayesfusion</groupId>
|
||||||
<artifactId>jsmile-native-${nativeSuffix}</artifactId>
|
<artifactId>jsmile-native-win64</artifactId>
|
||||||
|
<version>${smile.version}</version>
|
||||||
|
<type>zip</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<includes>*jsmile*</includes>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
<outputDirectory>${project.basedir}/src/main/resources/</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>resource-dependencies</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>unpack</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>com.bayesfusion</groupId>
|
||||||
|
<artifactId>jsmile-native-macos</artifactId>
|
||||||
|
<version>${smile.version}</version>
|
||||||
|
<type>zip</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<includes>*jsmile*</includes>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
<outputDirectory>${project.basedir}/src/main/resources/</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>resource-dependencies</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>unpack</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>com.bayesfusion</groupId>
|
||||||
|
<artifactId>jsmile-native-linux64</artifactId>
|
||||||
<version>${smile.version}</version>
|
<version>${smile.version}</version>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
@@ -104,23 +144,12 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Renaming the jsmile & make a copy to test resources -->
|
<!-- Make a copy of JSMILE to test resources -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.coderplus.maven.plugins</groupId>
|
<groupId>com.coderplus.maven.plugins</groupId>
|
||||||
<artifactId>copy-rename-maven-plugin</artifactId>
|
<artifactId>copy-rename-maven-plugin</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
|
||||||
<id>rename-file</id>
|
|
||||||
<phase>compile</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>copy</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<sourceFile>${project.basedir}/src/main/resources/${smileFile}</sourceFile>
|
|
||||||
<destinationFile>${project.basedir}/src/main/resources/jsmile</destinationFile>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
<execution>
|
||||||
<id>copy-file</id>
|
<id>copy-file</id>
|
||||||
<phase>compile</phase>
|
<phase>compile</phase>
|
||||||
@@ -128,12 +157,7 @@
|
|||||||
<goal>copy</goal>
|
<goal>copy</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- IDK Why but using 2 files makes the loading work, so i copy them in test too -->
|
|
||||||
<fileSets>
|
<fileSets>
|
||||||
<fileSet>
|
|
||||||
<sourceFile>${project.basedir}/src/main/resources/jsmile</sourceFile>
|
|
||||||
<destinationFile>${project.basedir}/src/test/resources/jsmile</destinationFile>
|
|
||||||
</fileSet>
|
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<sourceFile>${project.basedir}/src/main/resources/${smileFile}</sourceFile>
|
<sourceFile>${project.basedir}/src/main/resources/${smileFile}</sourceFile>
|
||||||
<destinationFile>${project.basedir}/src/test/resources/${smileFile}</destinationFile>
|
<destinationFile>${project.basedir}/src/test/resources/${smileFile}</destinationFile>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.berack.upo.ai.problem3;
|
package net.berack.upo.ai.problem3;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -21,12 +23,25 @@ import smile.Network;
|
|||||||
public class SmileLib {
|
public class SmileLib {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
var jsmile = jsmileLibName();
|
||||||
|
var loader = SmileLib.class.getClassLoader();
|
||||||
|
var resource = loader.getResource(jsmile);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var jsmile = "jsmile";
|
|
||||||
var loader = SmileLib.class.getClassLoader();
|
|
||||||
var resource = loader.getResource(jsmile);
|
|
||||||
var uri = resource.toURI();
|
var uri = resource.toURI();
|
||||||
var path = Path.of(uri).toString();
|
var path = "";
|
||||||
|
|
||||||
|
if(uri.toString().startsWith("jar")) {
|
||||||
|
var tmp = System.getProperty("java.io.tmpdir");
|
||||||
|
var file = new File(tmp + jsmile);
|
||||||
|
if(!file.exists()) {
|
||||||
|
var in = resource.openStream();
|
||||||
|
Files.copy(in, file.toPath());
|
||||||
|
}
|
||||||
|
path = file.getAbsolutePath();
|
||||||
|
}
|
||||||
|
else path = Path.of(uri).toString();
|
||||||
|
|
||||||
System.setProperty("jsmile.native.library", path);
|
System.setProperty("jsmile.native.library", path);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -53,6 +68,21 @@ public class SmileLib {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ritorna il nome della libreria jsmile in base al sistema operativo.
|
||||||
|
* @return il node del file
|
||||||
|
*/
|
||||||
|
private static String jsmileLibName() {
|
||||||
|
var os = System.getProperty("os.name").toLowerCase();
|
||||||
|
if(os.indexOf("win") >= 0) return "jsmile.dll";
|
||||||
|
if(os.indexOf("mac") >= 0) return "libjsmile.jnilib";
|
||||||
|
if(os.indexOf("nix") >= 0
|
||||||
|
|| os.indexOf("nux") >= 0
|
||||||
|
|| os.indexOf("aix") >= 0) return "libjsmile.so";
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crea un Network dal file indicato
|
* Crea un Network dal file indicato
|
||||||
* Il file deve essere una risorsa del jar o un file esterno
|
* Il file deve essere una risorsa del jar o un file esterno
|
||||||
|
|||||||
Reference in New Issue
Block a user