2016-07-04 111 views
-2

我想用maven运行批处理文件。运行.bat文件 - Maven/Eclipse

我的pom.xml看起来是这样的:

<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"> 
    <modelVersion>4.0.0</modelVersion> 
    <artifactId>test--clients</artifactId> 
    <packaging>war</packaging> 
    <name>test--clients</name> 


    <parent> 
     <artifactId>test--app</artifactId> 
     <groupId>de.timetoact.test-</groupId> 
     <version>10.0.0</version> 
    </parent> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.0</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <!-- <properties> --> 
    <!-- <maven.compile.source>1.6</maven.compile.source> --> 
    <!-- <maven.compile.target>1.6</maven.compile.target> --> 
    <!-- <failOnMissingWebXml>false</failOnMissingWebXml> --> 
    <!-- </properties> --> 

    <dependencies> 

     <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.8</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.mail</groupId> 
      <artifactId>mail</artifactId> 
      <version>1.4.7</version> 
     </dependency> 

     <dependency> 
      <groupId>org.mockito</groupId> 
      <artifactId>mockito-all</artifactId> 
      <version>1.9.5</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-api</artifactId> 
      <version>6.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.cloudfoundry</groupId> 
      <artifactId>cloudfoundry-client-lib</artifactId> 
      <version>1.0.2</version> 
     </dependency> 
<!--  <dependency> --> 
<!--   <groupId>org.springframework.security.oauth</groupId> --> 
<!--   <artifactId>spring-security-oauth2</artifactId> --> 
<!--   <version>1.0.0.RELEASE</version> --> 
<!--   <exclusions> --> 
<!--    <exclusion> --> 
<!--     <groupId>org.springframework</groupId> --> 
<!--     <artifactId>spring-jdbc</artifactId> --> 
<!--    </exclusion> --> 
<!--   </exclusions> --> 
<!--  </dependency> --> 
     <dependency> 
      <groupId>com.ibm.sbt</groupId> 
      <artifactId>com.ibm.commons</artifactId> 
      <version>9.0.0</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-fileupload</groupId> 
      <artifactId>commons-fileupload</artifactId> 
      <version>1.3.1</version> 
     </dependency> 

     <dependency> 
      <groupId>de.timetoact.test-</groupId> 
      <artifactId>test--util</artifactId> 
      <version>10.0.0</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-codec</groupId> 
      <artifactId>commons-codec</artifactId> 
      <version>1.9</version> 
     </dependency> 
    </dependencies> 


    <profiles> 
     <profile> 
      <id>test--clients-deploy-eu</id> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.cloudfoundry</groupId> 
         <artifactId>cf-maven-plugin</artifactId> 
         <version>1.1.2</version> 
         <configuration> 
          <server>bluemix</server> 
          <target>https://api.eu-gb.bluemix.net</target> 
          <org>test-</org> 
          <space>test--clients-eu</space> 
          <appname>test--clients</appname> 
          <urls> 
           <url>test--clients.eu-gb.mybluemix.net</url> 
           <url>test--client.eu-gb.mybluemix.net</url> 
          </urls> 

          <memory>192</memory> 
          <services> 
           <service> 
            <name>test-</name> 
            <label>postgresql</label> 
            <plan>100</plan> 
           </service> 
          </services> 
         </configuration> 
         <executions> 
          <execution> 
           <phase>package</phase> 
           <goals> 
            <goal>push</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 

     </profile> 
     <profile> 
      <id>test--dev-deploy-eu</id> 
      <build> 
       <plugins> 

    <plugin> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.8</version> 
     <executions> 
      <execution> 
      <phase>generate-sources</phase> 
      <configuration> 
       <tasks> 
       <exec 
        dir="${project.basedir}" 
        executable="${project.basedir}/test.bat" 
        failonerror="true"> 
        <arg line="/c" /> 
       </exec> 
       </tasks> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 



        <plugin> 
         <groupId>org.cloudfoundry</groupId> 
         <artifactId>cf-maven-plugin</artifactId> 
         <version>1.1.2</version> 
         <configuration> 
          <server>bluemix</server> 
          <target>https://api.eu-gb.bluemix.net</target> 
          <org>test-</org> 
          <space>test--dev-eu</space> 
          <appname>test--clients</appname> 
          <urls> 
           <url>test--clients-dev.eu-gb.mybluemix.net</url> 
           <url>test--client-dev.eu-gb.mybluemix.net</url> 
          </urls> 

          <memory>192</memory> 
          <services> 
           <service> 
            <name>test-</name> 
            <label>postgresql</label> 
            <plan>100</plan> 
           </service> 
          </services> 
         </configuration> 
         <executions> 
          <execution> 
           <phase>package</phase> 
           <goals> 
            <goal>push</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 

     </profile> 
     <profile> 
      <id>test--clients-deploy-us</id> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.cloudfoundry</groupId> 
         <artifactId>cf-maven-plugin</artifactId> 
         <version>1.1.2</version> 
         <configuration> 
          <server>bluemix</server> 
          <target>https://api.ng.bluemix.net</target> 
          <org>test-</org> 
          <space>test--clients-us</space> 
          <appname>test--clients</appname> 
          <urls> 
           <url>test--clients.mybluemix.net</url> 
           <url>test--client.mybluemix.net</url> 
          </urls> 
          <memory>192</memory> 
          <services> 
           <service> 
            <name>test-</name> 
            <label>postgresql</label> 
            <plan>100</plan> 
           </service> 
          </services> 
         </configuration> 
         <executions> 
          <execution> 
           <phase>package</phase> 
           <goals> 
            <goal>push</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 

     </profile> 
    </profiles> 

</project> 

我得到的输出是:

[INFO] Executing tasks 
[INFO] Executed tasks 

但.bat文件没有被调用。

在Stackoverflow尝试了很多答案我已经绝望了。

这里有什么问题?

+0

什么批处理文件是你想打电话? – Revive

回答

1

您正试图使用​​maven-antrun-plugin来调用批处理脚本。如果您仍然想这样做,看看这个教程run cmd with maven ant plugin或者你可以使用maven-exec-plugin运行批处理脚本:

  <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <executions> 
        <execution> 
         <phase>generate-sources</phase> 
         <configuration> 
          <executable>cmd</executable> 
          <workingDirectory></workingDirectory> 
          <arguments> 
           <argument>/C</argument> 
           <argument>"${project.basedir}/test.bat"</argument> 
          </arguments> 
         </configuration> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
        </execution>        
       </executions> 
      </plugin>