Thursday, June 2, 2011

Problema ao adicionar GWT a projeto Spring Roo

Problema

Ao executar o comando gwt setup para adicionar o GWT a projeto do spring roo, passa a apresentar erros de compilação, como:

The import com.google.appengine cannot be resolved GaeAuthFilter.java /src/main/java/br/com/server/gae line 3 Java Problem

User cannot be resolved to a type UserServiceLocator.java /src/main/java/br/com/server/gae line 24 Java Problem

UserService cannot be resolved to a type GaeAuthFilter.java /src/main/java/br/com/server/gae line 21 Java Problem

UserServiceFactory cannot be resolved GaeAuthFilter.java /src/main/java/br/com/server/gae line 21 Java Problem


Motivo

O comando do roo não está funcionando corretamente. Deveria adicionar ao pom a dependência ao GAE.

Solução

Adicione ao pom o seguinte:

...
com.google.appengine
appengine-api-1.0-sdk
1.4.0
...






Eclipse OutOfMemoryError: Java heap space

PROBLEM

Eclipse raises the following error when executing unit tests in JUnit:

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:515)
at java.lang.StringBuffer.append(StringBuffer.java:306)
at java.io.BufferedReader.readLine(BufferedReader.java:345)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at br.gov.al.sefaz.gcs.core.domain.particaodocumento.ParticaoDocumentoTest$AoValidarNoContextoInserir$ComConteudoMaior30Megas.inicializarContexto(ParticaoDocumentoTest.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

REASON

The enviroment needs more memory to run the tests.

SOLUTION

In Eclipse:

Click Run->Run Configurations->...

In the Run Configuration View locate and select the test that you tried to run.

Select the Tab Arguments

In the VM field put the following: -Xms512m -Xmx1024m

Run the tests.

Problema Eclipse OutOfMemoryError: Java heap space

Problema

Apresentou a seguinte mensagem de erro ao tentar executar alguns testes de unidade:

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:515)
at java.lang.StringBuffer.append(StringBuffer.java:306)
at java.io.BufferedReader.readLine(BufferedReader.java:345)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at br.gov.al.sefaz.gcs.core.domain.particaodocumento.ParticaoDocumentoTest$AoValidarNoContextoInserir$ComConteudoMaior30Megas.inicializarContexto(ParticaoDocumentoTest.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

Motivo

Falta de memória para execução de alguns testes.

Solução
Editar

Clique em Run->Run Configurations->...

Na tela Run Configurations localize e selecione o teste que tentou executar e não funcionou. Digite na caixa de testo no alto à esquerda.

Selecione a aba Arguments

No campo VM Arguments digite: -Xms512m -Xmx1024m

Execute os testes.

Saturday, August 29, 2009

GWT Test Execution Error

Problem:

When try to execute a test class that inherits from GWTTestCase the following message error is displayed:

com.google.gwt.junit.JUnitFatalLaunchException: The test class 'stories.SomeStoryTest' was not found in module'com.appspot.projectname.ProjectName; no compilation unit for that type was seen
    at com.google.gwt.junit.JUnitShell.checkTestClassInCurrentModule(JUnitShell.java:390)
    at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:626)
    at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:346)
    at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:219)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:132)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

 

Reason:

The test class SomeStoryTest should be in the same package of the GWT Module, or in a subpackage.

Solution:

Change de package of the test class. In this example, change from  story.SomeStoryTest to com.appspot.projectname.client.SomeStoryTest or to some subpackage as in com.appspot.projectname.client.stories.SomeStoryTest.

Related links:

http://code.google.com/intl/pt-BR/webtoolkit/doc/1.6/DevGuideTesting.html

http://www.ibm.com/developerworks/java/library/j-cq07247/index.html

Sorry any mistake in English. :)

Erro ao executar testes no GWT

Problema:

Ao tentar rodar os testes em uma classe que é filha de GWTTestCase apresentou a seguinte mensagem de erro:

com.google.gwt.junit.JUnitFatalLaunchException: The test class 'stories.SomeStoryTest' was not found in module 'com.appspot.projectname.ProjectName; no compilation unit for that type was seen
    at com.google.gwt.junit.JUnitShell.checkTestClassInCurrentModule(JUnitShell.java:390)
    at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:626)
    at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:346)
    at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:219)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:132)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Motivo:

A classe de teste SomeStoryTest deve estar no mesmo pacote do módulo do projeto, ou em em um pacote interno.

Solução:

Adequar o caminho da classe de teste. No exemplo atual devemos mudar o caminho de story.SomeStoryTest para com.appspot.projectname.client.SomeStoryTest ou algum pacote interno a cliente, como para com.appspot.projectname.client.stories.SomeStoryTest

Links relacionados:

http://code.google.com/intl/pt-BR/webtoolkit/doc/1.6/DevGuideTesting.html

http://www.ibm.com/developerworks/java/library/j-cq07247/index.html

Saturday, August 1, 2009

Use of regular expression to find text in Eclipse

Problem

Find text inside Eclipse as the following standard:

  • starting with a given set of characters. th for example;
  • having zero or one line break inside the text;
  • having in the end a semicolon “;”

Examples of expressions:

throw new RuntimeException(".newQuery() não implementado");

throw new RuntimeException(
". newQuery() não implementado");


Solution



Execute the search in Eclipse using the following regular expression: th.*\R?.* Explanation:




  • “th” – the text must star with th;


  • “.” – the point indicates that any character could be in this position;


  • “*” – Asterix indicates that the previous character may appear any number of times. As the previous character is a point then the entire line will be select;


  • “\R” – indicates that in this position is a line break;


  • “?” – the previous character may appear zero or once. So the text may or may not have a line break in the middle;


  • “.*” – already explained;


  • “;” – the end character must be a semicolon

Utilização de expressão regular para localização de texto no eclipse

Problema

Localizar textos dentro no eclipse conforme o seguinte padrão:

  • inicie com determinando conjunto de caracteres. "th" por exemplo (desconsidere as aspas);
  • tenha zero ou uma quebra de linha no meio do texto;
  • tenha no final um ";" ponto e vírgula;

Exemplos de expressões:



throw new RuntimeException(".newQuery() não implementado");

throw new RuntimeException(
". newQuery() não implementado");
Solução:

Fazer a pesquisa no Eclipse utilizando a seguinte expressão regular: th.*\R?.*;
Explicação:
  • "th" - a expressão deve iniciar com th
  • "." - o ponto indica que depois do th pode vir qualquer caracter
  • "*" - o asterisco indica que o caracter anterior pode aparecer qualquer número de vezes. Como o anterior é um ponto então qualquer linha que tenha th no começo será selecionada. O texto será selecionado até o final da linha
  • "\R" - indica que nesta posição é uma quebra de linha
  • "?" - indica que o caracter anterior pode aparecer zero ou uma vez. Ou seja, o texto pode ou não ter no meio uma quebra de linha
  • ".*" - já explicado
  • ";" - indica que na última posição deve vir um ponto e virgula