caelum / caelum-stella

O Caelum Stella visa suprir as necessidades do dia a dia do desenvolvedor brasileiro
http://stella.caelum.com.br
663 stars 340 forks source link

Gerar o boleto em JavaSE puro #124

Closed mariofts closed 10 years ago

mariofts commented 10 years ago

Ao gerar o boleto em um projeto JavaSE, o seguinte erro é exibido:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream
    at net.sf.jasperreports.web.util.WebResourceHandlersExtensionRegistryFactory.<clinit>(WebResourceHandlersExtensionRegistryFactory.java:47)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)
    at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:53)
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java:237)
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:214)
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:162)
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java:133)
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:105)
    at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:108)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:634)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:956)
    at br.com.caelum.vraptor4.Bla.App.main(App.java:83)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletOutputStream
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 22 more
mariofts commented 10 years ago

Atualmente para gerar os boletos necessária uma dependência para servlet 3.0.

Mudar a dependência para o jasper 5.5.2 resolve esse problema. Mas adiciona duas novas dependências quando geramos o relatório em html, do pacote com.fasterxml.jackson.core.

Precisamos discutir se é melhor resolver e adicionar 2 novas dependências opcionais (só para html) ou se deixamos a dependência obrigatória.

Reverti o commit desta issue, só quando rodei os testes do eclipse é que percebi, vou corrigir para rodar todos os testes da linha de comando sempre.

garcia-jj commented 10 years ago

Se é só o artefato do javax.servlet:servlet-api não vejo muito problema, pois é um jar bem pequeno. Além do mais a grande maioria usa em projetos web mesmo.

mariofts commented 10 years ago

Fechando, se alguém reclamar voltamos nisso.

aleffsouza commented 9 years ago

Tentei usar o com Scala, Play Framework e SBT e deu esse erro java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream

As dependências estão assim no arquivo build.sbt:

libraryDependencies ++= Seq(
  "br.com.caelum.stella"      % "caelum-stella-core"    % "2.1.2",
  "br.com.caelum.stella"      % "caelum-stella-boleto"  % "2.1.2",
  "br.com.caelum.stella"      % "caelum-stella-core"    % "2.1.2",
  "br.com.caelum.stella"      % "caelum-stella-boleto"  % "2.1.2",
  "net.sf.jasperreports"      % "jasperreports"         % "6.2.0",
  "commons-beanutils"         % "commons-beanutils"     % "1.8.3",
  "commons-collections"       % "commons-collections"   % "2.1",
  "commons-digester"          % "commons-digester"      % "2.1",
  "commons-logging"           % "commons-logging"       % "1.1.1",
  "net.sourceforge.barbecue"  % "barbecue"              % "1.5-beta1",
  "com.lowagie"               % "itext"                 % "2.1.7"
)

