简体   繁体   English

作为servlet而不是java类工作。 为什么?

[英]working as servlet but not as java class. why?

I am working on SAML SSO Authentication. 我正在研究SAML SSO身份验证。 I have created a servlet to generate SAML metadata and i deployed it and run it and I got the output. 我创建了一个servlet来生成SAML元数据,并部署并运行它,然后得到了输出。 Same time I have created a java class to generate SAML Metadata with the same code and tried to run it independently. 同时,我创建了一个Java类以使用相同的代码生成SAML元数据,并尝试独立运行它。 I have added the same Jar files that I have used for that servlet application. 我添加了与该servlet应用程序相同的Jar文件。 But I got the Exception given below. 但是我在下面给出了异常。 Can anybody help me to find the difference between running an application independently and by using java servlet?? 谁能帮助我找到独立运行应用程序与使用Java servlet的区别? Thanks in advance. 提前致谢。

Exception: 例外:

单击此处查看例外

Running as servlet in a web container means all sorts of stuff is on the classpath that is automatically provided by the servlet container. 在Web容器中作为Servlet运行意味着各种东西都在servlet容器自动提供的类路径上。

Running using main() means you have to put all needed stuff on the classpath yourself. 使用main()运行意味着您必须自己将所有需要的东西放到类路径上。 The ClassNotFoundException you got should be clear enough in that respect. 在这方面,您得到的ClassNotFoundException应该足够清楚。

(Pls note that although I did say "the" classpath, in a servlet container things are typically not quite that simple. But that's not the point. Also note that running as a servlet, and using features of libraries provided for the container, may even mean your stuff cannot run as an independent java program simply because the library stuff was deliberately intended for servlet container use exclusively.) (请注意,尽管我确实说了“ the”类路径,但是在servlet容器中,事情通常并不那么简单。但这并不是重点。还请注意,以servlet的身份运行,并使用为容器提供的库功能,可能会甚至意味着您的东西不能仅仅作为库的东西专门用于servlet容器而仅仅作为独立的Java程序运行。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 '。类。' java中的错误 - '.class.' error in java PowerShell 命令未使用 java 进程 class 执行。而所有其他命令工作正常 - PowerShell command not getting executed using java Process class. While all other commands are working fine getSupportFragmentManager()在片段类的onCreateView()方法上不起作用。 - getSupportFragmentManager() is not working on onCreateView() method of the fragment class. 在类中声明时无法访问变量。 在函数中声明时起作用。 为什么? - Unable to access variable when declared in class. Working when declared in a function. Why? Java实现克隆,泛型类。 - Java implementing clone, generic class. 为什么从另一个Java Servlet或Java类调用Java Servlet类中的方法会返回null? - Why method in Java servlet class return null when called from another java servlet or java class? java访问修饰符-类型为其他类的属性的可见性。 为什么它可见或不可见? - java access modifier- visibility of attributes whose type is other class. why it is visible or not? Java等于Class。 ==与.equals相同 - Java equals for a Class. Is == same as .equals 获取类的数组列表的索引。 爪哇 - Getting indexof arraylist of class. java Java:项目中的两个 jar 具有相同的类。 - Java: Two jars in project with same class.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM