Thursday, October 3, 2013

java.sql.SQLException: No suitable driver found for jdbc:mysql on Hibernate

No comments:
java.sql.SQLException: No suitable driver found for jdbc:mysql



To fix this issue add property

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

in hibernate.cfg.xml file.
Read More

Monday, August 12, 2013

Confluence Publisher Plugin with Jenkins

No comments:
Confluence Publisher Plugin with Jenkins



1) First I installed the confluence publisher plugin in jenkins.

2) Created a account in confluence (on demand service).

3) Get the Server Base Url,




Wiki Url will be like,





4) Configure this Confluence Url in jenkins global configuration



5) Then confgiure which file need to be uploaded in Specific job configuration




6) The specified files will be uploaded to the confluence, the jenkins console will be like,




7) Attached files can be found in confluence in the link



--
Thank you.
Read More

Tuesday, August 6, 2013

Error extracting plugin descriptor: 'Goal: * already exists in the plugin descriptor for prefix: *

1 comment:

Do you face this issue ?

Error extracting plugin descriptor: 'Goal: * already exists in the plugin descriptor for prefix: *
[ERROR] Existing implementation is: *.*Mojo
[ERROR] Conflicting implementation is: *.*Mojo'
[ERROR] -> [Help 1]



Solution :

You may encounter this error when changing a build -> directory on pom.xml

By default build directory will be target directory. If you face this issue, delete the target directory as well as newly specified build directory and install again.

Happy Coding :)
Read More

Monday, June 17, 2013

Jquery combine two objects values into a single object

No comments:
Jquery is having inbuilt function called  extend,
 which can be used to merge two objects values in a single object.
 
 
var data1 = {
   duration: 100
};
    
var data2 = {
   duration: 110
};

console.log("Before Data1 " + JSON.stringify(data1));
console.log("Before Data2 " + JSON.stringify(data2));

/* merge data2 into data1 */
    $.extend(data1, data2);

console.log("After Data1 " + JSON.stringify(data1));


console.log("After Data2 " + JSON.stringify(data2));

OUTPUT : 

  
  
Happy Coding :)
Read More

Tuesday, May 7, 2013

W3C DOM Parser

No comments:
W3C DOM Parser

We can use both jdom as well as w3c dom. In this I am going to explain about w3c dom.


Getting the document on w3c dom.



Some common function for Dom processing


We can specify the xpath value to get the specific tag/ Node.


From other resource example (stackoverflow),

Getting all the tags called "sites" and getting child node value using getTagValue common method.




Happy Coding :)
Read More

Saturday, May 4, 2013

Struts2 Application developemnt with Jquery

No comments:
Struts2 Application developemnt with Jquery

It is very easy to integrate Struts2 applicaiton with Jqery. There are many existing solution that can be used to solve it. No need to start from scratch.

http://struts.jgeppert.com/struts2-jquery-showcase

Which is popular among the jquery plugin. This site is having nice tutorial.

Other Sites :
http://malsup.com/jquery/form/#fields


http://struts.jgeppert.com is also having struts2-bootstap plugin, which contains bootstarp theme that can be integrated with struts2. Instead of struts2 default theme. We can use bootstarp theme.



--
Thank you.


Regards,
Kaleeswaran.S
Read More

Thursday, April 18, 2013

Send JSON data to struts2

No comments:
Send JSON data to struts2


I found a nice article which points out how the struts2 receives json data from UI and returns the json data as response.


We need to add a dependency in pom.xml

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-json-plugin</artifactId>
            <version>${struts2-json-plugin.version}</version>
        </dependency>


In action class just add the interceptor which maps the json data to the actions class.
    <action name="jsonTest" class="com.blah.action.JsonTestAction">          <interceptor-ref name="json">              <param name="contentType">application/json</param>          </interceptor-ref>          <result type="json"/>      </action>

Json data can be returned from strust2 action to View in the form of

        <action name="jsonTest" method="jsonTest" class="com.blah.action.JsonTestAction">
            <result type="json"/>
        </action>


Happy Coding.

--
Thank you.


Regards,
Kaleeswaran.S
Read More

