Java errors (hsqldb) - java

I am trying to start a jar file on Linux:
javac db.java #building
java -cp hsqldb.jar:. db
The code works fine with the JavaEditor on Wine:
http://pastebin.com/KVDqYydb

Looking at your code, this seems to be the problem:
new Datenbankzugriff(".\\Datenbank\\meineDB");
Linux uses forward slashes as path separator. Just convert the backslashes to forward slashes, then it should work (also on windows):
docs:
The database file path format can be specified using forward slashes in Windows hosts as well as Linux hosts.

Related

How to escape space in folder in JShell /env command in Windows

I am trying to set the external classpath in Java 11 JShell using /env --class-path command in windows OS. When the folder does not have space, it is working fine as shown below.
But when the folder is having space, it is giving error as shown below.
Could you please help how to resolve this error?
EDIT 1: enclosing the path within a single quote or double quote does not work.
This is known issue JDK-8223941 which applies to all OS if there are spaces in the pathnames. Workaround is to use --class-path from the command line, or paths that don't contain spaces.

Java Paths.get() strange behavior on Linux

I am currently writing some code in which I work with files a lot. I implemented all file paths processing (concatenation, normalization, etc) using the Java 7 nio classes Paths and Path. On Windows everything works as expected however on Linux the Paths class behavior seems to be broken.
For example the following code:
System.out.println(File.separator);
System.out.println(FileSystems.getDefault());
Path path = Paths.get("../dir1/", "\\dir2\\file1").toAbsolutePath().normalize();
System.out.println(path);
if(path.toFile().exists()) {
System.out.println(path + " exists");
}
on Windows prints the following output:
\
sun.nio.fs.WindowsFileSystem
D:\projects\dir1\dir2\file1
true
but the same code on Linux Ubuntu 14.04 on both Java 1.7.0_79 (64 bit) and Java 1.8.0_60 (64 bit) leaves the path un-normalized:
/
sun.nio.fs.LinuxFileSystem
/home/semi/dir1/\dir2\file1
Also even if the file is at path /home/semi/dir1/dir2/file1 exists it is reported as non-existent by path.toFile().exists().
I looked a bit over LinuxFileSystem.java and WindowsFileSystem.java and it seems that on windows the path is checked for both / and \ characters (in WindowsPathParser.isSlash(char c) method). Shouldn't the Linux implementation do the same?
Is this a bug in sun.nio.fs.LinuxFileSystem implementation or am I doing something wrong?
Also do you know any alternative to make sure Linux paths are parsed and normalized correctly (without doing all the parsing manually).
In Windows, / is not a valid character in a filename so any code can assume it's a wrongly typed path separator.
In Linux, just about any byte is acceptable in a filename. In your Paths.get(), you're effectively joining a path called dir1 (1 level deep) and a path called \dir2\file1 (also 1 level deep).
Java on Windows is compiled against Microsoft C++ standard libraries, which permit either backslash or forward slash as a valid path separator. So backslash is a valid path separator only when running on Windows, whereas forward slash is valid everywhere.
The only time backslash is required, even on Windows, is when creating command lines that will be passed to CMD.EXE, to PowerShell, and possibly other terminals/shells. There are also some open source libraries that require backslash in file paths (when running on Windows), but java itself permits either forward or back slash in file paths.
IMHO, using File.separator when parsing input often leads to avoidable errors, whereas it has a valid role when generating output to be consumed by software or human eyeballs.

Running Java batch file on Mac

I am trying to run a Java application on a Mac. Currently, there is a batch file that works for Windows that looks like this:
java -cp lib/appframework-1.0.3.jar;lib/commons-net-3.1.jar;lib/mysql-connector-java-5.1.6-bin.jar;lib/swing-worker-1.1.jar;TimeCardApplicationOdesk.jar org.ep.gui.TimeCardApplication
This works fine on Windows, but running that command on a Mac outputs a bunch of gibberish (mostly "command not found" errors").
I have tried to set the class path beforehand and load the jars with the -jar switch, but I'm stumped and know nothing about Java. I'm sure there are some slight changes that need to be made to the syntax, but I'm lost.
Replace all semicolons (;) with colons (:) in the command.
Multiple path entries to the -cp flag are separated by colons on unix systems. Following examples from these docs (solaris and windows) illustrate this.
On a windows system:
C:> java -classpath C:\java\MyClasses;C:\java\OtherClasses ...
Note that the two paths are separated by a semicolon.
And on a unix like system:
% java -classpath /java/MyClasses:/java/OtherClasses ...
Note that the two paths are separated by a colon.

Opening Files with Java while Working in Cygwin

I am running Cygwin on a Windows 7 machine, and using script files to execute Java programs in batch. My problem is this: I try to pass in a Cygwin / Linux path to a file, via the command line, and Java converts all of the forward slashes to backslashes.
For instance:
java program $scratchname/path_to_folder/ filename_$i.txt
Within Java, I take the directory and add the file name to open the file, which usually works with no issues as long as I'm using a Windows command line. However, in Cygwin Java converts this to:
home\scratch\path_to_folder
which Cygwin doesn't like.
I don't think this is a simple matter of replacing the backslashes with forward slashes, because Java seems to default to the Windows path conventions when I try to open the file. I'm guessing this is because Cygwin is pointed to the Windows installation of the JVM.
How can I force Java to use Cygwin / Linux path name conventions on a Windows system?
Java is a Windows program, and as such, only understands Windows paths; launching it from a Cygwin shell can't change that. You can use cygpath to convert paths back and forth.
Reference link: https://cygwin.com/cygwin-ug-net/using-effectively.html
Example case:
java -jar path/to/your-1.0.jar "$(cygpath -aw /home/YOUR_USER/path/to/file.txt)"
Options:
a provides the absolute path
w uses the Windows format

Using RCP or FTP to copy files from a remote unix machine onto a local windows machine

I'm trying to write a piece of code that uses a ProcessBuilder to transfer a file on a remote UNIX machine onto the local Windows machine. On a brief bit of research I've found that either RCP or FTP should be a suitable thing to use.
Having done some research on the RCP command, I found instructions for copying files from a UNIX to windows machine, but they don't seem to work. The command I was told to use was:
rcp -r unixhost.user:/example/directory C:\Directory
However using this told me that C: was not a host. I tried it with the IP address, localhost, the alias of the windows pc in the hosts file but none of these worked, it either said permission denied or it could not connect to the host. Having looked up ftp it seems that would be another viable option. I'm not sure if I can execute a command using ProcessBuilder to successfully achieve this via FTP.
Would rcp or ftp be more suitable for this task? And how would I go about using them?
EDIT : To clarify, the script/batch file will be running on the Windows machine and pulling the files from the UNIX machine to windows.
It may be possible to escape the colon in the destination part. Have you tried quoting the destination?
rcp -r unixhost.user:/example/directory "C:\Directory"
It's been a while since I've done any command-line stuff on windows, but I remember the backslash character always being problematic. You may need to use forward slashes in the destination, since the rcp command is consuming the command line. You may also be able to use the backslash as an escape character, so you might try the following:
rcp -r unixhost.user:/example/directory C\:/Directory
If that won't work, you can explicitly set the current drive letter before calling the rcp command. If you're using a batch file, try the following two lines:
c:
rcp -r unixhost.user:/example/directory \Directory

Categories

Resources