使用exec插件从Maven 3执行脚本 - 被阻止

时间:2011-10-18 10:13:13

标签: bash shell maven maven-3 maven-site-plugin

这就是我面临的情况:目前我有两个Maven项目,一个除了描述依赖项,存储库等(父项)和继承另一个pom.xml的子项之外什么都不做。将来会创建更多模块,遵循与孩子相同的模型。

我们决定将项目的网站(使用maven-site-plugin生成)部署到此时只能通过 sftp 访问的位置。我发现无法在<distributionManagement>中定义站点位置,因为我无法集成sftp协议(我尝试使用wagon-ssh-external)。

因此,我创建了一个连接到远程计算机的脚本,并在站点部署阶段上传我们站点部署的本地文件夹的内容:

echo "Uploading the site.."
lftp -u ${username},${password} sftp://${host} <<EOF
mirror -R --delete-first $sitedir $remotedir
echo "Exiting from lftp.."
bye
EOF
echo "Terminating script execution.."

这适用于父网站,在本地创建网站后立即上传网站,但当儿童到达脚本末尾时,它无法正常完成,打印Terminating script execution..并停留在那里。 / p>

我正在使用Eclipse,最新版本(3.7)和默认的Maven插件(v.3.0.2)。要在Eclipse中生成和部署站点,我右键单击了父项目&gt;以&gt;运行Maven build ...&gt; parent clean site-deploy

这些是父母pom.xml的一部分:

<distributionManagement>
 <!-- Generate the site locally, then it'll be uploaded to the server -->
 <!-- Children will append their artifact ID to the base url  -->
 <site>
  <id>project-name</id>
  <name>Project Name</name>
  <url>file://${env.HOME}/testsite/</url>
 </site>
</distributionManagement>
...
<build> 
<pluginManagement>
 <plugins>
  <plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <version>1.2.1</version>
  </plugin>
 </plugins>
</pluginManagement>
<plugins>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-site-plugin</artifactId>
  <version>3.0</version>
  <configuration>
    ...
 </plugin>
 <plugin>
  <groupId>org.codehaus.mojo</groupId>          
  <artifactId>exec-maven-plugin</artifactId>
  <inherited>false</inherited>
  <executions>
   <execution>
    <id>sh</id>
    <phase>site-deploy</phase>
    <goals>
     <goal>exec</goal>
    </goals>
    <configuration>
     <executable>sh</executable>
     <arguments>
      <argument>publish-site.sh</argument>
      <argument>${localsitedir}</argument>
      ...
     </arguments>
    </configuration>
   </execution>
  </executions>
 </plugin>
</plugins>
</build>

来自孩子:

<build>
 <plugin>
  <groupId>org.codehaus.mojo</groupId>          
  <artifactId>exec-maven-plugin</artifactId>
  <executions>
   <execution>
    <id>sh</id>
    <phase>site-deploy</phase>          
    <goals>
     <goal>exec</goal>
    </goals>
    <configuration>
     <executable>sh</executable>
     <arguments>
      <argument>../parent/publish-site.sh</argument>
      <argument>${localsitedir}/child</argument>
      ...
     </arguments>
    </configuration>
   </execution>
  </executions>
 </plugin>
</build>

我尝试过不同的方法来配置 exec 插件(不使用pluginManagement,继承父插件的插件,只重写参数部分等等。)和它在完成脚本时总是被阻止,并且不会结束执行。

网站上传正确,但当然,我不希望每次要更新网站时手动终止Maven构建执行(同时,计划将工件从项目部署到Jenkins服务器,所以网站部署有望在那时工作。

1 个答案:

答案 0 :(得分:0)

我的回答是基于很多猜测...我遇到了一个类似的问题,关于SSH命令没有终止,原因是:

也许&#39; lftp&#39;启动一个不退出的进程,也许(可能),maven-exec插件在stdout和stderr上循环,以便在退出之前打印所有相关消息。如果所有作家都没有关闭,那就会卡住。

尝试重定向&lt; lftp&#39;的输出到/ dev / null,以防万一。