0

プロジェクト クラスへのフィールド マッピングを使用してジャスパー レポートを作成しましたが、レポートがコンパイルされなくなりました。Eclipse でエクスポートされたプロジェクトから生成されたプロジェクトの jar をクラスパス レポートに入れました。このプロジェクトは、フレームワーク vraptor と maven を使用した Web Java です。

私のクラスは私のレポートに送信します:

@Entity
@Table
public class TransacaoBancaria implements Serializable {
    private static final long serialVersionUID = 5081334063974639104L;

    @Id
    @GeneratedValue
    private Long id;

    @NotNull
    @ManyToOne(optional = false)
    private ContaBancaria conta;


    @ManyToOne
    private Usuario usuario;

    @Column(nullable = false)
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    private Date data;

    @Column(nullable = false)
    @NotNull
    private BigDecimal saldo = BigDecimal.valueOf(0);

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the conta
     */
    public ContaBancaria getConta() {
        return conta;
    }

    /**
     * @param conta
     *            the conta to set
     */
    public void setConta(ContaBancaria conta) {
        this.conta = conta;
    }

    /**
     * @return the usuario
     */
    public Usuario getUsuario() {
        return usuario;
    }

    /**
     * @param usuario
     *            the usuario to set
     */
    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    /**
     * @return the data
     */
    public Date getData() {
        return data;
    }

    /**
     * @param data
     *            the data to set
     */
    public void setData(Date data) {
        this.data = data;
    }

    /**
     * @return the saldo
     */
    public BigDecimal getSaldo() {
        return saldo;
    }

    /**
     * @param saldo
     *            the saldo to set
     */
    public void setSaldo(BigDecimal saldo) {
        this.saldo = saldo;
    }

}

集約クラスの内容:

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "agencia", "conta", "banco" }))
public class ContaBancaria {
    @Id
    @GeneratedValue
    private Long id;

    @Column(nullable = false)
    @NotNull
    private String agencia;

    @Column(nullable = false)
    @NotNull
    private String conta;

    @Column(nullable = false)
    @NotNull
    private String banco;

    @Column(nullable = false)
    @NotNull
    private Boolean ativa = Boolean.FALSE;

    @ManyToOne
    private Usuario usuario;

    @OneToMany(mappedBy = "conta")
    private List<TransacaoBancaria> transacoes = new ArrayList<TransacaoBancaria>();

    //get-set-gerados-------------------------------------------------------

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAgencia() {
        return agencia;
    }

    public void setAgencia(String agencia) {
        this.agencia = agencia;
    }

    public String getConta() {
        return conta;
    }

    public void setConta(String conta) {
        this.conta = conta;
    }

    public String getBanco() {
        return banco;
    }

    public void setBanco(String banco) {
        this.banco = banco;
    }

    public Boolean getAtiva() {
        return ativa;
    }

    public void setAtiva(Boolean ativa) {
        this.ativa = ativa;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }
}

集約クラス usuario;

@Entity
@Table
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Usuario implements Serializable {
    private static final long serialVersionUID = -8066548068818800938L;

    @Id
    @GeneratedValue
    private Long id;

    @Column(unique = true, nullable = false)
    @NotNull
    private String email;

    @Column(nullable = false)
    @NotNull
    private String password;

    @Column(nullable = false)
    @NotNull
    private String nome;

    @Column(nullable = false)
    @NotNull
    private String endereco;

    @Column(nullable = false)
    @NotNull
    private String cep;

    private String telefone;

    @Column(nullable = false)
    @NotNull
    private BigDecimal saldo = BigDecimal.valueOf(0);

    @OneToMany(mappedBy = "usuario")
    private List<ContaBancaria> contasBancarias = new ArrayList<ContaBancaria>();

    @OneToMany(mappedBy = "usuario")
    private List<TransacaoBancaria> transacoes = new ArrayList<TransacaoBancaria>();

    public TipoUsuario getTipoUsuario() {
        return (this instanceof Agencia) ? TipoUsuario.AGENCIA : TipoUsuario.ANUNCIANTE;
    }

    public String getCpfCnpj() {
        return (this instanceof Agencia) ? ((Agencia) this).getCnpj() : ((Anunciante) this).getCpf();
    }

    // get-set-gerados-------------------------------------------------------
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    public String getCep() {
        return cep;
    }

    public void setCep(String cep) {
        this.cep = cep;
    }

    public String getTelefone() {
        return telefone;
    }

    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }

    public BigDecimal getSaldo() {
        return saldo;
    }

    public void setSaldo(BigDecimal saldo) {
        this.saldo = saldo;
    }

    public List<ContaBancaria> getContasBancarias() {
        return contasBancarias;
    }

    public void setContasBancarias(List<ContaBancaria> contasBancarias) {
        this.contasBancarias = contasBancarias;
    }
}

