在 Maven 中,如何使用 wagon 插件复制文件?

发布于 2024-11-14 22:14:45 字数 885 浏览 2 评论 0原文

摘要: 如何使用 Maven 将一些生成的文件复制到 Web 服务器(例如 IIS 或 Apache)目录中?

细节: 我有一个在 Maven 中构建的工作应用程序。我已经设法使用 webstart-maven-plugin 构建它在目录 target/jnlp 中生成所有需要的文件(.jar 和 .jnlp)。它还创建一个 zip 文件,将它们全部放在 target/foo-1.0.zip 中。

目前,webstart 插件没有 deploy 目标 - 对它的请求已结束于 常见问题解答(问题 3)。将来可能会实现,但暂时建议使用 wagon- maven-插件

我从来没有用过瓦格。首先,我只想将文件复制到网络服务器提供的本地目录中。稍后我想远程复制它们,可能使用 ftp。有人可以举例说明我需要添加到 pom.xml 中才能使本地副本正常工作(希望还有 ftp 示例吗?)。我在文档中找不到它。通过阅读,我认为我可能还需要 Wagon Maven File Provider 但是因为这似乎几乎没有文档,我不确定。

Summary: How do I copy some generated files into a webserver (eg IIS or Apache) directory using Maven?

Details:
I have a working application that builds in Maven. I've managed to get it building using the webstart-maven-plugin which produces all the needed files (.jar and .jnlp) in a directory target/jnlp. It also creates a zip file with them all in at target/foo-1.0.zip.

At the moment the webstart plugin does not have a deploy goal - the request for it has ended up on the FAQ (question 3). It may be implemented in future, but the suggestion for the time being is to use wagon-maven-plugin.

I've never used Wagon. To start with I'd like to just copy the files to a local directory served up by a webserver. Later I'd like to copy them remotely, probably using ftp. Can someone give an example to what I need to add to the pom.xml to get the local copy working (and hopefully an ftp example too?). I can't find it in the documentation. From reading I think I might also need the Wagon Maven File Provider but as this seems to have almost no documentation I'm not sure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风为裳 2024-11-21 22:14:45

Wagon 提供商仅提供额外的网络协议支持(例如 FTP)。

如果您想将文件复制到网络服务器(本地或远程),您可以使用 Maven 上传插件:

...
<plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-upload-plugin</artifactId>
</plugin>
...

在父 pom 中:

            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-upload-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <resourceSrc>
                        ${project.build.directory}/${project.build.finalName}.${project.packaging}
                    </resourceSrc>
                    <resourceDest>${jboss.deployDir}</resourceDest>
                    <serverId>${jboss.host}</serverId>
                    <url>${jboss.deployUrl}</url>
                </configuration>
            </plugin>

为了以智能方式配置参数,我使用 Maven 配置文件(在父 pom 中):

<profiles>
    <!-- local deployment -->
    <profile>
        <id>developpement</id>
        <properties>
            <jboss.host>localhost</jboss.host>
            <jboss.deployDir>appli/jboss-4.0.4.GA/server/default/deploy/</jboss.deployDir>
            <jboss.deployUrl>file://C:/</jboss.deployUrl>
        </properties>
    </profile>
    <!-- distant deployment -->
    <profile>
        <id>validation</id>
        <properties>
            <jboss.host>ENV_val</jboss.host>
            <jboss.deployDir>/home/envval/jboss/server/default/deploy/</jboss.deployDir>
            <jboss.deployUrl>scp://PROJECT_LAN_HOST</jboss.deployUrl>
        </properties>
    </profile>
</profiles>

我创建了一个“ ant launcher”,通过在 Eclipse ant 视图下单击来使用它:

<target name="copy war to JBoss local" description="Copy war to local JBoss">
    <maven goal="upload:upload" options="-Pdeveloppement" />
</target>

但您可以简单地在命令行上运行它:

mvn upload:upload -Pdeveloppement

编辑:顺便说一下,对于远程部署,您可能需要 scp 的登录密码到 工作。您必须将它们添加到 Maven settings.xml 文件中:

