Servlet no Android: UnavaliableException: Servlet Not Initialized

1 resposta
R

Pessoal

Criei um projeto web com uma servlet e gostaria de abrir este projeto no meu tablet android.
O projeto web é aberto normalmente no browser do pc (com o servidor jetty), mas no tablet dá erro:

UnavaliableException: Servlet Not Initialized

Um detalhe que notei é que apesar de no pom.xml haver o comando para gerar o classes.dex ele não está sendo gerado (colocado no war final)
Será que isto pode estar causando o erro acima?

Pom.xml

<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>hello-world</artifactId>
  <version>0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>Jetty HelloWorld</name>
  
  <properties>
    <jettyVersion>7.2.0.v20101020</jettyVersion>
    <googleVersion>2.3.3</googleVersion>
  </properties>

  <build>
    <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>aspectj-maven-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>test-compile</goal>
                                        <goal>compile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
            
            <plugin>
			        <artifactId>maven-compiler-plugin</artifactId>
			        <configuration>
			          <source>1.5</source>
			          <target>1.5</target>
			          <verbose>false</verbose>
			        </configuration>
			      </plugin>

	          <plugin>
	            <groupId>org.codehaus.mojo</groupId>
	            <artifactId>exec-maven-plugin</artifactId>
	            <version>1.1</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>${android.home}/${android-platform}/tools/dx</executable>
	                  <arguments>
	                    <!--<argument>-JXmx1024M</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>
    
  </build>
  
  <dependencies>
  	<dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <version>${jettyVersion}</version>
    </dependency>
    
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>${googleVersion}</version>
    </dependency>

  </dependencies>
  
</project>

Servlet:

public class HelloServlet extends HttpServlet {

	String proofOfLife = null;

	/* ------------------------------------------------------------ */
    @Override
	public void init(ServletConfig config) throws ServletException {
        super .init(config);
        //to demonstrate it is possible
        Object o = config.getServletContext().getAttribute(
                "org.mortbay.ijetty.contentResolver");
        android.content.ContentResolver resolver = (android.content.ContentResolver) o;
        android.content.Context androidContext = (android.content.Context) config
                .getServletContext().getAttribute("org.mortbay.ijetty.context");
        proofOfLife = androidContext.getApplicationInfo().packageName;
    }


	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		 response.setContentType("text/html");
         ServletOutputStream out = response.getOutputStream();
         out.println("<html>");
         out.println("<h1>Hello From Servlet Land!</h1>");
         out.println("Brought to you by: " + proofOfLife);
         out.println("</html>");
         out.flush();
	}
}

1 Resposta

R

nada?! ninguem passou por isso?

Criado 26 de agosto de 2011
Ultima resposta 29 de ago. de 2011
Respostas 1
Participantes 1