2014-04-15 3 views
1

현재 build.xml이있는 프로젝트가 있습니다. 이 빌드에는 something.jar을 호출하는 CreateDB 명령이 있습니다. 이 jar는 일부 sql 스크립트 (mysql db)를 실행합니다. 이제 명령을 실행하여이 명령을 실행할 수 있습니다.Maven 및 mysql 종속성

ant CreateDB 

명령 줄에서 실행할 수 있습니다. 하지만 지금, 나는 더 많은 것을 할 필요가 있습니다. Maven을 사용하여 응용 프로그램을 빌드 할 때 해당 ant 명령을 실행하려고합니다. 내가 MySQL 용 커넥터가없는 것 같다,이 메시지에 따르면

org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.gjt.mm.mysql.Driver' 

: 그래서, 나는이 pom.xml 파일 (아래 참조)을 생성하지만, 작동하지 않는,이 오류가 발생했습니다 그러나 나는 그것을 나의 의존에 명시했다. 그래서 내가 뭘 잘못 했니?

의 pom.xml :

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
     xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.dl.test</groupId> 
    <artifactId>toto</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <name>toto</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.23</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.6</version> 
     <executions> 
      <execution> 
      <id>mysql</id> 
      <phase>integration-test</phase> 
      <configuration> 
       <tasks> 
       <!-- For MySql --> 
       <ant antfile="path\build.xml" target="createDB" /> 
       </tasks> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

답변

0

자동으로 받는다는 종속성을 상속하지 않는 받는다는 antrun 플러그인에 의해 시작 개미 작업.

maven.test.classpath 속성을 통해 사용할 수있는 build.xml 코드에서 명시 적으로 maven 테스트 클래스 경로를 참조해야합니다.

그래서 다음과 유사하게 보일 수 있습니다 귀하의 실행 (test.classpath은 또한 당신의 build.xml에서 참조 할 필요가)

: 또한

<execution> 
    <id>mysql</id> 
    <phase>integration-test</phase> 
    <configuration> 
     <tasks> 
     <!-- For MySql --> 
     <property name="test_classpath" refid="maven.test.classpath"/> 
     <ant antfile="path\build.xml" target="createDB" /> 
     </tasks> 
    </configuration> 
    <goals> 
     <goal>run</goal> 
    </goals> 
</execution> 

참조 : Maven AntRun Plugin - Referencing the Maven Classpaths