2016-04-14 9 views
0

ich benutze mybatis 3.3.1 version und setzen mybatis konfigurationsdatei mybatis-conf.xml bei SqlSessionFactoryManager gefunden verzeichnis.mvn paket enthält nicht xml

I erstellt ausführbare-jar über mvn package aber SqlSessionFactoryManager einen Fehler

java.io.IOException sagen: Es konnte keine Ressource kr/stocktalk/Mybatis/Mybatis-conf.xml
bei org.apache finden. ibatis.io.Resources.getResourceAsStream (Resources.java:114)

Dies ist Codefragment von SqlSessionFactoryManager

try { 

    String resource = "kr/stocktalk/mybatis/mybatis-conf.xml"; 
    Reader reader = Resources.getResourceAsReader(resource); 

    if (sqlSessionFactory == null) { 
     sqlSessionFactory = new SqlSessionFactoryBuilder() 
       .build(reader); 
    } 
} catch (Exception e) { 
     e.printStackTrace(); 
} 

ich denke, die Ausnahme auftritt, dass mybatis-conf.xml ist ausführbar-jar nicht enthalten

Also habe ich versucht umfassen Code maven-jar-plugin innen

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <configuration> 
    <excludes> 
     <exclude>logback.xml</exclude> 
     </excludes> 
    <includes> 
     <include>**/*.xml</include> 
     <include>**/*.class</include> 
    </includes> 
    <archive> 
     <manifest> 
      <mainClass>kr.stocktalk.chat.ChatServer</mainClass> 
       <addClasspath>true</addClasspath> 
       <classpathPrefix>lib/</classpathPrefix> 
      </manifest> 
     </archive> 
    </configuration> 
</plugin> 

Aber keine XML-Dateien enthalten in ausführbarer-jar-Datei hinzuzufügen.

Wie kann ich * .xml-Dateien einschließen?

Hier ist alles pom.xml Code.

<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"> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    </properties> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>kr.stocktalk</groupId> 
    <artifactId>stocktalk-chat</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>java</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <mainClass>kr.stocktalk.chat.ChatServer</mainClass> 
        <!-- <arguments> <argument>foo</argument> <argument>bar</argument> </arguments> --> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <!-- <compilerArgument>-Xlint:all</compilerArgument> --> 
        <showWarnings>true</showWarnings> 
        <showDeprecation>true</showDeprecation> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.3</version> 
       <executions> 
        <execution> 
         <id>copy-dependencies</id> 
         <phase>package</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <!-- eclipse 에서는 target 밑의 lib 에 생성 됨 --> 
        <outputDirectory>target/lib</outputDirectory> 
        <overWriteIfNewer>true</overWriteIfNewer> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <excludes> 
         <exclude>logback.xml</exclude> 
        </excludes> 
        <includes> 
         <include>**/*.xml</include> 
         <include>**/*.class</include> 
        </includes> 
        <archive> 
         <manifest> 
          <mainClass>kr.stocktalk.chat.ChatServer</mainClass> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
     </plugins> 

     <resources> 
      <resource> 
       <directory>src/main/resources</directory> 
       <targetPath>${basedir}/target/resources</targetPath> 
      </resource> 
      <!-- <resource> 
       <directory>src/main/java</directory> 
       <targetPath>${basedir}/target</targetPath> 
       <excludes> 
        <exclude>*.java</exclude> 
       </excludes> 
      </resource> --> 
     </resources> 

    </build> 
    <dependencies> 
     <dependency> 
      <groupId>com.amazonaws</groupId> 
      <artifactId>aws-java-sdk-core</artifactId> 
      <version>1.10.68</version> 
     </dependency> 
     <dependency> 
      <groupId>com.amazonaws</groupId> 
      <artifactId>aws-java-sdk-datapipeline</artifactId> 
      <version>1.10.68</version> 
     </dependency> 
     <dependency> 
      <groupId>com.amazonaws</groupId> 
      <artifactId>aws-java-sdk-dynamodb</artifactId> 
      <version>1.10.68</version> 
     </dependency> 
     <dependency> 
      <groupId>com.ganyo</groupId> 
      <artifactId>gcm-server</artifactId> 
      <version>1.0.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.7</version> 
     </dependency> 
     <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-classic</artifactId> 
      <version>1.1.2</version> 
      <exclusions> 
       <exclusion> 
        <groupId>org.slf4j</groupId> 
        <artifactId>slf4j-api</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>jcl-over-slf4j</artifactId> 
      <version>1.7.7</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-api</artifactId> 
      <version>2.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-core</artifactId> 
      <version>2.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.mybatis</groupId> 
      <artifactId>mybatis</artifactId> 
      <version>3.3.1</version> 
     </dependency> 
     <dependency> 
      <groupId>io.netty</groupId> 
      <artifactId>netty-all</artifactId> 
      <version>4.0.36.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.projectlombok</groupId> 
      <artifactId>lombok</artifactId> 
      <version>1.16.8</version> 
     </dependency> 
     <dependency> 
      <groupId>com.google.code.gson</groupId> 
      <artifactId>gson</artifactId> 
      <version>2.6.2</version> 
     </dependency> 
     <dependency> 
      <groupId>net.sourceforge.jtds</groupId> 
      <artifactId>jtds</artifactId> 
      <version>1.3.1</version> 
     </dependency> 
    </dependencies> 
</project> 

Antwort

1

Ressourcen können über einen absoluten oder relativen Pfad zugreifen. Ihr Pfad "kr/stocktalk/mybatis/mybatis-conf.xml" ist relativ (relativ zur Klasse, in der er verwendet wird) - aber es sieht eher so aus, als wollten Sie einen absoluten Ressourcenpfad angeben.

Deshalb, wenn Ihre SqlSessionFactoryManager in dem Paket kr.stocktalk.mybatis ist, versucht es, die Ressource kr.stocktalk.mybatis.kr.stocktalk.mybatis.mybatis-conf.xml zu laden.

Sie sollten den Ressourcenpfad einen absoluten Pfad, indem Sie einen Schrägstrich am Anfang hinzu:

"/kr/stocktalk/mybatis/mybatis-conf.xml"

+0

Sie robert danken. Ich habe noch eine Frage. Ausführbare JAR-Datei, die mit 'mvn-Paket 'verpackt ist, aber keine XML-Dateien enthält. Wenn ich Dateien einschließen und den relativen Pfad 'mybatis-conf.xml' und'

Verwandte Themen