Wednesday, April 17, 2013

Confluence Publisher Plugin with Jenkins

2 comments:
Confluence Publisher Plugin with Jenkins

I integrated confluence publisher plugin with Jenkins. Here are the steps, it may be helpful to some one.

1) First I installed the confluence publisher plugin in jenkins.

2) Created a account in confluence (on demand service).

3) Get the Server Base Url,




Wiki Url will be like,





4) Configure this Confluence Url in jenkins global configuration



5) Then confgiure which file need to be uploaded in Specific job configuration




6) The specified files will be uploaded to the confluence, the jenkins console will be like,




7) Attached files can be found in confluence in the link





Thats it. Enjoy Happy Coding :).

Additional Info :



--
Thank you.


Regards,
Kaleeswaran.S
Read More

Tuesday, April 16, 2013

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure on Mysql, MAMP and MAC OS

No comments:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure on Mysql, MAMP and MAC OS
I just created the a new user in phpmyadmin with all the privileges to all the databases.








and

I used the dependency

    <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>

Which didn't work and throwed the exception. After some googling find the solution. I just changed the mysql connector dependency version. Now it is working.

    <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.24</version>
    </dependency>



    public void testTheApp() throws Exception {
        Connection conn = null; 
        try {
//            WARNING: Could not obtain connection metadata
//            java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:
            System.out.println("AppTest started.... ");
            Class.forName("com.mysql.jdbc.Driver");
            Properties connectionProperties = new Properties();
            connectionProperties.put("user", "java");
            connectionProperties.put("password", "java");
            conn = DriverManager.getConnection("jdbc:mysql://0.0.0.0:8889/java", connectionProperties);
            System.out.println("Connection success ...... ");
        } catch (Exception e) {
            e.printStackTrace();
        } finally 
        { 
            if (conn != null) 
            { 
                try 
                { 
                    conn.close (); 
                    System.out.println ("Database connection terminated"); 
                } 
                catch (Exception e) { /* ignore close errors */ } 
            } 
        }
    }

jdbc:mysql://0.0.0.0:8889/java (Works)jdbc:mysql://172.16.23.59:8889/java (Works)
jdbc:mysql://172.0.0.1:8889/java (Wont work)
Happy Coding :)
Read More

Wednesday, April 10, 2013

package javax.servlet does not exist

No comments:
package javax.servlet does not exist

Add a dependency


        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>


Happy Coding :)
--
Thank you.


Regards,
Kaleeswaran.S
Read More

html5 chart library

No comments:
HTML5 chart library

HTML5 and JS library rocks on graphs. Earlier it was little difficult to implement. Now it is very easy.

Highcharts



http://www.highcharts.com/demo/line-time-series/grid

Rgraph




I have used the RGraph, it is very easy to implement. Refer the doc. There are variety of graphs are available.





http://www.rgraph.net/

amCharts
Chart.js
Flotr2



     Financial graphs are nice on this library.
http://www.humblesoftware.com/flotr2/

Float






http://www.flotcharts.org/
--
Thank you.


Regards,
Kaleeswaran.S
Read More

Tuesday, April 9, 2013

JSON generator on JAVA

No comments:

JSON generator on JAVA,

http://java.dzone.com/articles/java-api-json-processing-jsr

--
Thank you.


Regards,
Kaleeswaran.S
Read More

Interact with Jenkins through Jenkins.jar

No comments:
Interact with Jenkins through Jenkins.jar


https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTdi94ODgrLWV6OaI5CxKqXkhuZlxjhVP13i7ezOYWSdOWY5OGURZIePzh0

To get the help commands from Jenkins,

java -jar /Users/users/Downloads/jenkins-cli.jar -s http://localhost:8080/jenkins/ help

Results will be like




Trigger a build from terminal

java -jar /Users/user/Downloads/jenkins-cli.jar -s http://localhost:8080/jenkins/ build DemoJob

Jenkins-cli jar can be downloaded from http://localhost:8080/jenkins/cli

Environment variable values can be accessed from shell($FOO, %FOO%) and Ant ( ${env.FOO} )  like

