Spring boot+jasperReports images path error in resources - java

I have spring boot project with jasperReports library.
I have this structure
project
-src
-main
-java
-my.pakeg
-resources
-static
-jasper
-images
-logo.jpg
-rep1.jrxml
-rep2.jrxml
-rep3.jrxml
-templates
and in rep1.jrxml I include
<variable name="tax_logo_repo" class="java.lang.String">
<initialValueExpression><![CDATA["images/logo.jpg"]]></initialValueExpression>
</variable>
And I have error net.sf.jasperreports.engine.JRException: Byte data not found at: images/logo.jpg.
But if I move image from images folder to jasper folder
-resources
-static
-jasper
-images
-logo.jpg
-logo2.jpg
-rep1.jrxml
-rep2.jrxml
-rep3.jrxml
-templates
And change this path
<variable name="tax_logo_repo" class="java.lang.String">
<initialValueExpression><![CDATA["logo2.jpg"]]></initialValueExpression>
</variable>
All work fine. Why? I want have images in images folder. How can I do it?

Related

IntelliJ doesn't create jar properly

when I try to build my .jar (as described here) I get a MANIFEST.MF and a xml file inside the artifacts folder that's in the .idea folder. However I have no artifact folder with a .jar file inside the out folder. That's where the .jar file should be. This build process had worked earlier and I have no idea what I messed up.
I really need to build a jar and I used the IntelliJ GUI creator so I can't simply build a jar with an other program because it uses some compiled classes from a IntelliJ library, can I?
The xml file inside the artifacts folder:
<component name="ArtifactManager">
<artifact type="jar" name="Zimmerbelegung_BwInf36:jar">
<output-path>$PROJECT_DIR$/out/artifacts/Zimmerbelegung_BwInf36_jar</output-path>
<root id="archive" name="Zimmerbelegung_BwInf36.jar">
<element id="directory" name="META-INF">
<element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
</element>
<element id="module-output" name="Zimmerbelegung_BwInf36" />
</root>
</artifact>
</component>
My project structure looks like this:
IntelliJ didn't automatically build the artifact.
So I had to build it manually: (Build > Build Artifacts...)

JRebel do not detect web resource changes over multiple webapp folders

I have a modular web project and thus I am allowing modules to be a war archive including webapp folder. Using the following rebel.xml works fine on detecting class changes over all modules. But for some reason jrebel does not move when a html or js is changed.
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<!-- appserver -->
<dir name="/home/xx/data/appserver/target/classes/main"/>
<dir name="/home/xx/data/appserver/target/resources/main"/>
<!-- module -->
<dir name="/home/xx/data/as.module.core/target/classes/main"/>
<dir name="/home/xx/data/as.module.core/target/resources/main"/>
<dir name="/home/xx/data/as.module.mqlcore/target/classes/main"/>
<dir name="/home/xx/data/as.module.mqlcore/target/resources/main"/>
</classpath>
<!-- web>
<link target="/">
<dir name="/home/xx/data/appserver/src/main/webapp"/>
<dir name="/home/xx/data/as.module.core/src/main/webapp"/>
<dir name="/home/xx/data/as.module.mqlcore/src/main/webapp"/>
</link>
</web -->
<web>
<link target="/">
<dirset dir="/home/xx/data">
<include name="**/src/main/webapp"/>
</dirset>
</link>
</web>
</application>
EDIT:
Interesting fact is. When I use the commented part of web configuration all three webapp folders are in the log and will be monitored for changes. But the application server can not find all of the webapp files. When I use the second <web> configuration all files are seen by the application server but are not observed by jrebel. I think it is not possible to have multiple directories linked to "/"
Each of the modules eg .war or .jar files need to have their own rebel.xml files. Otherwise all of them will reload same resources and when having different classloaders all kind of weird things can happen.
It is possible to check which instance of the file JRebel actually uses by searching "found resource" from jrebel.log. It should be written something like this
sun.misc.Launcher$AppClassLoader#184be29 found resource: 'cfg/log4j.xml' from 'file:/C:/Projects/testproject/Trunk/edm/target/cfg/log4j.xml'.
It is also seen which of the file changed by loking up lines with Event like this:
[IntelliJFSNotify] Event 'CHANGE' on: 'C:/Projects/testproject/Trunk/edm/target/cfg/log4j.xml'
Usually found resource and changed file paths do not match if the file is not reloaded. If they do match then it is recommended to send absolute path of the file and jrebel.log to support#zeroturnaround.com for investigation.
Ok, the answer is: indeed it is not possible to configure more than one directory under the <web><link target="/"></link></web> configuration. I have now a folder ./target/all-webapp where I smylink (cp -sR) all files via gradle task ... not nice but works ... and thank god jrebel is following symlinks!

