1

我正在尝试将 .jsp 页面预编译为 servlet 并在 Android 上的 I-jetty 上运行它们。

但是我得到的是:Servlet Not Initialized

我检查了 web.xml 中生成的东西,它对我来说看起来不错。一个普通的 helloworld servlet 运行良好。

我正在尝试使用的示例 JSP:

<html>
<body align='center'>
    <h1>Hello World</h1>    
    <h1>from jsp</h1>
</body>
</html>

它在 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">

<!--
Automatically created by JspC.
Place this fragment in the web.xml before all icon, display-name,
description, distributable, and context-param elements.
-->

    <servlet>
        <servlet-name>jsp.simple_jsp</servlet-name>
        <servlet-class>jsp.simple_jsp</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>jsp.simple_jsp</servlet-name>
        <url-pattern>/simple.jsp</url-pattern>
    </servlet-mapping>

<!--
All session-config, mime-mapping, welcome-file-list, error-page, taglib,
resource-ref, security-constraint, login-config, security-role,
env-entry, and ejb-ref elements should follow this fragment.
-->
</web-app>

我使用以下 pom.xml 来生成它:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bogus</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>test</name>

    <dependencies>

    </dependencies>

    <build>

<plugins>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <webXml>${basedir}/target/web.xml</webXml>
  </configuration>
</plugin>
<plugin>
  <groupId>org.mortbay.jetty</groupId>
   <artifactId>jetty-jspc-maven-plugin</artifactId>
   <version>8.1.0.RC5</version>
   <executions>
     <execution>
       <id>jspc</id>
       <goals>
         <goal>jspc</goal>
       </goals>
       <configuration>
       </configuration>
     </execution>
   </executions>
 </plugin>

               <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.3</version>
        <executions>    
          <execution>
            <id>unpack-dependencies</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
              <excludeArtifactIds>servlet-api,android</excludeArtifactIds>
              <excludeTransitive>true</excludeTransitive>
              <outputDirectory>${project.build.directory}/generated-classes</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <!-- Convert the compiled classes into a clases.dex. -->
          <execution>
            <id>generate-dex</id>
            <phase>process-classes</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>java</executable>
              <arguments>
                <argument>-jar</argument>
                <argument>C:\Android\adt-bundle-windows-x86_64-20130917\sdk\build-tools\android-4.3\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>
        <version>1.6</version>
        <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.jar" />
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>

        </plugins>
    </build>



</project>
4

2 回答 2

0

我们取消了这个项目。这是不可能的。

于 2014-01-20T15:54:31.830 回答
0

由 Apache Jasper 预编译的 JSP servlet 需要 Jasper 和其他库。但它们必须适用于 Android。我解决了这个问题。见https://sourceforge.net/projects/beigeerp

于 2016-04-16T13:46:27.027 回答