Ola…
Estou com um problema na criação do WAR de uma aplicação. segue abaixo o erro quando e criado o WAR
Compiling 16 source files to /Users/michaelgerson/Desktop/Transparencia/build/web/WEB-INF/classes
[color=red]Note: /Users/michaelgerson/Desktop/Transparencia/src/java/br/gov/rr/transparencia/controller/RelatorioUtil.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.[/color]
Copying 1 file to /Users/michaelgerson/Desktop/Transparencia/build/web/WEB-INF/classes
compile:
compile-jsps:
Created dir: /Users/michaelgerson/Desktop/Transparencia/dist
Building jar: /Users/michaelgerson/Desktop/Transparencia/dist/Transparencia.war
do-dist:
dist:
CONSTRUÍDO COM SUCESSO (tempo total: 4 segundos)
Segue a Classe
package br.gov.rr.transparencia.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import javax.faces.context.FacesContext;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.oasis.JROdtExporter;
import net.sf.jasperreports.engine.util.JRLoader;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
public class RelatorioUtil {
public static final int RELATORIO_PDF = 1;
public static final int RELATORIO_EXCEL = 2;
public static final int RELATORIO_HTML = 3;
public static final int RELATORIO_PLANILHA_OPEN_OFFICE = 4;
public StreamedContent geraRelatorio(HashMap parametrosRelatorio, String nomeRelatorioJasper, String nomeRelatorioSaida, int tipoRelatorio) throws UtilException {
StreamedContent arquivoRetorno = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
Connection conexao = this.getConexao();
String caminhoRelatorio = context.getExternalContext().getRealPath("jasper");
String caminhoArquivoJasper = caminhoRelatorio + File.separator + nomeRelatorioJasper + ".jasper";
String caminhoArquivoRelatorio = null;
JasperReport relatorioJasper = (JasperReport) JRLoader.loadObject(caminhoArquivoJasper);
JasperPrint impressoraJasper = JasperFillManager.fillReport(relatorioJasper, parametrosRelatorio, conexao);
JRExporter tipoArquivoExportado = null;
String extensaoArquivoExportado = "";
File arquivoGerado = null;
switch (tipoRelatorio) {
case RelatorioUtil.RELATORIO_PDF:
tipoArquivoExportado = new JRPdfExporter();
extensaoArquivoExportado = "pdf";
break;
case RelatorioUtil.RELATORIO_HTML:
tipoArquivoExportado = new JRHtmlExporter();
extensaoArquivoExportado = "html";
break;
case RelatorioUtil.RELATORIO_EXCEL:
tipoArquivoExportado = new JRXlsExporter();
extensaoArquivoExportado = "xls";
break;
case RelatorioUtil.RELATORIO_PLANILHA_OPEN_OFFICE:
tipoArquivoExportado = new JROdtExporter();
extensaoArquivoExportado = "ods";
break;
default:
tipoArquivoExportado = new JRPdfExporter();
extensaoArquivoExportado = "pdf";
break;
}
caminhoArquivoRelatorio = caminhoRelatorio + File.separator + nomeRelatorioSaida + "." + extensaoArquivoExportado;
arquivoGerado = new java.io.File(caminhoArquivoRelatorio);
tipoArquivoExportado.setParameter(JRExporterParameter.JASPER_PRINT, impressoraJasper);
tipoArquivoExportado.setParameter(JRExporterParameter.OUTPUT_FILE, arquivoGerado);
tipoArquivoExportado.exportReport();
arquivoGerado.deleteOnExit();
InputStream conteudoRelatorio = new FileInputStream(arquivoGerado);
arquivoRetorno = new DefaultStreamedContent(conteudoRelatorio, "application/" + extensaoArquivoExportado, nomeRelatorioSaida + "." + extensaoArquivoExportado);
} catch (JRException e) {
throw new UtilException("Nao foi possovel gerar o relatorio.", e);
} catch (FileNotFoundException e) {
throw new UtilException("Arquivo do relatorio nao encontrado.", e);
}
return arquivoRetorno;
}
private Connection getConexao() throws UtilException {
Connection connection = null;
String url = "org.postgresql.Driver";
String bd = "jdbc:postgresql://192.168.227.16:5432/cti";
String usuario = "postgres";
String senha = "Maker@1";
//String bd = "jdbc:postgresql://127.0.0.1:5432/transparencia";
//String usuario = "postgres";
//String senha = "bdm!c0l";
try {
Class.forName(url);
connection = DriverManager.getConnection(bd, usuario, senha);
return connection;
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}