how can import ms.security package

巧了我就是萌 提交于 2019-12-25 10:17:07

问题


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.


回答1:


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!




回答2:


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;



回答3:


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.




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/29962645/how-can-import-ms-security-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!