how to give dataadaptor in jasper report

I have created a .jrxml file using iReport eclipse plugin. It takes json as an input. I have created jsonDataAdaptor inside the eclipse to export the report. Now I want to do the same using java, not iReport.
I have a .jrxml file and i am compiling the file using:
JasperCompileManager.compileReportToFile
In the .jrxml file I have created some fields for the json and have used in textField.
<field name="username" class="java.lang.String">
<fieldDescription><![CDATA[username]]></fieldDescription>
</field>
<field name="pwd" class="java.lang.String">
<fieldDescription><![CDATA[pwd]]></fieldDescription>
</field>
I am having the username and pwd's in the test.json that is placed in my local drive in the same path as the .jrxml file.
My dataAdapter(in the same folder as .jrxml file):
<?xml version="1.0" encoding="UTF-8" ?>
<jsonDataAdapter class="net.sf.jasperreports.data.json.JsonDataAdapterImpl">
<name>jsonDataAdaptor</name>
<fileName>C:\test\test.json</fileName>
<useConnection>false</useConnection>
<timeZone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
dirty="false" DSTSavings="0" raw-offset="19800000"
xsi:type="java:sun.util.calendar.ZoneInfo">
<ID>Asia/Calcutta</ID>
<display-name>India Standard Time</display-name>
</timeZone>
<locale country="US" language="en" />
<selectExpression></selectExpression>
<datePattern></datePattern>
<numberPattern></numberPattern>
</jsonDataAdapter>
The problem is, when I am exporting the same into html I am getting values as null.
Here is the link for jasper datasource adapter.

Eclipse and IvyDE warning: Classpath Dependency Validator Message

I created a new Dynamic Web Project in Eclipse Kepler, and as it's my first time using IvyDE, I put some dependencies to test it out. here is my ivy.xml:
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="net.myorg"
module="mymodule"
status="integration">
</info>
<dependencies>
<dependency org="org.hibernate" name="hibernate-entitymanager" rev="4.2.3.Final"></dependency>
<dependency name="log4j" rev="1.2.17" org="log4j"></dependency>
</dependencies>
</ivy-module>
The dependencies where resolved and I can see them in the project libraries.
But after this, my project started giving this warning:
Description Resource Path Location Type
Classpath entry org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=myproject&ivyXmlPath=ivy.xml&confs=*&acceptedTypes=jar%2Cbundle%2Cejb%2Cmaven-plugin&alphaOrder=false&resolveInWorkspace=true&retrievedClasspath=true&retrievedClasspathPattern=lib%2F%5Btype%5Ds%2F%5Bartifact%5D-%5Brevision%5D.%5Bext%5D&retrievedClasspathSync=true&retrievedClasspathTypes=* will not be exported or published. Runtime ClassNotFoundExceptions may result. myproject P/myproject Classpath Dependency Validator Message
So if I am understanding it right, Eclipse is warning me that the IvyDE entry in the classpath don't correspond to a resource that will be in the builded project. I suppose this is the expected behavior, if so, is there a way to remove this warning from the project, without disabling every Classpath Dependency Validator Message?
The reason for the warning message is that the Eclipse flexible project deployment mechanism doesn't know whether or not to deploy the libraries referenced by the Ivy container. So you need to explicitly tell it which you want to do, deploy the jars to WEB-INF/lib or not.
If you need this container deployed to WEB-INF/lib you need to:
Right click project go to properties
Select Deployment Assembly
Click Add
Select "Java build path entries"
Select the Ivy container
Click Finish
Make sure the Deploy Path is set to "WEB-INF/lib"
If you look into the .classpath settings file you will see this adds an entry like this:
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=ivy-test-portlet&ivyXmlPath=ivy.xml&confs=*&ivySettingsPath=%24%7Bliferay_sdk_dir%3Aivy-test-portlet%7D%2Fivy-settings.xml&loadSettingsOnDemand=false&ivyUserDir=%24%7Bliferay_sdk_dir%3Aivy-test-portlet%7D%2F.ivy&propertyFiles=">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
Notice the <attributes>...</attributes> element has been added. Also my Ivy container path will be different than yours as this is a Ivy container path for one of my own projects.
Now if you don't need to deploy these libraries contained in the Ivy container to your runtime, then you need to tell Eclipse that there is no dependency on these libraries at runtime. You can do that by adding the appropriate attributes in the .classpath file.
Open .classpath file
Find the entry for the Ivy container
Manually add the following attributes element as a child element of the classpathentry
The final element will look something like this. Your path will have different options but the key part is the attributes child element:
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=ivy-test-portlet&ivyXmlPath=ivy.xml&confs=*&ivySettingsPath=%24%7Bliferay_sdk_dir%3Aivy-test-portlet%7D%2Fivy-settings.xml&loadSettingsOnDemand=false&ivyUserDir=%24%7Bliferay_sdk_dir%3Aivy-test-portlet%7D%2F.ivy&propertyFiles=">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
Either one that you choose, you have explicitly told Eclipse how to handle this library container dependency during deployment. So now you can re-validate the project (right click project and choose "Validate") and you should see the error go away.

