0

I am beginner in java.

I want run native application from applet.

I found Run App In Every Browser

Java Code

import com.ms.security.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.applet.*;
 import java.io.*  ;
 import java.util.*;
 import netscape.security.PrivilegeManager;

public class RunApp extends Applet implements ActionListener {
    TextArea ta = new TextArea (25, 80);
    Button startbutton = new Button("Start Application") ;
    private static String execommand = "C:\\windows\\notepad.exe" ;
    private String osname;

  public void init() {

    try { 
      if (Class.forName("com.ms.security.PolicyEngine") != null) {  // required for IE
         PolicyEngine.assertPermission(PermissionID.SYSTEM);
       }
    } 
   catch (Throwable cnfe) {
   } 
     this.setBackground(Color.white) ;
      startbutton.addActionListener(this) ;
      add(startbutton) ;  
      startbutton.setBackground(Color.red) ;

   try{
    PrivilegeManager.enablePrivilege("UniversalExecAccess") ;  // required for NN 
     }
    catch(Exception cnfe) { 
      System.out.println("netscape.security.PrivilegeManager class not found") ;
     }
   
   osname = System.getProperty("os.name");  // if NT, Win2000 or WinXP, adjust path
   if(osname.equals("Windows NT") || osname.equals("Windows 2000")|| osname.equals("Windows XP"))
     execommand = "C:\\winnt\\notepad.exe"  ;

  }


  public void actionPerformed(ActionEvent e) {
     if( (e.getActionCommand()).equals("Start Application")) {
   try{
    PrivilegeManager.enablePrivilege("UniversalExecAccess") ;  // required for NN 
     }
    catch(Exception cnfe) { 
      System.out.println("netscape.security.PrivilegeManager class not found") ;
     }
    try {
       Process proc =  Runtime.getRuntime().exec(execommand) ;
      }
    catch(IOException ieo) {
      System.out.println("Problem starting " + execommand) ;
      }

      // System.out.println("execommand: " + execommand) ;
    }
  }

 }

But when run it say error:package com.ms.security does not exit!

I does not any folder with ms or security name .

I should create folder with ms and then security in root file or should import library ms.security .

where is com.ms.security or netscape.security.PrivilegeManager?

how can download it?i search for download this package but i does not found anythings

I use eclipse for write code.

Community
  • 1
  • 1
mhkyazd
  • 285
  • 5
  • 17
  • 1
    Just a suggestion, use some IDE like Eclipse, it will show you the exact problem and probable solution. Your life would be much easier. – Kartic Apr 30 '15 at 08:28
  • This post: http://www.tutorialspoint.com/java/java_packages.htm explains how to use packages. – User404 Apr 30 '15 at 08:29
  • i install eclipse but still eclipse say error `The import com.ms cannot be resolved` – mhkyazd Apr 30 '15 at 09:23
  • You realise this code is for running in jview (*really* old IE) and *really* old Netscape Navigator? These browsers have not included their own Java implementation for quite some time. – Tom Hawtin - tackline Apr 30 '15 at 10:27
  • If you are **Beginner in java** - Why you breaking your and others head with this junk code....any good reasons. – Rajesh May 12 '15 at 16:02

5 Answers5

2

This package does not exist any more. The tutorial you point to dates from 2002. You can look at this javaranch post: http://www.coderanch.com/t/375470/java/java/Location-Jar-ms-security, and at the Microsoft documentation (https://msdn.microsoft.com/en-us/library/aa242534(v=vs.60).aspx). So basically your code would have worked 13 years ago, but with Microsoft not supporting their own JVM any more it's obsolete. Sorry!

JP Moresmau
  • 7,388
  • 17
  • 31
  • why `http://jensign.com/JavaScience/www/AppAnyBrowser/index.html` still worked for me?how this use ms-security? – mhkyazd May 12 '15 at 03:14
  • What do you mean "still worked for me". The question you asked is about it not compiling. How can it work if it doesn't compile? – JP Moresmau May 12 '15 at 06:55
  • i mean is this(http://jensign.com/JavaScience/www/AppAnyBrowser/index.html) run application native with ms.security,how ? i want do it – mhkyazd May 12 '15 at 10:42
  • Ah yes, I didn't even notice there was an applet there, since it doesn't load in my browsers. As the page says, it's been built with Microsoft Java compiler, which is not supported anymore. If it works on your browser, then your browser has the proper classes. Search for jar or cab files on your machine that would contain these classes. – JP Moresmau May 12 '15 at 11:16
  • But of course "works" does not mean that you have the classes, since the code recovers via a catch block if the microsoft classes are not known. So my advice would be: forget about this page and code sample. Read up on up to date information on applet security. But given how applets are restricted with each new version of the plugin and browsers (see latest versions of Chrome that have applets disabled by default), I would review my whole architecture and question my use of applets, if I were you. – JP Moresmau May 12 '15 at 11:26
1

You need to download that jar having this package ,com.ms.security. And b4 compiling your java class set that jar in your classpath from command prompt.

set classpath=%classpath%;path_of_your_jar;
Archana Mundaye
  • 523
  • 1
  • 5
  • 19
0

This package is not existed anymore. Microsoft is not supporting their own JVM anymore. You should try to learn java applet in the new way, such as http://www.tutorialspoint.com/java/java_applet_basics.htm.

codeaholicguy
  • 1,671
  • 1
  • 11
  • 18
-1

The import statement import com.ms.security.*; requires you to have a folder com, with a subfolder ms, with a subfolder security, which contains the needed files. I think you are missing some files for your application.

I recommend reading this post, for the use of imports: https://stackoverflow.com/a/12620773/3234981

Community
  • 1
  • 1
Tanix
  • 106
  • 1
  • 8
-1

Please check your jar file which contain the respective package are present in the classpath or not. If not, push them to classpath and re-compile the same class on a new command line.

Happy Learning.

sitakant
  • 1,766
  • 2
  • 18
  • 38