私のjrxmlに従ってください:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="032b97ec-ca85-463c-9603-afb4490dc6f1">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="5"/>
    <import value="br.com.bup.domain.Usuario"/>
    <import value="br.com.bup.domain.ContaBancaria"/>
    <field name="saldo" class="java.math.BigDecimal"/>
    <field name="data" class="java.util.Date"/>
    <field name="conta" class="br.com.bup.domain.ContaBancaria"/>
    <field name="usuario" class="br.com.bup.domain.Usuario"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="41" width="100" height="20" uuid="29f8398f-d405-4854-a49c-445cdb90d7a4"/>
                <text><![CDATA[saldo]]></text>
            </staticText>
            <staticText>
                <reportElement x="100" y="41" width="175" height="20" uuid="5084d42d-b909-4b4d-87ca-08d6b88bb18b"/>
                <text><![CDATA[data]]></text>
            </staticText>
            <staticText>
                <reportElement x="275" y="41" width="100" height="20" uuid="97389e53-4e4a-4035-9b85-fd297daf6563"/>
                <text><![CDATA[banco]]></text>
            </staticText>
            <staticText>
                <reportElement x="375" y="41" width="100" height="20" uuid="73c8f4aa-6283-4ba7-ad65-1cc8d0407cdf"/>
                <text><![CDATA[agencia]]></text>
            </staticText>
            <staticText>
                <reportElement x="475" y="41" width="100" height="20" uuid="964e28e1-db05-4c5e-8a3e-b590a5639da4"/>
                <text><![CDATA[conta]]></text>
            </staticText>
            <staticText>
                <reportElement x="575" y="41" width="100" height="20" uuid="bd8a4951-a847-48d0-9769-c5252a501e1c"/>
                <text><![CDATA[nome]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement x="0" y="0" width="100" height="20" uuid="2e55cd40-9d21-49b8-beb7-03708aaaf76f"/>
                <textFieldExpression><![CDATA[$F{saldo}.toString()]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" pattern="dd/MM/yyyy" isBlankWhenNull="true">
                <reportElement x="100" y="0" width="175" height="20" uuid="9b675e66-51a5-455a-8a36-a5445eb8841d"/>
                <textFieldExpression><![CDATA[$F{data}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement x="275" y="0" width="100" height="20" uuid="194dae97-d53a-4368-939f-dd632c9e6e3a"/>
                <textFieldExpression><![CDATA[$F{conta}.banco]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement x="375" y="0" width="100" height="20" uuid="7d97aeab-9764-4a32-8391-483dc90bf49a"/>
                <textFieldExpression><![CDATA[$F{conta}.agencia]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement x="475" y="0" width="100" height="20" uuid="16c2fc1b-903e-4d30-a2bb-4a2c262a452c"/>
                <textFieldExpression><![CDATA[$F{conta}.conta]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement x="575" y="0" width="100" height="20" uuid="49e7797e-c803-49dd-8529-9218fc95a6d2"/>
                <textFieldExpression><![CDATA[$F{usuario}.nome]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

コンパイラ エラー:  

Compiling to file... /Users/andreluisdionisio/git/bup/bup/src/main/webapp/WEB-INF/reports/report1.jasper
Error compiling the report java source!
java.lang.UnsupportedClassVersionError: br/com/bup/domain/ContaBancaria : Unsupported major.minor version 51.0     at java.lang.ClassLoader.defineClass1(Native Method)     at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)     at java.lang.ClassLoader.defineClass(ClassLoader.java:621)     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)     at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)     at java.net.URLClassLoader.access$000(URLClassLoader.java:58)     at java.net.URLClassLoader$1.run(URLClassLoader.java:197)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)     at java.lang.ClassLoader.loadClass(ClassLoader.java:295)     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)     at java.lang.Class.forName0(Native Method)     at java.lang.Class.forName(Class.java:249)     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.base.JRBaseField.getValueClass(JRBaseField.java:128)     at net.sf.jasperreports.engine.design.JRVerifier.verifyFields(JRVerifier.java:981)     at net.sf.jasperreports.engine.design.JRVerifier.verifyDataset(JRVerifier.java:2210)     at net.sf.jasperreports.engine.design.JRVerifier.verifyDesign(JRVerifier.java:386)     at net.sf.jasperreports.engine.design.JRVerifier.verifyDesign(JRVerifier.java:357)     at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:268)     at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:153)     at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:512)     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)     at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) 
Compilation running time: 18

私の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>br.com.bup</groupId>
    <artifactId>bup</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Propaganda</name>

    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>

        <!-- VRaptor -->
        <dependency>
            <groupId>br.com.caelum</groupId>
            <artifactId>vraptor</artifactId>
            <version>4.1.4</version>
        </dependency>

        <!--  -->
        <dependency>
            <groupId>br.com.caelum.vraptor</groupId>
            <artifactId>vraptor-quartzjob</artifactId>
            <version>4.0.2</version> 
            <scope>compile</scope>
        </dependency>

        <!-- JSTL -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- TILES - Apache Tiles is a framework that implements the Composite 
            View pattern... -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-extras</artifactId>
            <version>3.0.5</version>
        </dependency>

        <!-- LOG -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>

        <!-- CDI -->
        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-core</artifactId>
            <version>2.1.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-core-impl</artifactId>
            <version>2.1.2.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <!-- uncomment this line on app servers -->
            <!-- <scope>provided</scope> -->
        </dependency>

        <!-- Expression Language API -->
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>

        <!-- HIBERNATE -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.8.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator-cdi</artifactId>
            <version>5.1.1.Final</version>
        </dependency>
        <!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> 
            <version>5.1.3.Final</version> </dependency> -->

        <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.8.Final</version>
        </dependency>

        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
        </dependency>

        <!-- H2 in-memory database -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.2.145</version>
        </dependency>

        <!-- MySQL database driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.1.0</version>
        </dependency>
        <dependency>
            <groupId>br.com.prixma</groupId>
            <artifactId>vraptor-jasperreport</artifactId>
            <version>4.1.0</version>
        </dependency>
    </dependencies>

    <properties>
        <maven.test.skip>true</maven.test.skip>
    </properties>

    <build>
        <plugins>
