When I package my stand-alone-java-application, that compiles, renders and prints Jasper-Reports, in a fat jar with all dependencies, I get the error that the function TEXT – a function used in the report and defined in the net.sf.jasperreports-functions-library is not found.
The method TEXT(Integer, String) is undefined for the type [...]
value = IF(LEN(TEXT(((java.lang.Integer)parameter_X.getValue()),"#"))==2,"***",REPT("*",6-LEN(TEXT(((java.lang.Integer)parameter_X.getValue()),"#")))) //$JR_EXPR_ID=58$
Other functions from the same library work. When I run the application with gradle run, the function is found and the report can be printed. The library is on my classpath.
There are several similar questions on this site and Stackoverflow, but neither provided answers, that worked for me. In the following, I will explain what I tried:
In my build.gradle-File I defined dependencies to the following libraries:
implementation('net.sf.jasperreports:jasperreports:6.18.1')
implementation('net.sf.jasperreports:jasperreports-functions:6.18.1')
In my java-Files, I created a DesignFile and statically imported the functions into it. I tried two methods:
Method 1 as given in an answer in this thread: Unresolved symbols when compiling jasper report
/*…*/
designFile = JRXmlLoader.load(sourceFile.getAbsolutePath());
designFile.addImport("static net.sf.jasperreports.functions.standard.TextFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.MathFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.DateTimeFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.LogicalFunctions.*");
JasperReport compiledReport = JasperCompileManager.getInstance(ctx).compile(designFile);
/*…*/
Method 2: importing each function on its own
public static String[] textFunctions(){
return new String[]{"BASE", "CHAR", "CLEAN", "CODE", "CONCATENATE", "DOUBLE_VALUE",
"EXACT", "FIND", /*"FIXED", */"FLOAT_VALUE", "INTEGER_VALUE", "LEFT", "LEN", "LONG_VALUE",
"LOWER", "LTRIM", "MID", "PROPER", "REPLACE", "REPT", "RIGHT", "RTRIM", "SEARCH", "SUBSTITUTE",
"T", /*"TEXT",*/ "TRIM", "UPPER"};
}}
/*…*/
designFile = JRXmlLoader.load(sourceFile.getAbsolutePath());
for (String textFunction : textFunctions()){
designFile.addImport("static net.sf.jasperreports.functions.standard.TextFunctions." + textFunction);
}/* similarly for logical functions, numeric functions and datetime functions*/
}
JasperReport compiledReport = JasperCompileManager.getInstance(ctx).compile(designFile);
/*…*/
As you can see, the function TEXT is commented out. That’s because the program fails at runtime when run with “gradle run”, when I comment it in:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The import net.sf.jasperreports.functions.standard.TextFunctions.TEXT cannot be resolved
import static net.sf.jasperreports.functions.standard.TextFunctions.TEXT;
The same thing is true with most datetime-functions, in fact, only TIME can be imported to the DesignObject without error at runtime
In addition to that, when I type net.sf.jasperreports.functions.standard.TextFunctions. in my IDE, the content-assist shows a list of available functions, yet TEXT is missing.
I suspected, that the function is simply missing in the library, but it is there. In the .gradle/cache/modules-2/files-2.1/… directory, there is the jar with the TextFunctions.java, that contains the function TEXT:
When building the FatJar with dependencies, I have a TextFunctions.class-File in it, that contains the TEXT-Function as well.
In my jar, there are two jasperreports_extension.properties on the root level:
with the smaller one (from the jasperreport-functions-dependency) containing the following lines:
net.sf.jasperreports.extension.registry.factory.functions=net.sf.jasperreports.functions.FunctionsRegistryFactory
net.sf.jasperreports.extension.functions.datetime=net.sf.jasperreports.functions.standard.DateTimeFunctions
net.sf.jasperreports.extension.functions.math=net.sf.jasperreports.functions.standard.MathFunctions, net.sf.jasperreports.functions.standard.LogicalFunctions
net.sf.jasperreports.extension.functions.text=net.sf.jasperreports.functions.standard.TextFunctions
net.sf.jasperreports.extension.functions.report=net.sf.jasperreports.functions.standard.ReportFunctions
Funnily enough, commenting out TEXT, running it locally with gradle run, it works without problems. But packaging it and running it with java -jar it fails to find this function. And statically importing this function leads to gradle run failing as well.
What is happening and how can I fix this? I want to distribute my FatJar on a server and run it, but this problems makes it impossible for me.
I am using the CastCompanionLibrary-android and it is throwing the following error all of a sudden. Any ideas ?
The method setVerboseLoggingEnabled(boolean) is undefined for the type
Cast.CastOptions.Builder VideoCastManager.java
/CastCompanionLibrary-android/src/com/google/sample/castcompanionlibrary/cast
Its shows taht this method does infact exist in :
http://developer.android.com/reference/com/google/android/gms/cast/Cast.CastOptions.Builder.html
But when I drill into CastOptions it is no longer there.
Its seems I did an update with the Android SDK manager, but neglected to replace the old jar with the newly update jar.
Did this and it fixed the issue :)
I am using Eclipse Juno and Java.
I was trying to create a new list:
List myList = new ArrayList();
This had an error and the resolution on it was along the lines of change compiler to 1.7 which I accepted. The errror on this list creation line was corrected however I now have many errors thoughout the whole project on lines that were previously working. Some examples are:
class GetAccountAndCubsHandler<T> implements AsyncCallback<List<AccountAndCubs>>
Multiple markers at this line
- The hierarchy of the type GetAccountAndCubsHandler is inconsistent
- List cannot he resolved to a type
public class AccountCreationView extends Composite {
Multiple markers at this line
- The hierarchy of the type AccountCreationView is inconsistent
- Breakpoint:AccountCreationView
#SuppressWarnings("unused")
private String accountId;
First line - Multiple markers at this line
- SuppressWarnings cannot be resolved to a type
- The attribute valie is undefined for the annotation type SuppressWarnings
Second line - String cannot be resolved to a type
As you can imagine having my whole project adversely affected in this way is very disconcerting so any advice on how to recover would be greatly appreciated.
Regards,
Glyn
"String cannot be resolved to a type"
Ensure that a valid JRE or JDK is specified in your build-path.
Since you're using Eclipse, right-click on your project, then Properties → Java Build Path.
Perhaps you don't have a Java 7 JRE configured in the Installed JREs preference panel.
I'm writing eclipse plugin that looks for unresolved imports in all source files.
I found that it can be helpful to use IProblem or IMarker objects. Here's code example
public IMarker[] findJavaProblemMarkers(ICompilationUnit cu)
throws CoreException {
IResource javaSourceFile = cu.getUnderlyingResource();
IMarker[] markers =
javaSourceFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER,
true, IResource.DEPTH_INFINITE);
}
frome here
I don't know how I can get info from IProblem or IMarker about which import cause the compilation problem (unresolved import).
Any help?
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_classpath.htm
There are a list of different int values in the IProblem interface representing different errors; if you could get the errorcodes of a file somehow, you could use them. (Example, ImportNotVisible, ImportNotFound, etc.). Just check if the error ID matches one of the error ID's for import failures there.
An IMarker knows the line number and start and stop chars for the java source marked by the IMarker. You can take the substring of the java source string and, if the marker type indicates that it's a problem with the class or import, you can search the project's classpath for a class or package matching (or similar to) that substring.
I have received a project with many lines like the following ones:
HtmlOutputText content = new HtmlOutputText();
ValueBinding vb = dashBoardBean.getApplication()
.createValueBinding(columnas[cont][1]);
content.setValueBinding("value", vb);
Eclipse, with Java 5, marks them as deprecated (both class ValueBindingand the method setValueBinding).
So I looked the API for HtmlCommandLink.setValueBinding() (it actually is at UIComponentBase) and found this:
Deprecated. This has been replaced by UIComponent.setValueExpression(java.lang.String, javax.el.ValueExpression).
So I changed the last line code to the following:
content.setValueExpression("value", null);
But now I get a compiler error.
I also tried:
UIComponent uic;
uic.setValueExpression("", null);
And get the same error:
The type javax.el.ValueExpression cannot be resolved. It is indirectly referenced from
required .class files
What's the meaning of that error? How can I solve it?
You need the JSF 1.2 (or greater) jars on your classpath.