0

I work with a project in Eclipse with Mysql, SpringFramework, Maven and Jetty. I run the server with the goal:

jetty:run

Part of the pom.xml is:

   <build>

        <plugins>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sql-maven-plugin</artifactId>
                <version>1.5</version>

                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.21</version>
                    </dependency>
                </dependencies>

                <configuration>
                    <driver>com.mysql.jdbc.Driver</driver>
                    <url>jdbc:mysql://localhost:3306/bd</url>
                    <username>root</username>
                    <password></password>
                </configuration>

                <executions>
                    <execution>
                        <id>default-cli</id>
                        <configuration>
                            <delimiterType>row</delimiterType>
                            <autocommit>true</autocommit>
                            <srcFiles>
                                <srcFile>src/main/resources/sql/trigger.sql</srcFile>
                            </srcFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.26</version>
                <configuration>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                </configuration>
            </plugin>

        </plugins>

    </build>

The file trigger.sql is:

CREATE TRIGGER `ondeleteforum` 
BEFORE 
DELETE ON  `forum` 
FOR EACH ROW 
BEGIN 
INSERT INTO deletedforums( forumId, courseId, timeDeleted ) 
VALUES (OLD.id, OLD.course, UNIX_TIMESTAMP( ));
END
;

Questions:

Why the Sql Maven Plugin is not execut when run the Jetty server?

How to solve it?

Goal:

Create the trigger in the database when the server is deployed.

Thanks in advance.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
mlozdev
  • 137
  • 1
  • 4
  • 12
  • Simple answer is cause you don't started an life cylce. You just called a goal `jetty:run`. So the sql-maven-plugin can't run. – khmarbaise Nov 22 '14 at 17:03
  • This scenario looks like integration testing. So you should bound sql-maven-plugin to pre-integration-test phase and bound jetty to integration-test...and than you can do `mvn verify` (That's not the best but a solution. If you can give more details on what you like achieve i can improve my answer). – khmarbaise Nov 22 '14 at 17:04
  • @khmarbaise. Is it possible to call a goal jetty:run and run the sql-maven-plugin? – mlozdev Nov 22 '14 at 18:53

0 Answers0