简体   繁体   English

在Eclipse中进行“ Maven安装”时出错:软件包net.sf.jasperreports.engine不存在

[英]Error while “maven install” in eclipse: package net.sf.jasperreports.engine does not exist

I am trying to get started with Jasper Reports with Spring Batch. 我正在尝试从Spring Batch开始使用Jasper Reports。

Work Environment: RAD 7.5 (so eclipse!), Maven 工作环境:RAD 7.5(如此之蚀!),Maven

I have a simplest of all Spring Batch program with one job having one tasklet, which does nothing but prints HELLO WORLD. 我有一个最简单的Spring Batch程序,一个工作只有一个小任务,只打印HELLO WORLD。

This runs fine. 运行良好。

After this - I copy jasper reports jar file in the lib folder of my project. 之后-我将jasper report jar文件复制到我项目的lib文件夹中。 Right click on the project -> Go to properties -> Build Path -> Add Jar Files -> Select jasper report jar and click ok. 右键单击项目->转到属性->构建路径->添加Jar文件->选择jasper报告jar,然后单击确定。

Fine till now. 到现在为止。

Now in my tasklet program, I am just adding the below line: 现在在我的tasklet程序中,我只添加以下行:

JasperReport jasperReport;

Since I am declaring a variable of type JasperReport, eclipse shouts about importing the class. 由于我声明了JasperReport类型的变量,因此eclipse喊着导入该类。

I click on the error bubble (the red bubble with cross) which eclipse shows, and it lists the correct class from above jar which I added to the class path. 我单击Eclipse所显示的错误气泡(带有十字的红色气泡),它从我添加到类路径的jar上方列出了正确的类。 I select the import recommendation and error is gone. 我选择了导入建议,但错误消失了。

Now, I am saving the file -> Right click on the project -> Run As -> Maven-Install and thats it: 现在,我要保存文件->右键单击项目-> Run As-> Maven-Install,就这样:

Maven complains: Maven抱怨:

Compilation failure
C:\Nikunj\Sandbox\Reporting\src\main\java\com\in\nik\example\util\GenerateReportTasklet.java:[12,35] package net.sf.jasperreports.engine does not exist

C:\Nikunj\Sandbox\Reporting\src\main\java\com\in\nik\example\util\GenerateReportTasklet.java:[25,8] cannot find symbol
symbol  : class JasperReport
location: class com.in.nik.example.util.GenerateReportTasklet

Checked 100 times. 检查了100次。 The package is there in the jar. 包装在罐子里。 The class is there in the jar. 这个课在罐子里。 If its not there, won't eclipse show error. 如果不存在,则不会遮挡显示错误。 Its not showing. 它没有显示。 Means its there. 意味着它在那里。

My GenerateReportTasklet is: 我的GenerateReportTasklet是:

package com.hsbc.us.pb.custody.util;

import net.sf.jasperreports.engine.JasperReport;

import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;


public class GenerateReportTasklet implements Tasklet {

    public RepeatStatus execute(final StepContribution arg0, final ChunkContext arg1) throws Exception {

        JasperReport jasperReport;

        System.out.println("Hello Report!");

        return null;
    }

}

I am out of my mind figuring out what I am missing. 我想不通自己在想什么。

Please do not advice to add the jar as dependency in my POM.xml I can easily do that. 请不要建议将jar作为依赖项添加到我的POM.xml中,我可以轻松做到这一点。

But I know what I am trying to do above should work and its not working. 但是我知道我上面想要做的事情应该起作用,但是不起作用。 I want to get to the root of that. 我想扎根。

Any ideas ? 有任何想法吗 ?

I know it does not matter but I have downloaded the jar from java2s.com: 我知道没关系,但是我已经从java2s.com下载了jar:

http://www.java2s.com/Code/Jar/JKL/Downloadjasperreportsjar.htm

Thanks for reading!! 谢谢阅读!!

When you compile with Eclipse, then Eclipse will build a classpath for the compilation. 当您使用Eclipse进行编译时,Eclipse将为该编译构建类路径。 If you tell Eclipse you need a JAR, then Eclipse will include that JAR in the compile classpath and your compile will work. 如果您告诉Eclipse您需要一个JAR,那么Eclipse将在编译类路径中包含该JAR,并且您的编译将起作用。

The same thing happens with Maven, except that the way to tell Maven that you need that JAR is by adding it as a dependency in the POM. Maven也会发生同样的事情,只是告诉Maven您需要JAR的方法是将其添加为POM中的依赖项。

You don't expect Eclipse to know (without you telling it) that you need a certain JAR. 您不希望Eclipse知道(不告诉您)您需要特定的JAR。 Why do you expect anything different of Maven? 您为什么期望Maven有什么不同?

Note: Maven, which is an IDE-independent tool, doesn't know about your Eclipse project configuration - though you can do the reverse and make Eclipse configure its classpath from the POM-declared dependencies. 注意:Maven是一个独立于IDE的工具,它不了解您的Eclipse项目配置-尽管您可以进行相反的操作并使Eclipse从POM声明的依赖关系中配置其类路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jasper报告找不到包net.sf.jasperreports.engine - Jasper report can't find package net.sf.jasperreports.engine 使用maven install命令时包不存在错误 - package does not exist error while using maven install command 错误:包net.sf.dynamicreports.jasper.builder不存在 - error: package net.sf.dynamicreports.jasper.builder does not exist Jaspersoft报告-net.sf.jasperreports.engine.JRException:net.sf.jasperreports.engine.fill.JRExpressionEvalException:计算表达式时出错 - Jaspersoft Report - net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression 使用Maven时出现“包不存在”错误 - Error on “package does not exist” while using Maven 填写 JasperReports 报告时出现意外异常 - 无法初始化 net.sf.jasperreports.engine.util.JRStyledTextParser (GWT) - Unexpected exception while filling JasperReports report - Could not initialize net.sf.jasperreports.engine.util.JRStyledTextParser (GWT) JasperReports-net.sf.jasperreports.engine.JRException:从bean检索字段值时出错 - JasperReports - net.sf.jasperreports.engine.JRException: Error retrieving field value from bean JasperReport:net.sf.jasperreports.engine.JRException - JasperReport : net.sf.jasperreports.engine.JRException jdeveloper-在Maven和Eclipse上编译时,包不存在 - jdeveloper - Package does not exist while compiling on Maven and Eclipse Net.sf.jasperreports.engine.util.JRStyledTextParser 上的 JasperReports NoClassDefFoundError 异常 - JasperReports NoClassDefFoundError exception on net.sf.jasperreports.engine.util.JRStyledTextParser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM