内容:


Linux 64位Debian
Java JDK 1.8.0_181
CEF_VERSION 75.0.13 + g2c92fcd + chromium-75.0.3770.100放入CMakeLists.txt
提交467f8fc 2019-07-02


这是项目树:

.
├── pom.yml
├── java-cef/. <------- the cloned java-cef repository
├── lib/ <------------- where builded jar cef and dependencies are stored
|   ├── jogamp/gluegen/1.0/gluegen-1.0.jar
|   ├── jogamp/jogl/1.0/jogl-1.0.jar
|   └── org/cef/1.0/cef-1.0.jar
└── src/


我正在构建JCEF本机源,以下是以下命令:

# Build the JCEF natives and jar
cd java-cef
mkdir jcef_build && cd jcef_build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make -j4
cd ../tools
./compile.sh linux64
./make_jar.sh linux64

# Install the CEF jar and it's jar dependencies into lib/ folder
cd ../../
mvn install:install-file -Dfile=java-cef/out/linux64/jcef.jar -DgroupId=org -DartifactId=cef -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=lib
mvn install:install-file -Dfile=java-cef/third_party/jogamp/jar/jogl-all-natives-linux-amd64.jar -DgroupId=jogamp -DartifactId=jogl -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=lib
mvn install:install-file -Dfile=java-cef/third_party/jogamp/jar/gluegen-rt.jar -DgroupId=jogamp -DartifactId=gluegen -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=lib

# Link to avoid ICU internal errors of CEF
ln -s $PWD/native/Release/icudtl.dat $JAVA_HOME/jre/bin/icudtl.dat
ln -s $PWD/native/Release/natives_blob.bin $JAVA_HOME/jre/bin/natives_blob.bin
ln -s $PWD/native/Release/snapshot_blob.bin $JAVA_HOME/jre/bin/snapshot_blob.bin

mvn install


这是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>my.app</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <dependencies>
    <!-- JCEF dependencies -->
        <dependency>
            <groupId>org</groupId>
            <artifactId>cef</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>jogamp</groupId>
            <artifactId>gluegen</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>jogamp</groupId>
            <artifactId>jogl</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- All about bash/bat creation -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>2.0.0</version>
                <configuration>
                    <programs>
                        <!-- generic -->
                        <program>
                            <mainClass>my.app.boot.Boot</mainClass>
                            <id>player</id>
                            <jvmSettings>
                                <extraArguments>
                                    <extraArgument>-Djava.library.path=${project.basedir}/java-cef/jcef_build/native/Release:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib</extraArgument>
                                </extraArguments>
                            </jvmSettings>
                        </program>
                    </programs>
                    <assembleDirectory>${project.basedir}</assembleDirectory>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


问题 :

当src代码运行CefApp.getInstance(args, settings).getVersion();时,它返回null并引发以下错误:

Caused by: java.lang.UnsatisfiedLinkError: org.cef.CefApp.N_PreInitialize()Z
    at org.cef.CefApp.N_PreInitialize(Native Method)
    at org.cef.CefApp.access$000(CefApp.java:24)
    at org.cef.CefApp$1.run(CefApp.java:162)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    ...

java.lang.UnsatisfiedLinkError: org.cef.CefApp.N_GetVersion()Lorg/cef/CefApp$CefVersion;
    at org.cef.CefApp.N_GetVersion(Native Method)
    at org.cef.CefApp.getVersion(CefApp.java:235)
    at my.app.boot.Browser.<init>(Browser.java:42)
    at my.app.boot.Boot.main(Boot.java:52)


任何想法 ?

最佳答案

Answer is at following link

CefApp.startup();的任何调用之前先调用CefApp.getInstance()使其加载libjcef.so。

10-06 10:43