Jena TDB java.lang.ExceptionInInitializerError

守給你的承諾、 提交于 2019-11-28 11:32:28
AndyS

The POM uses the shade plugin. It needs to manage services files (META_INF/services/) with a ServicesResourceTransformer transformer.

Add the following transformed to your POM file:

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />

See <transformers> here for example: https://github.com/apache/jena/blob/master/jena-fuseki2/jena-fuseki-server/pom.xml

I had the same problem and found that the accepted answer is in general correct but not complete (at least it took me quite a while before I figured out how to apply the tip of the answer correctly). Here is how it works.

1) You have to add the maven-shade plugin to you pom.xml as demonstrated e.g. in: https://github.com/apache/jena/blob/master/jena-fuseki2/jena-fuseki-server/pom.xml

2) Change the link to the main class in the plugin configuration. The main class is provided via the following lines:

<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
          <mainClass>org.apache.jena.fuseki.cmd.FusekiCmd</mainClass>
</transformer>

You have to add you main class in the mainClass tag. When now building the project using the maven build command, you will get a jar called your-project-name-VERSION.jar which is the runnable jar you want to have. If you previously worked with a "jar with dependencies", then make sure to run the new one (which does not include the "with dependencies" in the name anymore) as otherwise you will run into the same problem.

The accepted answer is actually missing the solution. So here it is:

The linked file is: https://github.com/apache/jena/blob/master/jena-fuseki2/jena-fuseki-server/pom.xml

Of course, what should you get from it?

Here is the complete fragment that you should add to your pom:

<build>     
<plugins>     
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.1</version>

    <executions>    
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>com.example.MainClass</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

remember to replace the com.example.MainClass with your main class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!