8

I have created a text editor using Java, and have it packed in a jar file using Netbeans. Now I created a text file, with an extension of ".text". I'm on Windows 7, so using it's property window I changed the default opening program to my text editor's jar file.

Now when I double click the file with ".text" extension, windows shows a dialogbox saying "{file name} is not a valid win32 application".

Please help me out of it..

Thanks.

3
  • If i make it .txt, it opens with notepad, and I don't want to mess with the default settings of the .txt extension. So I changed my text editor's extension to .text Mar 9, 2012 at 10:57
  • the above question was just an experiment, I was trying to associate the .text file with my text editor, but it did't work, then I posted a question about how to associate file extensions so that it opens the respective file in my text editor using it's jar file on Stackoverflow, (didn't get satisfactory ans) then deleted the question. Mar 9, 2012 at 11:01
  • 1
    What i basically need is a file with .text extension should open with my text editor...so that I can include it in the setup process of the text editor. Mar 9, 2012 at 11:02

2 Answers 2

11

The problem is that a JAR file is selected as the "default application". However, JAR files are normally not executable. That is, a JAR file is not a valid Windows application. It doesn't matter if the JAR extension itself has a default application associated with it, because the "Open verb" is not used recursively in other "Open verb" definitions.

Instead,

  1. Create a batch (".BAT") file (or small EXE wrapper) that calls java (or javaw, as appropriate) and use that executable wrapper as the "Open with" program. (This will have an annoying intermediate console window if using a batch file.) Or,
  2. Modify the registry so that the "Open verb" for the extension launches the JAR through java (or javaw).

In the end, either form should look similar to: javaw -jar TheJarFile.jar "%1%". (Note that javaw is an executable, while TheJarFile.jar is not an executable.)

See java - the Java application launcher for how to use java/javaw.

2
  • Thanks man !! I got it working, created an exe out of the jar :) Mar 9, 2012 at 12:25
  • 1
    @Jaydeep Cool :-) Which tool did you use to do that?
    – user166390
    Mar 9, 2012 at 12:26
-3

May be because .text is not an executable file.

try using this..

Runtime.getRuntime().exec("cmd.exe /C file");

This will open your file with the default program.

Update: I got confused first, may be I didn't read your question properly. I thought your executing .text file directly from a Java code..

Runtime.getRuntime().exec("file.text"); //Gives error CreateProcess error=193, %1 is not a valid Win32 application

So I suggested opening it with cmd(as in answer).

But reading your scenario, it seems windows is unable to execute your jar itself.

To make your jar executable, try this..

java -jar yourjarfile.jar....

2
  • Actually, I'm a newbie, so can you please tell me where to write the above syntax.. Mar 9, 2012 at 11:24
  • Hmm...i think what pst said make sense....Try this first...java -jar yourjar.jar........this will make your jar executable...and then try.. Mar 9, 2012 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.