Java Unicode Issue on Windows - java

When I run my application within Netbeans everything works fine - I can read/write unicode texts and filenames, but when I run the jar by double click or with java -jar test.jar I only get strange symbols...
Is this a known issue? I use jdk 1.7 but build 1.6 byte code with it...
Thanks in advance for any help :D
EDIT: I'm not talking about stdout - the app reads and writes files and has a GUI

If I run the application from terminal System.getProperty("file.encoding") outputs cp152,
but if I run it from Netbeans it results UTF-8.
this: java -Dfile.encoding=UTF-8 -jar XY.jar
solves my problem, but I don't like the solution...

Related

Why am I getting 'appletviewer not found' error?

I have written a program appletExample.java.
c:/users/set path = "C:\Program Files\Java\jdk-16\bin"
c:/users/desktop/jp>appletviewer appletexample.java
The error is"
'applet viewer' is not recognized as an internal or external command,
operable program or batch file.
I am getting this error. But set path is also correct way but why this error has occurred? Could anyone explain to me?
I think jdk 16 has eliminated applets so one who would like to run applets download jdk 8 version.
As jdk 15 also doesn't have applets if you want to check your version support appletviewer or not do this thing:
Go to windows> program files >java > jdk 1.5.05 > bin
So in that folder if you find appletviewer.exe then your version supports applets.
If you don't find that thing then you must go and download jdk 8 version or others which support applets.
As other people have said, applets are history really but try the following:
(cd to wherever appletexample.java is)
set PATH="C:\Program Files\Java\jdk-16\bin";%PATH%
appletviewer appletexample.java
Bear in mind that to run a java file as an argument to appletviewer, it needs to have a special format with commented-out applet tags in the Java source

Jar file runs successfully from command line, but freezes when double clicked in windows

I'm having issues running a jar file I compiled from an eclipse project. I'm fairly new to Java so I'm likely missing something simple.
When I run the jar file from the command line:
javaw -jar test1.jar
the program runs fine. But when I double click the jar it doesn't run. I believe the issue has to do with 32 bit versus 64 bit java (double clicking the jar file opens the "javaw.exe *32" process whereas running from the command line opens "javaw.exe"). I'm using the swing GUI libraries, if that makes a difference.
Is that the issue?
Is there a way to make eclipse export a .jar file that will be compatible with "javaw.exe *32"?
Thanks.
EDIT:
I figured out the error was related to using generics with JList, which is only supported in Java 7. Double clicking the .jar was running a 32-bit version of Java 6, which is what was throwing the error. Thanks for the help guys

Java JTextField special chars

I have a problem with the chars of all JTextField on my program (when compiled into JAR).
When I run it from Eclipse everything works fine... the problem is when run from the already compiled JAR.
The problem is, when I insert text to JTextField with special character as "Ñandú?" when java extract text from the input that goes with rare characters.
For example: System.out.println( myTextField.getText() );. That would write in the console: IMAGE
I have tried all kinds of way to switch chars, but when I write again on the console or in the interface reappear rare signs. I've even tried the library Commons Lang 3.1, but I have not been successful :(
I hope someone knows what to do! The only way to work is inserting -Dfile.encoding=UTF-8 on running the jar file, but that can not be so.
Sorry for the English. Thanks!!!
Java uses the default encoding for your computer, which for Windows would be C16 and doesn't support unicode. Run your program with the following command in terminal:
java -jar -Dfile.encoding=utf-8 <path to your .jar>
Eclipse would run your applications like so if you have any unicode in your document, but outside of it, you're on your own.
The only other possible way I can think of is writing a .bat script with this command and putting it in the same folder as the application.

Writing Japanese chars into XML gives Junk value in java standalone program, but from eclipse gets proper output

My problem is I have written a code in java to read some japanese chars and write into XML file. The program works fine when i am using eclipse with JRE 1.5 and 1.6 but when i created a *.jar file and run the same program standalone, the output i am getting some junk chracters. Can anybody please help me out? Thanks in advance!!!
I think you need to run it with -Dfile.encoding=UTF8

Getting error "bash: appletviewer: command not found".

I'm trying to learn Java and I'm having problems with the appletviewer command. I am using openSUSE 11 and am able to compile and run normal java programs but when I issue the appletviewer command I'm getting the following error "bash: appletviewer: command not found".
I have set the PATH variable in the .bashrc file. so the problem is not that of the path. This can also be verified from the fact that javac and java commands are working normally. I have googled and tried many said resolution but none is working. I have even tried moving the files to the bin folder and running the command from there.
So what may the cause of this? Isn't appletviewer designed to work in linux? And FYI I have replaced the OpenSDK and IcedTea versions with the jdk1.6.0_14 version from the sun site. Please help.
Thanks
Chris
As a test, do the following:
$which java
$which appletviewer
Check to see if the paths are different. If the second command gives no output, appletviewer may not even be installed (or can't be located by your system).
You need to install java-1_6_0-sun-devel-1.6.0.u14-0.2.1
$ sudo zypper install java-1_6_0-sun-devel
You will find it in the openSUSE-11.1-Non-Oss repository.

Categories

Resources