Tenho um stack trace semelhante:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[RuntimeException: java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:265) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.GlobalSettings$class.onError(GlobalSettings.scala:179) [play_2.11-2.4.3.jar:2.4.3]
    at play.api.DefaultGlobal$.onError(GlobalSettings.scala:212) [play_2.11-2.4.3.jar:2.4.3]
    at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:94) [play_2.11-2.4.3.jar:2.4.3]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$9$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:158) [play-netty-server_2.11-2.4.3.jar:2.4.3]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$9$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:155) [play-netty-server_2.11-2.4.3.jar:2.4.3]
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36) [scala-library-2.11.6.jar:na]
    at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:215) [scala-library-2.11.6.jar:na]
    at scala.util.Try$.apply(Try.scala:191) [scala-library-2.11.6.jar:na]
    at scala.util.Failure.recover(Try.scala:215) [scala-library-2.11.6.jar:na]
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [scala-library-2.11.6.jar:na]
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [scala-library-2.11.6.jar:na]
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.11.6.jar:na]
    at play.api.libs.iteratee.Execution$trampoline$.executeScheduled(Execution.scala:109) [play-iteratees_2.11-2.4.3.jar:2.4.3]
    at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:71) [play-iteratees_2.11-2.4.3.jar:2.4.3]
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [scala-library-2.11.6.jar:na]
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [scala-library-2.11.6.jar:na]
    at scala.concurrent.Promise$class.complete(Promise.scala:55) [scala-library-2.11.6.jar:na]
    at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [scala-library-2.11.6.jar:na]
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23) [scala-library-2.11.6.jar:na]
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) [akka-actor_2.11-2.3.13.jar:na]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) [akka-actor_2.11-2.3.13.jar:na]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.11.6.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.11.6.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.11.6.jar:na]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.11.6.jar:na]
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream
    at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:498) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:104) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:103) ~[play_2.11-2.4.3.jar:2.4.3]
    at scala.Option.map(Option.scala:146) ~[scala-library-2.11.6.jar:na]
    at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:103) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:96) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:741) ~[play-iteratees_2.11-2.4.3.jar:2.4.3]
    at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:741) ~[play-iteratees_2.11-2.4.3.jar:2.4.3]
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [scala-library-2.11.6.jar:na]
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [scala-library-2.11.6.jar:na]
    ... 6 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream
    at net.sf.jasperreports.web.util.WebResourceHandlersExtensionRegistryFactory.<clinit>(WebResourceHandlersExtensionRegistryFactory.java:47) ~[jasperreports-5.5.0.jar:5.5.0]
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_40]
    at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_40]
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:53) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java:237) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:214) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:162) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java:133) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:105) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:108) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:634) ~[jasperreports-5.5.0.jar:5.5.0]
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:956) ~[jasperreports-5.5.0.jar:5.5.0]
    at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraRelatorio(GeradorDeBoleto.java:126) ~[caelum-stella-boleto-2.1.2.jar:na]
    at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:155) ~[caelum-stella-boleto-2.1.2.jar:na]
    at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:142) ~[caelum-stella-boleto-2.1.2.jar:na]
    at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:119) ~[caelum-stella-boleto-2.1.2.jar:na]
    at controllers.Application$$anonfun$index$1.apply(Application.scala:63) ~[classes/:na]
    at controllers.Application$$anonfun$index$1.apply(Application.scala:11) ~[classes/:na]
    at play.api.mvc.ActionBuilder$$anonfun$apply$17.apply(Action.scala:439) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.ActionBuilder$$anonfun$apply$17.apply(Action.scala:439) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.ActionBuilder$$anonfun$apply$16.apply(Action.scala:408) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.ActionBuilder$$anonfun$apply$16.apply(Action.scala:407) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.Action$.invokeBlock(Action.scala:533) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.Action$.invokeBlock(Action.scala:530) ~[play_2.11-2.4.3.jar:2.4.3]
    at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:493) ~[play_2.11-2.4.3.jar:2.4.3]
    ... 18 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletOutputStream
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_40]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_40]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_40]
    ... 52 common frames omitted
mariofts commented 9 years ago

Você está gerando um boleto em html? S sim, precisa da api de servlets.

Se não, posta o trecho onde você instancia o gerador de boleto.

aleffsouza commented 9 years ago

Só estou gerando o boleto em pdf mesmo. Eu estou usando o código de exemplo em https://github.com/caelum/caelum-stella/wiki/Gerando-boleto. Sendo que adapatado para Scala:

    val datas = Datas.novasDatas()
      .comDocumento(1, 5, 2008)
      .comProcessamento(1, 5, 2008)
      .comVencimento(2, 5, 2008)

    val enderecoBeneficiario = Endereco.novoEndereco()
      .comLogradouro("Av das Empresas, 555")
      .comBairro("Bairro Grande")
      .comCep("01234-555")
      .comCidade("São Paulo")
      .comUf("SP")

    //Quem emite o boleto
    val beneficiario = Beneficiario.novoBeneficiario()
      .comNomeBeneficiario("Fulano de Tal")
      .comAgencia("1824").comDigitoAgencia("4")
      .comCodigoBeneficiario("76000")
      .comDigitoCodigoBeneficiario("5")
      .comNumeroConvenio("1207113")
      .comCarteira("18")
      .comEndereco(enderecoBeneficiario)
      .comNossoNumero("9000206")

    val enderecoPagador = Endereco.novoEndereco()
      .comLogradouro("Av dos testes, 111 apto 333")
      .comBairro("Bairro Teste")
      .comCep("01234-111")
      .comCidade("São Paulo")
      .comUf("SP")

    //Quem paga o boleto
    val pagador = Pagador.novoPagador()
      .comNome("Fulano da Silva")
      .comDocumento("111.222.333-12")
      .comEndereco(enderecoPagador)

    val banco = new BancoDoBrasil()

    val boleto = Boleto.novoBoleto()
      .comBanco(banco)
      .comDatas(datas)
      .comBeneficiario(beneficiario)
      .comPagador(pagador)
      .comValorBoleto("200.00")
      .comNumeroDoDocumento("1234")
      .comInstrucoes("instrucao 1", "instrucao 2", "instrucao 3", "instrucao 4", "instrucao 5")
      .comLocaisDePagamento("local 1", "local 2")

    val gerador = new GeradorDeBoleto(boleto)

    // Para gerar um boleto em PDF
    gerador.geraPDF("BancoDoBrasil.pdf")
itsmemarioss commented 6 years ago

Olá galera, esse problema já foi resolvido em alguma versão? Estou usando a API em um projeto javaFx e estou encontrando a mesma situação.

Att,