<!--        <plugin> -->
<!--             <groupId>com.alexnederlof</groupId> -->
<!--             <artifactId>jasperreports-plugin</artifactId> -->
<!--             <version>1.6</version> -->
<!--             <executions> -->
<!--                 <execution> -->
<!--                    <phase>prepare-package</phase> -->
<!--                     <goals> -->
<!--                             <goal>jasper</goal> -->
<!--                     </goals> -->
<!--                 </execution> -->
<!--             </executions> -->
<!--             <configuration> -->
<!--                 <compiler>net.sf.jasperreports.engine.design.JRJdtCompiler</compiler> -->
<!--                  <sourceDirectory>src/main/jasperreports</sourceDirectory> -->
<!--                 <outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/reports</outputDirectory> -->
<!--                 <outputDirectory>src/main/jasperreports</outputDirectory> -->
<!--                 <outputDirectory>src/main/webapp/WEB-INF/reports</outputDirectory> -->

<!--                 <outputFileExt>.jasper</outputFileExt> -->
<!--                 <xmlValidation>true</xmlValidation> -->
<!--                 <verbose>false</verbose> -->
<!--                 <numberOfThreads>4</numberOfThreads> -->
<!--             </configuration> -->
<!--         </plugin> -->

<!--            <plugin> -->
<!--                <groupId>org.codehaus.mojo</groupId> -->
<!--                <artifactId>jasperreports-maven-plugin</artifactId> -->
<!--                <version>1.0-beta-2</version> -->
<!--                <configuration> -->
<!--                    <outputDirectory>target/${project.artifactId}/WEB-INF/reports</outputDirectory> -->
<!--                </configuration> -->
<!--                <executions> -->
<!--                    <execution> -->
<!--                        <phase>prepare-package</phase> -->
<!--                        <inherited>false</inherited> -->
<!--                        <goals> -->
<!--                            <goal>compile-reports</goal> -->
<!--                        </goals> -->
<!--                    </execution> -->
<!--                </executions> -->
<!--            </plugin> -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>ISO-8859-1</encoding>
                </configuration>
            </plugin>
        </plugins>

        <testResources>
            <testResource>
                <filtering>false</filtering>
                <directory>src/test/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </testResource>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
    </build>

</project>

私のコントローラー:

    package br.com.bup.controller;

import java.util.List;
import java.util.ResourceBundle;

import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import br.com.bup.annotation.OpenTransaction;
import br.com.bup.dao.TransacaoBancariaDAO;
import br.com.bup.dao.UsuarioDAO;
import br.com.bup.domain.TransacaoBancaria;
import br.com.bup.util.BaseWeb;
import br.com.bup.web.UsuarioSession;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.jasperreports.Report;
import br.com.caelum.vraptor.jasperreports.ReportBuilder;
import br.com.caelum.vraptor.jasperreports.download.ReportDownload;
import br.com.caelum.vraptor.jasperreports.formats.Pdf;
import br.com.caelum.vraptor.observer.download.Download;
import br.com.caelum.vraptor.validator.Validator;

@Controller
@Named("relatorio")
public class RelatorioController extends BaseWeb {
    private final static Logger LOGGER = LoggerFactory.getLogger(AgenciaController.class);

    private final UsuarioDAO usuarioDAO;
    private final TransacaoBancariaDAO transacaoBancariaDAO;

    /**
     * @deprecated CDI eyes only
     */
    protected RelatorioController() {
        this(null, null, null, null, null, null);
    }

    @Inject
    public RelatorioController(Result result, Validator validator, TransacaoBancariaDAO transacaoBancariaDAO,
            UsuarioSession usuarioSession, UsuarioDAO usuarioDAO, ResourceBundle i18n) {
        super(result, validator, usuarioSession, i18n);
        this.usuarioDAO = usuarioDAO;
        this.transacaoBancariaDAO = transacaoBancariaDAO;

    }

    @OpenTransaction
    public Download teste() {
        List<TransacaoBancaria> dataList = transacaoBancariaDAO.buscarTodos();
        Report report = new ReportBuilder().withTemplate("report1.jasper").withData(dataList).build();
        return new ReportDownload(report, new Pdf(), false); //boolean indica que deve ou nao baixar direto... por exemplo... caso false o chrome tenta abrir o arquivo no proprio navegador
    }
}
4

2 に答える 2