Java Tess4J可以从源代码正常工作,但不能从JAR正常工作
我在Java Tess4J可以从源代码正常工作,但不能从JAR正常工作,java,dll,jar,tesseract,noclassdeffounderror,Java,Dll,Jar,Tesseract,Noclassdeffounderror,我在Java中使用maven作为构建系统和IntelliJ作为开发环境,我想做OCR 我添加了tess4j作为maven依赖项: <dependency> <groupId>net.sourceforge.tess4j</groupId> <artifactId>tess4j</artifactId> <version>LATEST</version> <!-- 4.2.1 --&g
Java
中使用maven
作为构建系统和IntelliJ
作为开发环境,我想做OCR
我添加了tess4j
作为maven依赖项:
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>LATEST</version> <!-- 4.2.1 -->
</dependency>
从IntelliJ
运行时,一切正常。从JAR
运行时,OCR
无法正确识别我的机器上的文本(例如,识别的文本是空字符串,但在IntelliJ
中,尽管图像相同,但仍能正确识别),但由于某些原因,很难用最少的测试用例重现。我只是在使用instance.doOCR(bufferedImage)
,没什么特别的
在doOCR()
之前,但它没有帮助
但是,JAR
的一些用户会出现以下错误:
java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.TessAPI
这表明JAR
中缺少了一些文件,但它们不是因为teseract
从JAR
中提取并加载DLL
以供使用
有关系吗
(通过安装固定)
我的pom.xml
构建插件:
<!-- Generate Target JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<!-- Drop the META-INF/maven folder -->
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${libraries.directory}</classpathPrefix>
<mainClass>LauncherClient</mainClass>
</manifest>
<manifestEntries>
<Built-By>Me</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- Copy JAR libraries to target folder -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${libraries.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven jar插件
3.1.0
假的
真的
${libraries.directory}
启动器客户端
我
org.apache.maven.plugins
maven依赖插件
3.1.1
复制依赖项
包裹
复制依赖项
${project.build.directory}/${libraries.directory}
假的
假的
真的
我有点绝望,因为这些奇怪的问题,所以我不知道还有什么可以让它完美地工作。所有用户(包括我自己)仅在Windows
上。我在windows10pro
上阅读这个论坛。
<!-- Generate Target JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<!-- Drop the META-INF/maven folder -->
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${libraries.directory}</classpathPrefix>
<mainClass>LauncherClient</mainClass>
</manifest>
<manifestEntries>
<Built-By>Me</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- Copy JAR libraries to target folder -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${libraries.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>