class not found when running maven jar

时间:2016-07-30 21:29:32

标签: java maven jar dependencies executable

First of all, I am new to creating maven projects. My java project has 2 dependencies. gson2.2.4, and sqlite-jdbc3.8.11.2. Both dependencies are fine when maven compiles. I have the maven-dependency-plugin exporting my dependencies to the jars root directory. When I try to run the generated jar I get class not found exceptions. sqlite-jdbc jar is right there in the root directory, but it isn't being found. This isn't a "how to compile using maven" it is a my maven doesn't generate a correct classpath problem.

Exception: java.lang.ClassNotFoundException: org.sqlite.JDBC

Created jar hierarchy:

client
  all the class files
META-INF
  maven
    eventually gets to pom.properties and pom.xml
  MANIFEST.MF
server
  main
    Server.class
  other files with .class files
gson-2.2.4.jar
sqlite-jdbc-3.8.11.2

MANIFEST.MF:

Manifest-Version: 1.0  
Archiver-Version: Plexus Archiver  
Built-By: Steve  
Class-Path: .  
Created-By: Apache Maven 3.3.9  
BuildJdk: 1.8.0_65  
Main-Class: server.main.Server  

pom.xml build tag

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>copy-dependencies</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <outputDirectory>${project.build.directory}/classes</outputDirectory>
            <overWriteReleases>false</overwritereleases>
            <overWiteSnapshots>false</overWriteSnapshots>
            <overWriteIfNewer>true</overwriteIfNewer>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <archive>
          <manifestEntries>
            <Class-Path>.</Class-Path>
            <Main-Class>server.main.Server</Main-Class>
          </manifestEntries>
        </archive>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.1</version>
      <configuration>
        <source>1.7</source>
        <target>1.7</source>
      </configuration>
    </plugin>
  </plugins>
</build>

0 个答案:

没有答案