使用maven构建的Java Web应用程序,用于Android战争部署

时间:2013-08-12 12:47:00

标签: java android maven

我正在使用Maven构建我的Java Web应用程序。它将.class文件转换为dalvik可读文件。 我生成war文件并将其放在我的Android设备上的i-Jetty服务器上(webapps / hello / hello.war)。

这是 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>MyWebApp</artifactId>
  <groupId>com.example.mwa</groupId>
  <name>MyWebApp</name>
  <version>1.0</version>
  <packaging>war</packaging>
  <url>http://maven.apache.org</url>
  <properties>
     <android.version>1.6_r2</android.version>
     <jetty.version>7.6.0.RC4</jetty.version>
     <servlet.version>2.5-20081211</servlet.version>
  </properties>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
          <verbose>false</verbose>
        </configuration>
      </plugin>

      <!-- Convert the compiled classes into a clases.dex. -->
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <id>generate-dex</id>
        <phase>process-classes</phase>
        <goals>
          <goal>exec</goal>
        </goals>
        <configuration>
          <!-- executable>${env.ANDROID_HOME}/platform-tools/dx</executable -->
          <executable>java</executable>
          <arguments>
           <!-- <argument>-JXmx1024M</argument> -->
            <argument>-jar</argument>
            <argument>${env.ANDROID_HOME}/build-tools/android-4.2.2/lib/dx.jar</argument>
            <argument>--dex</argument>
            <argument>--verbose</argument>
            <argument>--core-library</argument>
            <argument>--output=${project.build.directory}/classes.dex</argument>
            <argument>--positions=lines</argument>
            <argument>${project.build.directory}/classes/</argument>
          </arguments>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <id>copydex</id>
        <phase>process-classes</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
            <mkdir
              dir="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/lib" />
            <jar
              basedir="${project.build.directory}"
              update="true"
              includes="classes.dex"
              destfile="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/lib/classes.zip" />
          </tasks>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
<pluginManagement>
    <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
<lifecycleMappingMetadata>
    <pluginExecutions>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <goals>
                    <goal>exec</goal>
                </goals>
                <versionRange>[0.0,)</versionRange>
            </pluginExecutionFilter>
            <action>
                <execute />
            </action>
        </pluginExecution>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <goals>
                    <goal>run</goal>
                </goals>
                <versionRange>[0.0,)</versionRange>
            </pluginExecutionFilter>
            <action>
                <execute />
            </action>
        </pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
  <dependencies>
<dependency>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>servlet-api</artifactId>
  <version>${servlet.version}</version>
  <scope>provided</scope>
 </dependency>

<dependency>
  <groupId>com.google.android</groupId>
  <artifactId>android</artifactId>
  <version>${android.version}</version>
  <scope>provided</scope>
</dependency>
  </dependencies>
</project>

我的 web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    version="3.0"> 

  <servlet>
    <servlet-name>hello</servlet-name>
    <servlet-class>com.example.mwa.HelloWorld</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>/sayit/*</url-pattern>
  </servlet-mapping>

</web-app>

问题是当我在http://localhost:8080/hello/hello的Android设备上打开它时,我的html包含了大量随机字母和符号。 (无法发布图片) 你有什么想法以及如何解决这个问题吗?

0 个答案:

没有答案