开发者

Java application does not work properly outside IDE's directory

开发者 https://www.devze.com 2022-12-19 00:23 出处:网络
When I run it with NetBeans it\'s all OK. When I copy dist directory contents and run .jar, some stuff gets buggy. Most important, JTable editing gets messy, some fields lose focus only when you hit E

When I run it with NetBeans it's all OK. When I copy dist directory contents and run .jar, some stuff gets buggy. Most important, JTable editing gets messy, some fields lose focus only when you hit ESC (if you did hit ENTER before, changes are accepted, otherwise they are not, but you need ESC in both cases) and similar weird stuff. I got a feeling that I'm missing something obvious...

P.S. files are compiled automatically on save (NetBeans feature) if that matters.

Edit: when I just go to dist dir and run .jar, it works too. Problems begin when I copy dist dir out of NetBeans projects dir... can it be that some dependencies get broken or something?

Edit 2 (reply):

This problem was happening in my computer (Ubuntu 9.04), in my Windows XP inside Virtual Box and in another (real) computer with Windows XP. When I run it from console with java /path/to/main.jar it throws mainClassNot found exception and does not launch at all. When I run it with java -jar /path/to/main.jar, it works of sorts, but when it comes to said situations, it throws java.lang.NumberFormatException: null.

The only place I use NumberFormat (on table update) is开发者_开发问答:

DecimalFormat parser = new DecimalFormat("0.00");

And, possibly, this:

currencyFormatter = NumberFormat.getCurrencyInstance( Locale.getDefault() );

Where default locale is set to

Locale.setDefault(new Locale("lt", "LT"));

Java version is 1.6.0_18, both JDK used by NetBeans and JVM in said machines.


In NetBeans go to your project's properties (File > Project Properties). Go to the Libraries tab. Click Manage Platforms and see the value for the Platform Folder.

From a console, run <platform folder>\java -version.

Now try it again without the full path; just java -version.

I would expect these are returning different values.

The path used by the IDE comes from the platform definition which, by default, is created when NB is installed and never updated. The path used in the console is from the windows PATH environment variable. This is updated whenever Java is installed and will, over time, diverge from the path used by the IDE.

A good rule of thumb is when Java prompts that an update is available it's time to add a new Java Platform in NetBeans.

I usually keep several platforms around. At a minimum: latest versions of 1.4.2, 1.5.0, 1.6.0, and an old version of 1.6.0 (currently u4, the version we recommended in our first product release).


Have you tried something as mundane as making a clean build to make sure all new changes and resources are copied to the dist library?


Interesting... JAR's are stored in ZIP format, so you could try comparing the JAR that you've compiled with Netbean's JAR (if you can find it) to see exactly what is different.


Different JRE versions? That would be my guess, looking at your symptoms.

There are different ways to do this, but you could get the complete details of both the processes (one launched by NetBeans and one without) using jconsole (jdk_dir/bin/jconsole.exe). This would give you the JRE, loaded jars, etc that you could then compare...

HTH...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号