Open jnlp file with java

How to Open a JNLP File

Java Network Launch Protocol (JNLP) files are used to launch applications from a hosted web server on a remote desktop client. Software such as Java Plug-in and Java Web Start programs use JNLP files to run.

Because JNLP files are program-specific, your computer may not properly recognize JNLP files to execute them using the Java Web Start application. If this happens, you need to modify your computer’s file associations so that JNLP files open correctly with the Java Web Start application.

Download and Install the Latest Version of Java

Before you edit the file association on your PC to open JNLP files correctly, confirm that you have the proper Java programs installed on your computer. Here is how:

  1. On a PC, click the Windows Search field and type «Java,» or scroll through the list of alphabetized apps for the Java program. If you do not see it, Java is not installed.

On a Mac, go to Finder > Applications > Utilities Folder. You should see a Java folder. If you do not see it, you do not have Java installed.

Editing JNLP File Associations on Windows 10

To edit the file associations on a PC running Windows 10 so that JNLP files open correctly:

  1. From the Start window, navigate to the Control Panel.
  2. Go to Programs >Default Programs.
  3. Click Select Your Default Programs.
  4. Select Choose Default Applications by File Type.
  5. Choose JNLP from the list of extension types.
  6. Select the option to Change program.
  7. It is unlikely the proper Java application shows up automatically, so choose More apps.
  8. Select Look for another app on thisPC.
  9. Navigate to the Java folder, which should be located in your Program Files (x86) folder.
  10. Click through the jre[version #] and bin folders to the javaws.exe application. This is the Java Web Start application launcher. Choose it by double-clicking it.
  11. Confirm the choice by pressing the Close button and complete the process.

From now on, the Java Web Start application will open JNLP files whenever you click on them.

Editing the JNLP File Associations on a Mac

To change the file associations for opening a JNLP file properly on a Mac:

  1. Open the Finder and locate the JNLP file you plan to open.
  2. Right-click the JNLP file and select Get Info.
  3. From the JNLP file information screen, click the arrow next to Open With.
  4. Select Java Web Start from the list of applications in the drop-down menu. If it is not listed in the first group of options, select Other and locate it in the complete list of applications.
  5. After you select the right app, click Change All to apply the change to all JNLP file types in the future.
  6. Finalize the process by clicking Continue.

Now, whenever you click a JNLP file to open on your Mac, it opens automatically with the correct Java application.

  • Verify Java is associated with JNLP files using the Java Control Panel window. Open it by clicking “Start,” selecting “Control Panel,” clicking “Programs” and clicking the “Java (32-bit)” option. Click the “Advanced” tab at the top of the Java Control Panel window, click the plus sign to the left of “JNLP File/MIME Association,” select “Always Allow” or “Prompt” and click “OK.” JNLP files won’t work if you select “Never Allow.”
  • You can also use the Open With feature in Windows to associate JNLP files with Java Web Start. Right-click a JNLP file and click “Open With.” Select the “Java Web Start Launcher” application in the list or click “Browse,” browse to the “C:\Program Files (x86)\Java\jre[version]\bin” folder on your computer and double-click the “Javaws.exe” program file. Browse to the “Program FIles” directory if you don’t see the “Program Files (x86)” directory.
Читайте также:  Php run code in string

Grant Harvey is a writer with experience in the tech and crowdfunding space.

Источник

What is JNLP File and How to Open it?

Every file with a unique extension is associated with an application that runs it. Most users that are unfamiliar with Java or just starting to know about it will be unaware of some of the file extensions. Many users are wondering about what .jnlp files are and how to open them. As it is possible that the JNLP files can become associated with another application, causing it to open incorrectly. In this article, we will cover what the JNLP file is and how to open it.

What is the JNLP File?

JNLP or Java Network Launch Protocol is a file format that is used for launching Java executable over the Web or Network. This file may contain information about the remote address for downloading a Java program and the initial class to run. The JNLP files will be in XML file format and can be edited or viewed with a text editor that supports XML format. These files can easily be executed on the system that has a Java Runtime Environment (JRE) installed. This is because JRE includes Java Web Start technology that opens JNLP files. There may be different types of JNLP files depending on what they are used for. Users always will have the main JNLP file that points to all other files.

Open the JNLP File through Java Web Start

In this method, we will be using Java Web Start to open the JNLP File. Java Web Start is included in the Java Runtime Environment (JRE) package since the 5.0 release of Java. By using the JavaWS, users can launch full-featured applications with a single click. However, sometimes Windows will have a different application set as default for JNLP files. So, users need to open the files by manually selecting JavaWS from the directory of Java. Follow the below steps to try opening the JNLP file through Java Web Start:

  1. Right-click on the JNLP file and choose the Open With option in the list.
  2. Scroll down and select the Look for another app on this PC option.
  3. Go to the following location and choose javaws.exe.
C:\Program Files (x86)\Java\jre1.8.0_261\bin

  • Click on the Open button to open the JNLP file using Java Web Start.
  • Open the JNLP File in a Text Editor

    This method is mostly to check or edit the code of the JNLP file through the text editor. The JNLP will not function for what it was made but simple open in a text editor as a text file. The purpose of this method is that you can open the file, even if you don’t have Java installed on the computer. Sometimes a user would like to extract a piece of specific information or check the code of a JNLP file. Users can use notepad or some other text editors to open the JNLP file. Down below, we show you the steps of opening the JNLP file in Notepad++:

    1. Right-click on the JNLP file and choose Notepad++ in the list.
      Note: You can also choose Notepad. If you don’t see any text editor you can choose the Open with option and then search for the text editor.
    2. This will open the file in the Notepad++ and then you can check or edit the code in the JNLP file as shown below:
    Читайте также:  Сохранение фрагмента HTML-страницы в виде изображения

    Источник

    Running a Java Web Start Application

    Note: To run applications deployed with Java Web Start technology, you must have a compatible version of the Java Runtime Environment (JRE) software. The complete Java Java Development Kit (JDK) is not required.

    Running a Java Web Start Application From a Browser

    You can run a Java Web Start application from a browser by clicking a link to the application’s JNLP file. The following text is an example of a link to a JNLP file.

    Java Web Start software loads and runs the application based on instructions in the JNLP file.

    Running a Java Web Start Application From the Java Cache Viewer

    If you are using at least Java Platform, Standard Edition 6 or later, you can run a Java Web Start application through the Java Cache Viewer.

    When Java Web Start software first loads an application, information from the application’s JNLP file is stored in the local Java Cache Viewer. To launch the application again, you do not need to return to the web page where you first launched it; you can launch it from the Java Cache Viewer.

    To open the Java Cache Viewer:

    1. Open the Control Panel.
    2. Double click on the Java icon. The Java Control Panel opens.
    3. Select the General tab.
    4. Click View. The Java Cache Viewer opens.

    The application is listed on the Java Cache Viewer screen.

    A screen shot of the Java Cache Viewer application

    Java Cache Viewer application

    To run the application, select it and click the Run button, , or double click the application. The application starts just as it did from the web page.

    Running a Java Web Start Application From the Desktop

    You can add a desktop shortcut to a Java Web Start application. Select the application in the Java Cache Viewer. Right-click and select Install Shortcuts or click the Install button, .

    A shortcut is added to the desktop.

    You can then launch the Java Web Start application just as you would launch any native application.

    Источник

    Accessing the Client Using JNLP API

    When launched by using the Java Network Launch Protocol (JNLP), rich Internet applications (RIAs) can access the client with the user’s permission. Consider the Text Editor applet example to understand how to use JNLP API based services. The Text Editor has a text area and buttons labeled Open, Save, and SaveAs. The Text Editor can be used to open an existing text file, edit it, and save it back to disk.

    The Text Editor applet is shown next.

    Note: If you don’t see the applet running, you need to install at least the Java SE Development Kit (JDK) 6 update 10 release.

    Note: If you don’t see the example running, you might need to enable the JavaScript interpreter in your browser so that the Deployment Toolkit script can function properly.

    The TextEditor and TextEditorApplet classes lay out the user interface and display it as an applet. The FileHandler class contains the core functionality with respect to using JNLP API based services.

    Читайте также:  Html кнопки с градиентом

    Remember, the techniques described in this topic apply to Java Web Start applications as well.

    To make use of a JNLP service, first retrieve a reference to the service. The initialize method of the FileHandler class retrieves references to JNLP services as shown in the following code snippet:

    private static synchronized void initialize() < . try < fos = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService"); fss = (FileSaveService) ServiceManager.lookup("javax.jnlp.FileSaveService"); > catch (UnavailableServiceException e) < . >>

    After you have a reference to the required services, invoke methods on the service to perform the necessary operations. The open method of the FileHandler class invokes the openFileDialog method of the FileOpenService class to display a file chooser. The open method returns the contents of the selected file.

    public static String open() < initialize(); try < fc = fos.openFileDialog(null, null); return readFromFile(fc); > catch (IOException ioe) < ioe.printStackTrace(System.out); return null; >>

    Similarly, the save and saveAs methods of the FileHandler class invoke corresponding methods of the FileSaveService class to enable the user to select a file name and save the contents of the text area to disk.

    public static void saveAs(String txt) < initialize(); try < if (fc == null) < // If not already saved. // Save-as is like save save(txt); >else < fc = fss.saveAsFileDialog(null, null, fc); save(txt); > > catch (IOException ioe) < ioe.printStackTrace(System.out); >>

    At runtime, when the RIA attempts to open or save a file, users see a security dialog asking them if they want to allow the action. The operation will proceed only if users allow the RIA to access their environment.

    The complete source of the FileHandler class is shown next.

    // add javaws.jar to the classpath during compilation import javax.jnlp.FileOpenService; import javax.jnlp.FileSaveService; import javax.jnlp.FileContents; import javax.jnlp.ServiceManager; import javax.jnlp.UnavailableServiceException; import java.io.*; public class FileHandler < static private FileOpenService fos = null; static private FileSaveService fss = null; static private FileContents fc = null; // retrieves a reference to the JNLP services private static synchronized void initialize() < if (fss != null) < return; >try < fos = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService"); fss = (FileSaveService) ServiceManager.lookup("javax.jnlp.FileSaveService"); >catch (UnavailableServiceException e) < fos = null; fss = null; >> // displays open file dialog and reads selected file using FileOpenService public static String open() < initialize(); try < fc = fos.openFileDialog(null, null); return readFromFile(fc); >catch (IOException ioe) < ioe.printStackTrace(System.out); return null; >> // displays saveFileDialog and saves file using FileSaveService public static void save(String txt) < initialize(); try < // Show save dialog if no name is already given if (fc == null) < fc = fss.saveFileDialog(null, null, new ByteArrayInputStream(txt.getBytes()), null); // file saved, done return; >// use this only when filename is known if (fc != null) < writeToFile(txt, fc); >> catch (IOException ioe) < ioe.printStackTrace(System.out); >> // displays saveAsFileDialog and saves file using FileSaveService public static void saveAs(String txt) < initialize(); try < if (fc == null) < // If not already saved. Save-as is like save save(txt); >else < fc = fss.saveAsFileDialog(null, null, fc); save(txt); >> catch (IOException ioe) < ioe.printStackTrace(System.out); >> private static void writeToFile(String txt, FileContents fc) throws IOException < int sizeNeeded = txt.length() * 2; if (sizeNeeded >fc.getMaxLength()) < fc.setMaxLength(sizeNeeded); >BufferedWriter os = new BufferedWriter(new OutputStreamWriter(fc.getOutputStream(true))); os.write(txt); os.close(); > private static String readFromFile(FileContents fc) throws IOException < if (fc == null) < return null; >BufferedReader br = new BufferedReader(new InputStreamReader(fc.getInputStream())); StringBuffer sb = new StringBuffer((int) fc.getLength()); String line = br.readLine(); while (line != null) < sb.append(line); sb.append("\n"); line = br.readLine(); >br.close(); return sb.toString(); > >

    Note: To compile Java code that has a reference to classes in the javax.jnlp package, include /jre/lib/javaws.jar in your classpath. At runtime, the Java Runtime Environment software automatically makes these classes available to RIAs.

    Download source code for the Text Editor Applet example to experiment further.

    Источник

    Оцените статью