执行使用Maven cmd命令 [英] Executing cmd command using Maven
问题描述
我要执行这个命令:
zipalign [-f] [-v] <alignment> infile.apk outfile.apk
使用Maven。我已经在Android SDK / tools目录来执行此命令。谁能帮我对如何做到这一点?我认为这是可以使用批处理文件来完成,但我不知道如何创建一个批处理文件。我需要当我输入MVN全新安装要执行该命令。谢谢
Using Maven. I have to execute this command in the Android SDK/ tools directory. Can anyone help me on how to do this? I think this can be done using batch file but I am not sure how to create a batch file. I need this command to be executed when I type "mvn clean install". Thanks
推荐答案
您可以使用 的Maven Exec插件 绑定到安装
阶段。
在下面的片段中,commant 平
通过参数 8.8.8.8
将每隔你做一次执行一个 MVN安装
:
In the snippet below, the commant ping
with the argument 8.8.8.8
will be executed every time you do a mvn install
:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.2.1</version>
<executions>
<execution>
<id>My Command Runner</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>ping</executable>
<arguments>
<argument>8.8.8.8</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
&NBSP;结果
就是这样。
And that's it.
&NBSP;
&NBSP;
我现在真的具有正在执行的zipalign ,不是任意命令的麻烦什么看。为此,有两种方法。
I see now what you really having trouble with is executing zipalign, not an arbitrary command. For that, there are two ways.
由于Android Maven插件发布2.5.0的的zipalign
目标是插件的一部分。要激活只需将目标的zipalign
作为执行(例如,在包
相),并设置跳过
在插件参数
配置
到假
:
As of release 2.5.0 of the Android Maven Plugin the zipalign
goal is part of the plugin. To activate simply add the goal zipalign
as an execution (e.g. to the package
phase) and set the skip
parameter in the plugin
configuration
to false
:
<zipalign><skip>false</skip></zipalign>
全部&LT;&插件GT;
标记示例:
Full <plugin>
tag example:
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<sign>
<debug>false</debug>
</sign>
<zipalign>
<verbose>true</verbose>
<inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk>
<outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk
</outputApk>
</zipalign>
</configuration>
<executions>
<execution>
<id>alignApk</id>
<phase>package</phase>
<goals>
<goal>zipalign</goal>
</goals>
</execution>
</executions>
</plugin>
来源:
- 在这里,你会发现使用旧版本的一个例子(还是叫
Android的Maven的插件
); - ZipalignAPKBuiltByMAven :介绍如何自动的zipalign已通过的Maven构建的APK。
- Simpligility :Android版的Maven插件用的zipalign和改进的验证
- 又如:<一href=\"https://$c$c.google.com/p/osmdroid/source/browse/trunk/OpenStreetMapViewer/pom.xml?spec=svn1159&r=1159\"相对=nofollow>全
的pom.xml
使用了的zipalign
。
- Here you'll find an example using the an older version (still called
android-maven-plugin
); - ZipalignAPKBuiltByMAven: Describes how to automatically zipalign an APK that has been built by Maven.
- Simpligility: Maven Android Plugin with zipalign and improved verification
- Another example: A full
pom.xml
that uses thezipalign
.
在code下面将拉链对准的功能结合到包
阶段,覆盖previous的zip文件排列不问。
The code below will bind the functionality of zip aligning to the package
phase, overwriting previous zip aligned file without asking.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>zipalign</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>${ANDROID_HOME}/tools/zipalign</executable>
<arguments>
<argument>-f</argument>
<argument>4</argument>
<argument>target/${project.build.finalName}.apk</argument>
<argument>target/${project.build.finalName}-zipped.apk</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
请注意,此配置文件已被添加到POM实际APK。你可以把它添加到一个父POM。这样做的原因是,它使用定义假象名Maven的财产( project.build.finalName
)。
Please note that this profile has to be added to the pom for the actual APK. You can't add it to a parent pom. The reason for this is that it uses the Maven property that defines the artefact name (project.build.finalName
).
这篇关于执行使用Maven cmd命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!