English 中文(简体)
Maven: 拼写目录路径以选择文件并部署
原标题:Maven : Specfying directory paths to pick the file and deploy
  • 时间:2012-05-23 14:55:03
  •  标签:
  • maven

我使用马文 2.2.1 版本作为 Java 应用程序的构建工具 。

使用这个 Maven 工具, 我正在一些目录中建立战争文件并将其复制到服务器( Tomcat ) 。

由以下线条进行的这项工作

<copy file="D:/MyProject/target/Test.war"
tofile="C:/Softwares/apache-tomcat-6.0.33/webapps/Test.war" />

这一切都很好工作。

在这里我的问题是, 与其硬编码目录目录目录目录路径, 我能否在别的地方?

我看过这些 src 目录的 project. building. directory 和目标目录的 project.building.output Directory , 能否在文件中指定此属性名称?

请引导我, 提前感谢。

最佳回答

对于战争之路,你可以使用在马文建的地产:

${project.build.directory}/${project.build.finalName}.${project.packaging}

您想要将部署路径设置为自定义 Maven 属性。 有几种方法可以做到这一点。 一个人将它直接设置在 pom 中, 比如 :

<properties>
  <deploy.path>C:/Softwares/apache-tomcat-6.0.33/webapps/Test.war</deploy.path>
</properties>

然而,这仍然很难编码 路径在波姆, 只是在一个变量中。

另一种方式是使用 < a href=> http:// mojo.codehaus.org/ properties- maven- plugin/ plugin- info.html" rel=“ nofollow” > properities-maven-plutin 在属性文件中读取。 这样可以将用户特定的设置保存在 pom 之外, 您可以将您的属性文件保存在源控制之外。 但是, 这不是马文最喜欢的做法, 并且该插件在未来版本中可能不再支持 。

Maven 这样做的方法是将您的部署路径存储在 ~/.m2/ sembts. xml 文件中。 此属性会进入一个配置文件, 默认情况下可以激活。 解释请参见 < a href=" http:// maven. apache. org/ examples/ inpinting- properities-via- sebts. html" rel=“ nofollow” > this page

一旦您安装了. path 变量集, 请更改您的复制语句, 使其看起来像这样 :

<copy file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
    tofile="${deploy.path}" />

编辑 :

在最起码的例子项目上,为我设定了以下属性:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
      <execution>
        <id>compile</id>
        <phase>compile</phase>
        <configuration>
          <target>
            <echo message="project.build.directory: ${project.build.directory}"/>
            <echo message="project.build.finalName: ${project.build.finalName}"/>
            <echo message="project.packaging: ${project.packaging}"/>           
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

如果那些地产没有为您设置好, 你能张贴你的pom.xml吗?

问题回答

暂无回答




相关问题
JavaFX with Maven [closed]

I recently started a JavaFX project, and I d like to use Maven as my compiler/deployment tool. Is there a good tutorial or plugin to integrate JavaFX and Maven?

How to upload jar to respository?

I have jar files that cannot be found on Maven Central repository. I would like to add the jar so I can just include extra tag in my pom.xml file and other developer can use the jar. What are the ...

Debug Maven project in Eclipse with third party sources

I am currently developing a maven project in eclipse. The m2eclipse plugin works beautifully. It even works out of the box with debugging. But when I am debugging open source third party libarries. ...

Could Free Pascal benefit of something like Apache Maven?

Apache Maven is a very popular build and dependency management tool in the Java open source ecosphere. I did some tests to find out if it can handle compiled Free Pascal / Delphi units and found it ...

Run a single test method with maven

I know you can run all the tests in a certain class using: mvn test -Dtest=classname But I want to run an individual method and -Dtest=classname.methodname doesn t seem to work.

Uploading a directory using sftp with Maven

How can I upload a directory - Eclipse update site - using sftp with public key authentication in Maven? For background information: I m using tycho to build an Eclipse plugin and want to get the ...

What are solid NMaven or build servers for .NET alternatives?

Maven had a long history and is well supported in the Java world. NMaven has received a less successful start and has never become as popular in the C#/.NET world as its larger cousin was in the Java ...

热门标签