Including a shared object in a maven assembly

I am currently trying to create my project with maven and sqlite4java. This is available in the official maven repositories. The official sqlite4java page in google code has an approximate configuration, but it is a bit outdated and does not meet my needs. I want at the end there is one .jar file that I can deploy elsewhere. The problem here is the decentration of a common object. I use the official build target from my page to copy it to build.dir / lib, but my build result fails:

[INFO] Failed to create assembly: Error adding file-set for 'com.almworks.sqlite4java:libsqlite4java-linux-i386:so:0.282' to archive: Error adding archived file-set. PlexusIoResourceCollection not found for: /home/lhw/.m2/repository/com/almworks/sqlite4java/libsqlite4java-linux-i386/0.282/libsqlite4java-linux-i386-0.282.so
No such archiver: 'so'.

What am I doing wrong? Here is my current pom.xml, devoid of some dependencies not related to this topic

<?xml version="1.0"?>
<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>de.ring0.lhw</groupId>
  <artifactId>system</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>com.almworks.sqlite4java</groupId>
      <artifactId>sqlite4java</artifactId>
      <version>${sqlite4java.version}</version>
    </dependency>
    <dependency>
      <groupId>com.almworks.sqlite4java</groupId>
      <artifactId>libsqlite4java-linux-i386</artifactId>
      <version>${sqlite4java.version}</version>
      <type>so</type>
    </dependency>
  </dependencies>
  <properties>
    <sqlite4java.version>0.282</sqlite4java.version>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>compile</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>com.almworks.sqlite4java</groupId>
                  <artifactId>libsqlite4java-linux-i386</artifactId>
                  <version>${sqlite4java.version}</version>
                  <type>so</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/lib</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.2</version>
        <configuration>
          <skipTests>true</skipTests>
          <systemProperties>
            <property>
              <name>sqlite4java.library.path</name>
              <value>${project.build.directory}/lib</value>
            </property>
          </systemProperties>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <archive>
                <manifest>
                  <mainClass>de.ring0.lhw.Init</mainClass>
                </manifest>
              </archive>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
+5
source share
2 answers

Edit:

, jar-with-dependents .

. :

http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html

maven.apache.org/plugins/maven-assembly-plugin/......

<unpack>true</unpack>

, , .so

,

+1

"jar-with-dependencies" / . , Maven.

/** List of native libraries you put in src/main/resources */
public static final String[] NATIVE_LIB_FILENAMES = {
    "libsqlite4java-linux-amd64.so",
    "libsqlite4java-linux-i386.so",
    "libsqlite4java-osx.jnilib",
    "libsqlite4java-osx-10.4.jnilib",
    "libsqlite4java-osx-ppc.jnilib",
    "sqlite4java-win32-x64.dll",
    "sqlite4java-win32-x86.dll",
};

/**
 * Extract native libraries to the current directory.
 * This example needs Apache Commons IO (https://commons.apache.org/proper/commons-io/)
 */
public static void extractNativeResources() {
    for(String filename: NATIVE_LIB_FILENAMES) {
        // Change "DemoSQLite2" to your class name
        final InputStream in = DemoSQLite2.class.getResourceAsStream("/"+filename);

        if(in != null) {
            try {
                System.out.println("Extracting " + filename);
                FileUtils.copyInputStreamToFile(in, new File(filename));
            } catch (IOException e) {
                System.err.println("Can't extract " + filename);
                e.printStackTrace();
            }
        }
    }
}

/**
 * Delete native libraries in the current directory
 */
public static void removeNativeResources() {
    for(String filename: NATIVE_LIB_FILENAMES) {
        File file = new File(filename);
        file.delete();
    }
}

public static void main(String[] args) throws Exception {
    boolean deleteNativesOnExit = false;    // Delete natives on exit

    // Extract native libraries if sqlite4java.library.path property is not set
    String sqlitePath = System.getProperty("sqlite4java.library.path");
    if(sqlitePath == null) {
        System.setProperty("sqlite4java.library.path", "."); // Read natives from current directory
        extractNativeResources();
        deleteNativesOnExit = true;
    }

    // Do SQLite jobs here
    final SQLiteConnection db = new SQLiteConnection(new File("test.db"));
    try {
        db.open();
        db.dispose();
        System.out.println("Success");
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("FAILED");
    }

    // Delete the native libraries we extracted
    if(deleteNativesOnExit) removeNativeResources();
}

>

"jar-with-dependencies", "java -jar your_jar.jar".

, sqlite4java , .

, , , !

0

All Articles