create a .war file from gwt-project

How do I create a .war-file from my gwt-project in eclipse?
I always use Ant build file, so the project gets compiled and packaged as a war with one click.
Add an xml-file to your project with the following content:
<project name="test" basedir="." default="default">
<property name="src.dir" value="src" />
<property name="build.dir" value="war" />
<path id="compile.classpath">
<fileset dir="${build.dir}/WEB-INF/lib">
<include name="**/*.jar" />
<include name="**/*.xml" />
</fileset>
</path>
<target name="default" depends="gwtc, buildwar,deploy">
</target>
<target name="gwtc" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="${src.dir}" />
<path refid="compile.classpath" />
</classpath>
<arg line="-logLevel INFO" />
<jvmarg value="-Xmx1024M" />
<arg value="YourProject.EntryPointClass" />
</java>
</target>
<target name="buildwar">
<war basedir="war" destfile="YourProject.war" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="war/WEB-INF/">
<include name="**/gwt-servlet.jar" />
<include name="**/classes/**" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="YourProject.war" todir="." />
</target>
</project>
(Edit `YourProject.EntryPointClass to the path to your EntryPoint-class)
You would need to add gwt-user.jar and gwt-dev.jarto your projects build path(right click on your project -> Build Path -> Add External Achives).
If you now look at your "Problems"-view you get a warning that the two files are not available on the server's class path. You can use the QuickFix to either copy it to WEB-INF/lib or hide the warning. The build file will not include those two file in the war-file.
All you need to do to compile and create the file is to right click the xml-file and select run as Ant Build.
Using Eclipse:
right click the project
choose Google→GWT Compile
when compilation has finished, the console will say i.e.
Linking into /home/janus/bpworkspace/gwtwerkstatt2/war/gwtwerkstatt2
Link succeeded
Compilation succeeded -- 28.623s
open a terminal and navigate to the directory
create the WAR: jar cv * > /tmp/myGWTproject.war
you can now launch it with jetty-runner or similar: java -jar jetty-runner-8.1.7.v20120910.jar /tmp/myGWTproject.war
I just found this solution, and it's amazing :)
Just install the jar and enjoy extracting to a war file.
Project Site
http://code.google.com/p/gwt-project-export-wizard/
One can also use webAppCreator to generate Ant build file.
webAppCreator ships with GWT SDK and also with Eclipse GWT Plugin. First locate GWT plugin directory
find $HOME/.eclipse/ -name "*gwt*sdk*"
this will output GWT plugin dir path. This dir has gwt dir something like gwt-2.4.0. WebAppCreator will be in this dir. Set this dir as GWTSDK_HOME.
export GWTSDK_HOME=/home/m/.eclipse/org.eclipse.platform_3.7.0_1364963873/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0
make webAppCreator executable
chmod 755 $GWTSDK_HOME/webAppCreator
Now create a project using webAppCreator in some temp dir.
$GWTSDK_HOME/webAppCreator -out fins in.m.fins.Fins
in.m.fins.Fins is the module name. This has to match with your project's gwt.xml in Eclipse workspace. If your gwt.xml is src/in/m/fins/Fins.gwt.xml then module name should be in.m.fins.Fins
-out fins will create the project and build.xml in fins directory. Copy generated build.xml file to your project in Eclipse workspace.
Run war target in Eclipse Ant Window to package your project as war
You have to have GWT designer installed from here
http://dl.google.com/eclipse/inst/d2gwt/latest/3.7
In Eclipse on the main panel click on "Deploy module on aplication server" (It's next to blue google button).
Chose war file name and location where to store it
Click ok
That's it. Works on my GWT 2.4.0, Google Plugin for Eclipse 4.2, Eclipse Juno
For future reference: you'll find another tutorial on how to create a .war using Eclipse on http://blog.elitecoderz.net/.
Fist compile your project. Then:
1. Open your project.
2. Navigate to war folder.
3. Go to File>Export>Archive File
4. Export your war FOLDER as zip file.
5. Change your file extension form .zip to .war
6. Keep calm and enjoy your war file.
Compile your project. Then:
Open your project.
Navigate to war folder.
Go to File>Export>Archive File
Export your war FOLDER as zip file.
Change your file extension form .zip to .war
Keep calm and enjoy your war file.

Categories