I am developing a point of sales system in java using ireport as my reporting tool, which works fine in the IDE (Netbeans), but after packaging with install anywhere the ireport does not work anymore. Can anyone help on which library I might have excluded. Or where I am mistaken
Your executable jar file not working because it can't find its dependent jar file any more in the packaging. You can also get the exact exception by running application by cmd. like:
cmd -> open directory which contain your jar file -> write jarfile.jar
You have to do following steps:
open properties of your project
click on build => packaging
than you must check on copy dependent liraries
output package will pack your project in jar file and libraries in lib folder
you must move your lib folder as well if your moving your jar file
I've made a temporary solution to this problem about iReport/jasper report not opening/making an executable.
Seems that the program cannot locate the .jrxml/.jasper file in its default location (within the project folder usually with the build and manifest file) so the alternative would be to save the report file somewhere in the hard disk. ex. "D:/Files and Documents/Documents/report1.jrxml"
This works but somehow not the proper way.
After you design your report in jrxml, then compile it
(click that icon).
then change your jrxml report to jasper, like this.
Map<String, Object> nim = new HashMap<String, Object>();
nim.clear();
Statement stmt2 = SGB.c.createStatement();
ResultSet rs = stmt2.executeQuery("select * from mytable;");
JasperPrint jasperPrint = JasperFillManager.fillReport("report.jasper", nim, new JRResultSetDataSource(rs));
JasperViewer jv = new JasperViewer(jasperPrint);
formReport fformReport = new formReport(mainform,true);
fformReport.setBounds(jv.getBounds());
fformReport.getContentPane().add(jv.getContentPane());
fformReport.setLocationRelativeTo(null);
fformReport.setVisible(true);
Related
I use new ClassPathResource("myFolder") to get some files from this folder "myFolder".
File file = new ClassPathResource("myFolder").getFile();
This returns file path my-project\build\eclipse\test\myFolder instead of my-project\build\test\myFolder
How can I fix it?
It seems that you have a classpath issue in eclipse. The result that you're getting is like that because eclipse does it's own voodoo when youre building and running the application.
Check your classpath in eclipse (and also in the Run Configurations).
Below is my code which works perfect in Eclipse Java Project
String IEPath = "src/IEDriverServer.exe";
File file = new File(IEPath);
System.setProperty("webdriver.ie.driver",file.getPath());
WebDriver driver = new InternetExplorerDriver();
If I export the same code to a runnable JAR file and double click it or if I run it from command prompt gives below exception
The driver ececutable does not exist C:\Backup\New folder\src\IEDriverServer.exe
I have copied IE exe inside my Java Project and have exported the Java Project including the IE exe. When I run the JAR, it is failing to pick the IE exe path.
Please help! TIA!
You have two options here:
Read the resource inside the jar. See more info here.
Use WebDriverManagerto automate the management of IEDriverServer.exe.
For alternative 2, simply import the WebDriverManager library in your project and change your code:
String IEPath = "src/IEDriverServer.exe";
File file = new File(IEPath);
System.setProperty("webdriver.ie.driver",file.getPath());
... by:
InternetExplorerDriverManager.getInstance().setup();
I'm trying to export a java project in eclipse as a runnable jar, but for some reason the runnable jar doesn't work. If I double click the executable jar, it doesn't do anything. I tried both extract and package required libraries into generated jar.
So I also tried to export some simpler projects, those worked fine. The biggest difference is my real project has files: images and xml files.
In code reference them like this:
File file = new File("Recources/test.xml");
ImageIcon imageIcon = new ImageIcon("Recources/" + num + ".gif");
The structure of the project looks like this:
But in the executable jar they look like this:
Thank you for your help.
Edit:
I have tried the 'java -jar filename.jar', but now it says it can't find my resources folder, while in eclipse it can still find it.
Files in a JAR-File aren't just like files stored in your hard-disc. If you include files in a JAR, they'll be seen as a Stream of Bytes. So you have to use different methods to access these resources.
//To read/access your XML-File
BufferedReader read = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/test.xml")));
//To read/access your gif-Files
ImageIcon icon = new ImageIcon(this.getClass().getResource("/"+num+".gif"));
"/" is not the root-Folder of your file-system, but the root folder of the resources inside your JAR.
The issue may be that Java is not the default program to run the jar.
Try right click -> Open with, and select the Java Runtime, and it should run successfully.
Make it the default program to enable double-click running.
Right click -> Properties -> Change -> C:\Program Files\Java\jre7\bin\javaw.exe
Inspired by stratwine's answer at https://stackoverflow.com/a/8511277
So thank you all, but it seems like the problem wasn't the export only. There was an error I saw when I opened my program with cmd, I was using file name to open xml and images while I should have used inputStreams: https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html.
I am developing intellij plugin, on click of menu option it should copy jar to libs folder of select project. kindly provide any link or code how I can implement this.
jar is on this path "project_name\resources\raw\xyz.jar" and using below code to get that jar as inputsream but getting "NULL"
ClassLoader CLDR = this.getClass().getClassLoader();
InputStream is = CLDR.getResourceAsStream("raw/xyz.jar");
Try something like this:
PluginId runtimePluginId = PluginManager.getPluginByClassName("com.company.AnyClassInYourPlugin");
IdeaPluginDescriptor runtimePlugin = PluginManager.getPlugin(runtimePluginId);
File yourJar = new File(runtimePlugin.getPath().getAbsolutePath(), "your-file.jar");
Given any class that's contained in your plugin, the API allows you to retrieve a plugin descriptor for that plugin, which then allows you to get the absolute path to the plugin or any jar related to it.
See this real example of how to retrieve a JAR embedded in a plugin.
hi friends I have created a java project and also used jasper reports in that project to generate reports, when I package my java project to .exe installer the jasper reports is working fine, but when I deploy that exe installer in another system the jasper report is not working ie:jasper reports is invoking in my system but not in another systems, I know that I have to change my file path but I don't know how to give file path which is accepted in all the systems and jasper reports will be working fine in another system too.
my code is :
try( InputStream is = getClass().getResourceAsStream("C:\\Users\\Applebj\\Documents\\NetBeansProjects\\JavaApplication14\\src\\resources\\bil.jrxml")){
String txt = jLabel1.getText();
String t1=lb2.getText();
String t2=lbl3.getText();
Connection cn;
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/billing", "root", "");
Map <String,Object> mp =new HashMap <String,Object>();
mp.put("bj", txt);
mp.put("hpy",t1);
mp.put("li",t2);
// URL urpo=getClass().getResource("/resources/bil.jrxml");
JasperReport jasperReport;
jasperReport = JasperCompileManager.compileReport(is);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,mp, cn);
// JasperExportManager.exportReportToPdfFile(jasperPrint, "C:\\Users\\Applebj\\Desktop\\rep\\simple_report.pdf");
JasperExportManager.exportReportToPdfFile(jasperPrint, "bil.pdf");
JasperViewer.viewReport(jasperPrint);
}
catch(Exception eey){
eey.printStackTrace();
System.out.println(eey.getMessage());
}
kindly help me to resolve this problem thanks in adavance
Depending on how you build your application, you will need to ensure that the .jrxml file is included within the resulting .jar file.
In Netbeans and Eclipse, you should be able to drop the .jrxml file into the src directory and it should be bundled as part of the build process.
This means you will no longer be able to refer to the .jrxml as a file, but instead, you will need to treat it as a embedded resource...
try (InputStream is = getClass().getResourceAsStream("/path/to/report/relative/to/the/src/directory/bil.jrxml")) {
JasperReport jasperReport = JasperCompileManager.compileReport(is);
}
(Nb it still possible that the JasperCompileManager will throw exceptions you need to handle, but at least the InputStream will be closed properly)
What this means is, if you put the bil.jrxml report in the src/resources directory (for example), you would need to use the path /resources/bil.jrxml
Now, I will discourage you from compiling a .jrxml file at runtime, as it's not a short process and the reporting process can already take several seconds if not longer, so you won't want to keep your users waiting, instead, pre-compile them and use the resulting .jasper file instead, which you can load at runtime...