The parameter are available as environment parameters. So e.g. a shell ($FOO, %FOO%) or Ant ( ${env.FOO} ) can access these values.

https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build






--
Thank you.


Regards,
Kaleeswaran.S
  
Read More

Monday, April 8, 2013

Online Free Jenkins

No comments:
Use it and Enjoy.

Happy coding.

--
Thank you.


Regards,
Kaleeswaran.S
Read More

Wednesday, March 27, 2013

Maven Options

No comments:
There are many options that can be passes as parameter to maven, those useful options are,



usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -am,--also-make                        If project list is specified, also
                                        build projects required by the
                                        list
 -amd,--also-make-dependents            If project list is specified, also
                                        build projects that depend on
                                        projects on the list
 -B,--batch-mode                        Run in non-interactive (batch)
                                        mode
 -C,--strict-checksums                  Fail the build if checksums don't
                                        match
 -c,--lax-checksums                     Warn if checksums don't match
 -cpu,--check-plugin-updates            Ineffective, only kept for
                                        backward compatibility
 -D,--define <arg>                      Define a system property
 -e,--errors                            Produce execution error messages
 -emp,--encrypt-master-password <arg>   Encrypt master security password
 -ep,--encrypt-password <arg>           Encrypt server password
 -f,--file <arg>                        Force the use of an alternate POM
                                        file.
 -fae,--fail-at-end                     Only fail the build afterwards;
                                        allow all non-impacted builds to
                                        continue
 -ff,--fail-fast                        Stop at first failure in
                                        reactorized builds
 -fn,--fail-never                       NEVER fail the build, regardless
                                        of project result
 -gs,--global-settings <arg>            Alternate path for the global
                                        settings file
 -h,--help                              Display help information
 -l,--log-file <arg>                    Log file to where all build output
                                        will go.
 -N,--non-recursive                     Do not recurse into sub-projects
 -npr,--no-plugin-registry              Ineffective, only kept for
                                        backward compatibility
 -npu,--no-plugin-updates               Ineffective, only kept for
                                        backward compatibility
 -nsu,--no-snapshot-updates             Suppress SNAPSHOT updates
 -o,--offline                           Work offline
 -P,--activate-profiles <arg>           Comma-delimited list of profiles
                                        to activate
 -pl,--projects <arg>                   Comma-delimited list of specified
                                        reactor projects to build instead
                                        of all projects. A project can be
                                        specified by [groupId]:artifactId
                                        or by its relative path.
 -q,--quiet                             Quiet output - only show errors
 -rf,--resume-from <arg>                Resume reactor from specified
                                        project
 -s,--settings <arg>                    Alternate path for the user
                                        settings file
 -T,--threads <arg>                     Thread count, for instance 2.0C
                                        where C is core multiplied
 -t,--toolchains <arg>                  Alternate path for the user
                                        toolchains file
 -U,--update-snapshots                  Forces a check for updated
                                        releases and snapshots on remote
                                        repositories
 -up,--update-plugins                   Ineffective, only kept for
                                        backward compatibility
 -V,--show-version                      Display version information
                                        WITHOUT stopping build
 -v,--version                           Display version information
 -X,--debug                             Produce execution debug output

--
Thank you.


Regards,
Kaleeswaran.S
Read More

Jenkins Environment variables

No comments:



Jenkins is having many environment variables, Each environment variable is very important one or other way. Lets see how can we use these variables efficiently  in jenkins.

E.g : BUILD_NUMBER

While archiving each build on a job. We can name the build such as MyJob_1.

Goal: -DjobName=${env.JOB_NAME}  -DbuildNumber=${env.BUILD_NUMBER}



