system cannot found the file - java

I am getting this error when I'm using .jrxml file in NetBeans applications
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: \schoolmngt\FirstReport.jrxml (The system cannot find the file specified)
Compi at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:174)
The code id
try{
System.out.println("Compiling report...");
JasperCompileManager.compileReportToFile("/schoolmngt/FirstReport.jrxml");
System.out.println("Filling report...");
JasperFillManager.fillReportToFile("/schoolmngt/FirstReport.jasper",new HashMap(), new JREmptyDataSource());
//JasperRunManager.runReportToHtmlFile("FirstReport.jasper",new HashMap(),new JREmptyDataSource());
JasperRunManager.runReportToPdfFile("/schoolmngt/FirstReport.jasper",new HashMap(),new JREmptyDataSource());
}
catch(Exception ee){ee.printStackTrace();}
My file path is:
D:\Schoolmngt\src\schoolmngt\FirstReport.jrxml
When I run the project this error is coming regularly please tell me the solution.

Relative paths do not start with /. /schoolmngt/FirstReport.jrxml is an absolute path.
If the current drive is D: it will look for D:/schoolmngt/FirstReport.jrxml

I had the same problem, but I didn't have time to resolve it so I just provided the full path (starting with drive letter) and it worked. I know it doesn't really fix the problem properly, but if want to just make it working for now try it.

The path in your code should be src/schoolmngt/FirstReport.jrxml.

Related

Applet cannot recognize relative path on Tomcat Service?

I got some errors in my app. The app is using applet for accessing local file system.
converting file, for example.
First: Using relative path.
I can place project folder wherever I need and the application still working properly. However, when I placed it on the tomcat server directory, it cannot find the files' path.
Run with browser: file:///C:/report-param/index.html, ok
Run with browser: localhost:8080/report-param/index.html, error
Second: Using absolute path.
The application working well in both browser and tomcat server.
Run with browser: file:///C:/report-param/index.html, ok
Run with browser: localhost:8080/report-param/index.html, ok
Here is my sample code:
File jrxmlPath = new File("reports//people-report-withparam-multi.jrxml");
File pdfPath = new File("reports//people-report-withparam-multi.pdf");
String sourceJrxml = jrxmlPath.getPath();
String destPdf = pdfPath.getPath();
JasperReport jasperReport = JasperCompileManager.compileReport(sourceJrxml);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, paramMap,
getPostgreSQLDataSource(driverUrl, username, password));
JasperExportManager.exportReportToPdfFile(jasperPrint,destPdf);
What is the matter on here? Any ideas?
How can I fix the error above? Please help...
Note: if you don't understand, feel free to ask me...

The process cannot access the file because it is being used by another process (java)

I am trying to replace a jar file after it's been added to the class path programmatically.
When I try to replace a jar that's been loaded, it gives me the subject error.
I'm using Windows 8 , and JDK 7.
Any suggestions or workaround is highly appreciated.
error line
Files.copy(Paths.get(sourcePath), Paths.get(desPath), StandardCopyOption.REPLACE_EXISTING);
exception
java.nio.file.NoSuchFileException: D:\test\test.jar
> D:\project\plugins\test.jar
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsFileCopy.copy(WindowsFileCopy.java:205)
at sun.nio.fs.WindowsFileSystemProvider.copy(WindowsFileSystemProvider.java:278)
at java.nio.file.Files.copy(Files.java:1225)
at org.test.Test.apply(Test.java:89)

Java code to read excel on Mac

I have been trying to read excel using java code but i am not sure what should be the excel path. This is what i am using on mac:
String xPath = "Desktop/ReadData.xls".
I am getting error message "No such file found"
How the path should be given on mac?
Please help guys. Thanks in advance
If the file is in the desktop, then the path must be specified relative to the current user's home directory, like this:
/Users/<user>/Desktop/ReadData.xls
Where <user> is your user name in the Mac. Or alternatively, you can use this shorter form:
~/Desktop/ReadData.xls

Java file path in Linux

I have a rather silly question, but I haven't been able to find a solution for this:
When I try and read a file I get a "file not found error" is runtime. It compiled the file though.
I am on Linux, so I use the statement something like:
Scanner s = new Scanner(new File("home/me/java/ex.txt"));
and it gives me a runtime rror:
/home/me/javaException in thread "main" java.io.FileNotFoundException: home/me/java/ex.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:137)
at java.util.Scanner.<init>(Scanner.java:653)
at test.main(test.java:14)
I tried changing every possible thing along the lines of filenames, but nothing seems to work.
Any clues as to why this is happening? where does java look for files by default?
Looks like you are missing a leading slash. Perhaps try:
Scanner s = new Scanner(new File("/home/me/java/ex.txt"));
(as to where it looks for files by default, it is where the JVM is run from for relative paths like the one you have in your question)
I think Todd is correct, but I think there's one other thing you should consider. You can reliably get the home directory from the JVM at runtime, and then you can create files objects relative to that location. It's not that much more trouble, and it's something you'll appreciate if you ever move to another computer or operating system.
File homedir = new File(System.getProperty("user.home"));
File fileToRead = new File(homedir, "java/ex.txt");
The Official Documentation is clear about Path.
Linux Syntax: /home/joe/foo
Windows Syntax: C:\home\joe\foo
Note: joe is your username for these examples.

Deployment in tomcat

i am getting a problem
i have deployed a war file, when i run localy through tomcat it works fine but when i run on another system by giveing my system ip and then project folder e.g
http:\192.168.0.145\DllTest it loads the applet but when i click on a button to load the functionality it is throwing an exception
Exception in thread "AWT-EventQueue-3" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: http:\192.168.0.145:8080\DllTest\lib\jinvoke.dll
while it is working fine localy but not in another system. Please tell me what is the problem.
Is it a rights issue or something else.
You cannot load a DLL on an external host. It has to be an absolute disk file system -as the exception message already hints. Your best bet is to download it manually, create a temp file and load it instead.
File dllFile = File.createTempFile("jinvoke", ".dll");
InputStream input = new URL(getCodeBase(), "lib/jinvoke.dll").openStream();
OuptutStream output = new FileOutputStream(dllFile);
// Write input to output and close streams the usual Java IO way.
// Then load it using absolute disk file system path.
System.loadLibrary(dllFile.getAbsolutePath());
dllFile.deleteOnExit();

Categories