<settings>
  ...
  <servers>
    <server>
      <id>ENV_val</id>
      <username>login</username>
      <password>password</password>
    </server>
  </servers>
  ...
</settings>

编辑:您需要添加 Atlassian 存储库:

    <pluginRepositories>
    <pluginRepository>
        <id>Atlassian</id>
        <url>https://maven.atlassian.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>   

编辑:取决于您将拥有的远程协议要添加 Wagon 扩展,请参阅 使用 sftp 上传目录Maven

Wagon providers are only there to provide additional network protocol supports (such as FTP).

If you want to copy file to a webserver (local or distant) you can use Maven upload plugin :

...
<plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-upload-plugin</artifactId>
</plugin>
...

In parent pom :

            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-upload-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <resourceSrc>
                        ${project.build.directory}/${project.build.finalName}.${project.packaging}
                    </resourceSrc>
                    <resourceDest>${jboss.deployDir}</resourceDest>
                    <serverId>${jboss.host}</serverId>
                    <url>${jboss.deployUrl}</url>
                </configuration>
            </plugin>

And to configure parameters in a smart way, I use maven profiles (in parent pom) :

<profiles>
    <!-- local deployment -->
    <profile>
        <id>developpement</id>
        <properties>
            <jboss.host>localhost</jboss.host>
            <jboss.deployDir>appli/jboss-4.0.4.GA/server/default/deploy/</jboss.deployDir>
            <jboss.deployUrl>file://C:/</jboss.deployUrl>
        </properties>
    </profile>
    <!-- distant deployment -->
    <profile>
        <id>validation</id>
        <properties>
            <jboss.host>ENV_val</jboss.host>
            <jboss.deployDir>/home/envval/jboss/server/default/deploy/</jboss.deployDir>
            <jboss.deployUrl>scp://PROJECT_LAN_HOST</jboss.deployUrl>
        </properties>
    </profile>
</profiles>

I've created an "ant launcher", to use it by clicking under Eclipse ant view :

<target name="copy war to JBoss local" description="Copy war to local JBoss">
    <maven goal="upload:upload" options="-Pdeveloppement" />
</target>

But you can simply run it on a command line :

mvn upload:upload -Pdeveloppement

EDIT : By the way, for distant deployment, you may need a login password for scp to work. You have to add them to you Maven settings.xml file :

<settings>
  ...
  <servers>
    <server>
      <id>ENV_val</id>
      <username>login</username>
      <password>password</password>
    </server>
  </servers>
  ...
</settings>

EDIT: You'll need to add the Atlassian repository:

    <pluginRepositories>
    <pluginRepository>
        <id>Atlassian</id>
        <url>https://maven.atlassian.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>   

EDIT: depending upong the remote protocol you'll have to add wagon extensions, see Uploading a directory using sftp with Maven

蓝梦月影 2024-11-21 22:14:45

最后我没有使用 Maven 上传插件 - 它似乎有点有限,并且不是主要 Maven 发行版的一部分。我按照建议使用了 Maven Wagon 插件。这是我可以做到的最简单的 pom。希望其他人会发现它有用,因为我无法轻松找到类似的东西。

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>wagon-maven-plugin</artifactId>
    <version>1.0-beta-3</version>
    <configuration>
      <fromDir>${project.build.directory}/jnlp</fromDir>
      <includes>*</includes>
      <url>file://c:/inetpub/wwwroot</url>
      <toDir>jnlp</toDir>
    </configuration>
  </plugin>

对于远程分发,您只需更改 URL 类型,并可能根据需要添加货车扩展。

In the end I didn't use the Maven upload plugin - it seemed a bit limited and not part of the main maven distribution. I used the maven wagon plugin as suggested. Here is the simplest possible pom that I could make that worked. Hopefully others will find it useful, as I couldn't find anything similar easily.

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>wagon-maven-plugin</artifactId>
    <version>1.0-beta-3</version>
    <configuration>
      <fromDir>${project.build.directory}/jnlp</fromDir>
      <includes>*</includes>
      <url>file://c:/inetpub/wwwroot</url>
      <toDir>jnlp</toDir>
    </configuration>
  </plugin>

For remote distributions, you just change the URL type, and possibly add wagon extensions as necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文