Environment Variable Description
BUILD_NUMBER The current build number, such as "153"
BUILD_ID The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)
BUILD_URL The URL where the results of this build can be found (e.g. http://buildserver/jenkins/job/MyJobName/666/)
NODE_NAME The name of the node the current build is running on. Equals 'master' for master node.
JOB_NAME Name of the project of this build. This is the name you gave your job when you first set it up. It's the third column of the Jenkins Dashboard main page.
BUILD_TAG String of jenkins-${JOB_NAME}-${BUILD_NUMBER}. Convenient to put into a resource file, a jar file, etc for easier identification.
JENKINS_URL Set to the URL of the Jenkins master that's running the build. This value is used by Jenkins CLI for example
EXECUTOR_NUMBER The unique number that identifies the current executor (among executors of the same machine) that's carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
JAVA_HOME If your job is configured to use a specific JDK, this variable is set to the JAVA_HOME of the specified JDK. When this variable is set, PATH is also updated to have $JAVA_HOME/bin.
WORKSPACE The absolute path of the workspace.
SVN_REVISION For Subversion-based projects, this variable contains the revision number of the module. If you have more than one module specified, this won't be set.
CVS_BRANCH For CVS-based projects, this variable contains the branch of the module. If CVS is configured to check out the trunk, this environment variable will not be set.
GIT_COMMIT For Git-based projects, this variable contains the Gitish of the commit checked out for the build
GIT_BRANCH For Git-based projects, this variable contains the Git branch that was checked out for the build (normally master)


--
Thank you.


Regards,
Kaleeswaran.S
Read More

Eclipse Remote Debugging

No comments:
Eclipse Remote Debugging




In earlier posts, I wrote about remote debugging with eclipse. Today i found some interesting eclipse debugging blogs,


http://javarevisited.blogspot.in/2011/02/how-to-setup-remote-debugging-in.html

http://javarevisited.blogspot.in/2011/07/java-debugging-tutorial-example-tips.html



--
Thank you.


Regards,
Kaleeswaran.S
Read More

Wednesday, March 13, 2013

Jenkins CLI commands

No comments:

Jenkins CLI commands

  

  • build: Builds a job, and optionally waits until its completion.
  • cancel-quiet-down: Cancel the effect of the "quiet-down" command.
  • clear-queue: Clears the build queue
  • connect-node: Reconnect to a node
  • copy-job: Copies a job.
  • create-job: Creates a new job by reading stdin as a configuration XML file.
  • delete-builds: Deletes build record(s).
  • delete-job: Deletes a job
  • delete-node: Deletes a node
  • disable-job: Disables a job
  • disconnect-node: Disconnects from a node
  • enable-job: Enables a job
  • get-job: Dumps the job definition XML to stdout
  • groovy: Executes the specified Groovy script.
  • groovysh: Runs an interactive groovy shell.
  • help: Lists all the available commands.
  • install-plugin: Installs a plugin either from a file, an URL, or from update center.
  • install-tool: Performs automatic tool installation, and print its location to stdout. Can be only called from
    inside a build.
  • keep-build: Mark the build to keep the build forever.
  • list-changes: Dumps the changelog for the specified build(s).
  • login: Saves the current credential to allow future commands to run without explicit credential information.
  • logout: Deletes the credential stored with the login command.
  • mail: Reads stdin and sends that out as an e-mail.
  • offline-node: Stop using a node for performing builds temporarily, until the next "online-node" command.
  • online-node: Resume using a node for performing builds, to cancel out the earlier "offline-node" command.
  • quiet-down: Quiet down Jenkins, in preparation for a restart. Don't start any builds.
  • reload-configuration: Discard all the loaded data in memory and reload everything from file system. Useful when
    you modified config files directly on disk.
  • restart: Restart Jenkins
  • safe-restart: Safely restart Jenkins
  • safe-shutdown: Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down
    Jenkins.
  • set-build-description: Sets the description of a build.
  • set-build-display-name: Sets the displayName of a build
  • set-build-result: Sets the result of the current build. Works only if invoked from within a build.
  • shutdown: Immediately shuts down Jenkins server
  • update-job: Updates the job definition XML from stdin. The opposite of the get-job command
  • version: Outputs the current version.
  • wait-node-offline: Wait for a node to become offline
  • wait-node-online: Wait for a node to become online
  • who-am-i: Reports your credential and permissions
Ref : http://www.kellyrob99.com/blog/2012/02/26/hooking-into-the-jenkinshudson-api-part-2/

--
Thank you.


Regards,
Kaleeswaran.S
Read More

Monday, March 11, 2013

XMLPropertyListConfiguration / Plist Parser example

No comments:

XMLPropertyListConfiguration / Plist Parser example



XMLPropertyListConfiguration is having a fantastic API to work with plist files. But there is no much example for this library. After some googling and library analysis, it came to know that it is very very easy to parse the files !. Here is the example.


    @Test
    public void test() {
        try {
            String plistFile = "/Users/plistFile/info.plist";
            XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();

            HashMap life = new HashMap();
            life.put("Home", "home.png");
            life.put("Office", "browse.png");
            life.put("School", "mycart.png");
            life.put("College", "offers.png");
            plist.addProperty("Life", life);
           
            HashMap phones = new HashMap();
            phones.put("Nokia", "8000");
            phones.put("Samsung", "4000");

            List<String> imagesArray = new ArrayList<String>();
            imagesArray.add("icon1.png");
            imagesArray.add("icon2.png");
            imagesArray.add("icon3.png");
            phones.put("PhoneIcons", imagesArray);
            plist.addProperty("Phones", phones);
           
            List<String> imagesArray1 = new ArrayList<String>();
            imagesArray1.add("icon1.png");
            imagesArray1.add("icon2.png");
            imagesArray1.add("icon3.png");
                       
            Map dashBoard = new HashMap();
            dashBoard.put("imgArray", imagesArray1);

            plist.addProperty("ImageArrayBoard", dashBoard);
            plist.addProperty("ImageArray.innnerLevelTag", "IamInnerLevelTag");
            plist.save(plistFile);

            System.out.println("File saved .... ");
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
        }
    }

Thats All, Happy Coding :)

