"java.lang.SecurityException:禁止的软件包名称:java.sql"错误仅在Eclipse外部执行时发生 [英] "java.lang.SecurityException: Prohibited package name: java.sql" error happen only when executing outside of Eclipse

查看:82
本文介绍了"java.lang.SecurityException:禁止的软件包名称:java.sql"错误仅在Eclipse外部执行时发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Tika编写主题建模程序,以从其他文件类型提取文本内容.实际上,它可以在Eclipse上完美运行.但是,当我从窗口10的命令提示符中导出到JAR文件以使用时,在尝试代码时出现此错误消息:"parser.parse(stream,handler,metase,parseContext);"

I am writing a Topic Modeling program using Apache Tika to extract the text contents from other file type. Actually It run perfectly on Eclipse. But when I export to JAR file to use from command prompt of the Window 10. This error message appear when it try the code: "parser.parse(stream, handler, metadata, parseContext);"

"java.lang.SecurityException:禁止的包名称:java.sql"

"java.lang.SecurityException: Prohibited package name: java.sql"

我没有在这里上传我的Java代码,因为我认为它们不是问题的根源.由于它可以在Eclipse IDE中完美运行.因此,有谁知道为什么只有在我尝试从命令行运行它时才会发生这种情况. Eclipse IDE内部和外部之间的JVM有何不同?谢谢.

I didn't upload my java code here because I don't think they are the root of the problem. Since it run perfectly inside Eclipse IDE. So do anyone know why it only happen when I try to run it from command line. What are the different in JVM between inside and outside of Eclipse IDE? Thank you.

        package Views;

import java.io.*;
import org.apache.commons.io.FileUtils;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.sax.BodyContentHandler;

public class TestTika {

    public static void main(String[] args) throws IOException {
        String inputFolderName = "data";
        String outputFolderName = "data_text";
        System.out.println("Extracting text data from '" + inputFolderName + "' to '" + outputFolderName + "'");

        FileUtils.deleteDirectory(new File(outputFolderName)); // Delete the old file in this directory
        System.out.println("Delete all of the old files in directory'" + outputFolderName + "' successfully \n");

        if (new File(outputFolderName).mkdir()) {
            System.out.println("Created folder '"+ outputFolderName );
        }

        File inputFolder = new File(inputFolderName);
        File[] listOfFiles = inputFolder.listFiles();

        String fileName;

        for (File file : listOfFiles) {
            if (file.isFile()) {
                fileName = file.getName();
                System.out.println("\n" + fileName);
                BodyContentHandler handler = new BodyContentHandler();
                AutoDetectParser parser = new AutoDetectParser();
                Metadata metadata = new Metadata();
                ParseContext parseContext = new ParseContext();
                FileInputStream stream = new FileInputStream(new File(inputFolderName + "/" + fileName));
                try {

//////////////////////////////////// Error: Prohibited package name: java.sql ////////////////////////////////
//////////////////////////////////// /////////////////////////////////////////////////////////////////////////

                    parser.parse(stream, handler, metadata, parseContext);

                } catch (Exception e) {
                    System.out.println("Warning: Error when processing file:" + fileName
                            + " . This file will be igrored! \n" + e.getMessage() + "\n" + e.toString());
                    e.printStackTrace();
                    continue;
                } finally {
                    stream.close();
                }
                String s = handler.toString();
                Writer writer = null;
                try {
                    writer = new BufferedWriter(new OutputStreamWriter(
                            new FileOutputStream(outputFolderName + "/" + fileName + ".txt"), "utf-8"));
                    writer.write(s);
                } catch (IOException ex) {
                    // report
                    System.out.println("Warning: Error when saving file:" + fileName
                            + ".txt  . This file had been ignore! \n" + ex.getMessage());
                    continue;
                } finally {
                    try {
                        writer.close();
                    } catch (Exception ex) {
                        /* ignore */}
                }
            }

        }
        System.out.println("Extracting text data from document files has been completed!");
        return;

    }

}

java.lang.SecurityException: Prohibited package name: java.sql
        at java.base/java.lang.ClassLoader.preDefineClass(Unknown Source)
        at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
        at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.base/java.net.URLClassLoader.defineClass(Unknown Source)
        at java.base/java.net.URLClassLoader.access$100(Unknown Source)
        at java.base/java.net.URLClassLoader$1.run(Unknown Source)
        at java.base/java.net.URLClassLoader$1.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.net.URLClassLoader.findClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:113)
        at Views.TestTika.main(TestTika.java:43)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

推荐答案

当您使用以'java'开头的包类时,将抛出'prohibited package name'.在您的rt.jar中找不到.您要么自己创建了一个此类,要么在类路径中有一个包含此类的.jar文件.

The 'prohibited package name' is thrown, when you are using a class of a package starting with 'java.' that is not found in your rt.jar. Either you created such a class yourself, or you have a .jar file containing such a class in your classpath.

如果是前者,则将该类放在另一个包中.如果是后者,请尝试查找包含此类的.jar文件(例如,打印出系统属性java.class.path中找到的类路径)

If it's the former, put the class in another package. If it's the latter, try to find the .jar file containing this class (e.g. print out the classpath found in the system property java.class.path)

这篇关于"java.lang.SecurityException:禁止的软件包名称:java.sql"错误仅在Eclipse外部执行时发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