Ref : http://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.html
Read More

Wednesday, January 23, 2013

How to print base64 image in jasper report pdf ?

1 comment:

How to print base64 image in jasper report pdf ?

1) import base64 class in jrxml file <import value="org.apache.commons.codec.binary.Base64"/>

2) Create two parameters logo and base64Img in jasper report.

3) logo parameter class as String (java.lang.String) and

4) base64Img parameter class as InputStream (java.io.InputStream) and

5) base64Img parameter Default Value expression should be like "new ByteArrayInputStream(new Base64().decodeBase64($P{logo}.getBytes("UTF-8")))"

Thats all..

Note :
parameter class - specifies the type of that parameter
Default Value expression - just like method. we can write our implementation here.

    @Test
    public void base64ImageAsStream() {
        try {
            compileReports();
            System.out.println("report ");
            String outFileNamePDF = "/Users/user/Tried/POC/imageStreamToPdf/base64ImageStream.pdf";
            new File(outFileNamePDF).getParentFile().mkdirs();
            String containerJrxmlFile = "/Users/user/Tried/POC/imageStreamToPdf/imageToStreamPdf.jrxml";
           
            Map<String, Object> parameters = new HashMap<String,Object>();
            File img = new File("/Users/user/Desktop/wallpaper.jpg");
            InputStream fis = new FileInputStream(img);
           
            byte[] imgByte = null;
            imgByte = IOUtils.toByteArray(fis);
            byte[] encodedImage = Base64.encodeBase64(imgByte);
            String encodeImg = new String(encodedImage);
           
            System.out.println("printnng");
            parameters.put("logo", encodeImg);
           
            InputStream reportStream = new FileInputStream(containerJrxmlFile);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(reportStream);
            JasperDesign jasperDesign = JRXmlLoader.load(bufferedInputStream);
           
//            JasperReport jasperReport = (JasperReport) JRLoader.loadObject("/Users/user/Tried/POC/imageStreamToPdf/imageToStreamPdf.jasper");
           
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
           
            JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
            exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.exportReport();
           
            System.out.println("pdf report created .... ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Enjoy the coding !!!
--
Thank you.


Regards,
Kaleeswaran.S
Read More

How to apply dynamic colors to jasper report ?

No comments:
How to apply dynamic colors to jasper report ?

After some googling, i found the way to apply colors dynamically to jasper report.

My working code is,

We can access all the jasper files styles and everything with the help of JasperDesign class.
Just create some styles like header, body and footer and set colors for those style from java file.

The code "styleList[j].setBackcolor(
userBackGRDColor);" - sets the back groud color of a style

    @Test
    public void dynamicColorPdf() {
        try {
            System.out.println("pdf report creation started .... ");

            String outFileNamePDF = "/Users/user/Tried/POC/
imageStreamToPdf/dynamicColorPdf.pdf";
            new File(outFileNamePDF).
getParentFile().mkdirs();
            String containerJrxmlFile = "/Users/user/Tried/POC/
imageStreamToPdf/dynamicColorPdf.jrxml";
           
            Map<String, Object> parameters = new HashMap<String,Object>();
           
            InputStream reportStream = new FileInputStream(
containerJrxmlFile);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(
reportStream);
            JasperDesign jasperDesign = JRXmlLoader.load(
bufferedInputStream);
           
            JasperReport jasperReport = JasperCompileManager.
compileReport(jasperDesign);
            JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, parameters, new JREmptyDataSource());
           
            // applying styles
            java.awt.Color userForeColor = new java.awt.Color(255, 69, 0);
            java.awt.Color userBackGRDColor = new java.awt.Color(255, 0, 0);
            JRStyle[] styleList = jasperPrint.getStyles();
            System.out.println("styleList.length => " + styleList.length);
            for (int j = 0; j < styleList.length; j++) {
                System.out.println("styleList[j].getName() => " + styleList[j].getName());
                    if (styleList[j].getName().equals("style1")) {
                            styleList[j].setBackcolor(userBackGRDColor);
                            styleList[j].setForecolor(userForeColor);
                            jasperPrint.addStyle(styleList[j], true);
                    } else if (styleList[j].getName().equals("style2")) {
                        styleList[j].setBackcolor(userBackGRDColor);
                            styleList[j].setForecolor(userForeColor);
                            jasperPrint.addStyle(styleList[j], true);
                    }
            }

           
            JRExporter exporter = new net.sf.jasperreports.engine.
export.JRPdfExporter();
            exporter.setParameter(
JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
            exporter.setParameter(
JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.exportReport();
           
            System.out.println("pdf report created .... ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Happy coding :)

--
Thank you.


Regards,
Kaleeswaran.S
Read More

How to image stream to jasper report ?

6 comments:
How to image stream to jasper report ?

It is very easy to pass image stream to jasper report pdf.

Steps are,

1) Convert the image to stream and set it in parameter ("logo")
2) In jrxml file , create a parameter with parameter class as "java.io.InputStream"
3) Place a image on the jrxml design, set "Image Expression" to $P{logo} and "Expression class" to java.lang.String

    @Test
    public void createPdfWithImageAsStream() {
        try {
            System.out.println("pdf report creation started .... ");

            String outFileNamePDF = "/Users/user/Tried/POC/
imageStreamToPdf/createPdfWithImageAsStream.pdf";
            new File(outFileNamePDF).
getParentFile().mkdirs();
            String containerJrxmlFile = "/Users/user/Tried/POC/
imageStreamToPdf/createPdfWithImageAsStream.jrxml";
           
            // pass logo as stream.
            Map<String, Object> parameters = new HashMap<String,Object>();
            File img = new File("/Users/user/Desktop/
wallpaper.jpg");
            InputStream fis = new FileInputStream(img);
            System.out.println("printnng")
;
            parameters.put("logo", fis);
           
            InputStream reportStream = new FileInputStream(
containerJrxmlFile);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(
reportStream);
            JasperDesign jasperDesign = JRXmlLoader.load(
bufferedInputStream);
           
            JasperReport jasperReport = JasperCompileManager.
compileReport(jasperDesign);
            JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, parameters, new JREmptyDataSource());
           
            JRExporter exporter = new net.sf.jasperreports.engine.
export.JRPdfExporter();
            exporter.setParameter(
JRExporterParameter.OUTPUT_FILE_NAME, outFileNamePDF);
            exporter.setParameter(
JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.exportReport();
           
            System.out.println("pdf report created .... ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Happy coding :)

--
Thank you.


Regards,
Kaleeswaran.S
Read More