简体   繁体   English

如何导入commons-io.jar jsp / java

[英]How to import commons-io.jar jsp/java

I am getting an exception: 我有一个例外:

Cannot find symbol: FileUploadException; 

I have a piece of code which uses 我有一段代码使用

FileUploadException

The library that needs importing is: 需要导入的库是:

org.apache.commons.fileupload.FileUploadException

The path to my project is : 我的项目的路径是:

D:\Projects\website

In the project folder I have each in its folder: 在项目文件夹中,每个文件夹都有:

Tomcat, Derby, Website

I have copied: 我已复制:

commons-fileupload.jar and commons-io.jar

into both: 两者都:

Tomcat/lib and Website/Web-INF/lib

---------------I tried this-------------- ---------------我尝试过这个--------------

just importing the library on its own 只是自己导入库

import org.apache.commons.fileupload.FileUploadException;

adding the jars to the class path upon build: 在构建时将jar添加到类路径:

javac -cp .;D:Projects\website\Tomcat\lib\commons-fileupload.jar;D:\Projects\website\Tomcat\lib\commons-io.jar com/otrocol/app/*.java

adding them to the Environment variables CLASSPATH 将它们添加到环境变量CLASSPATH中

D:Projects\website\Tomcat\lib\commons-fileupload.jar;D:\Projects\website\Tomcat\lib\commons-io.jar

I also tried adding the jars where my .java files are as @Scot Ship suggested 我还尝试过将罐子添加到我的.java文件所在的罐子中,如@Scot Ship建议的那样

----mentions--- ----提到---

I am not using any IDE 我没有使用任何IDE

The code contains more unrecognized symbols, but I'm trying to solve one at a time 该代码包含更多无法识别的符号,但我想一次解决一个

First time using apache, tomcat, jsp.. please be gentle 第一次使用apache,tomcat,jsp ..请轻柔

Vlad, the web container will automatically look for JARs inside Vlad,Web容器将自动在其中查找JAR

/WEB-INF/lib

even without any developer intervention. 即使没有任何开发人员干预。 Take note that it's all caps WEB-INF. 请注意,所有这些都是大写的WEB-INF。 As long as your JAR is there, it will be in your web application's classpath. 只要您的JAR在那里,它将在您的Web应用程序的类路径中。

Try to display this in one of your servlets or JSP: 尝试在您的servlet或JSP之一中显示它:

System.getProperty("java.class.path")

and you'll get a better view of what classes and JARs were actually loaded. 这样您就可以更好地了解实际加载了哪些类和JAR。

Update: After reviewing your question, it appears you're facing issues in compiling the files to begin with and you're doing it outside an IDE. 更新:查看问题后,似乎您在编译文件时遇到了问题,并且正在IDE 之外进行。

Take note that when you use -cp in javac like this: 请注意,当您在javac中使用-cp时,如下所示:

javac -cp .;D:Projects\website\Tomcat\lib\commons-fileupload.jar;D:\Projects\website\Tomcat\lib\commons-io.jar com/otrocol/app/*.java

Whatever value you have set in the CLASSPATH environment variable becomes ignored. 您在CLASSPATH环境变量中设置的任何值都将被忽略。

Be absolutely sure that the class FileUploadException is indeed inside one of the JARs you're trying to import: you can view the JAR directly using an unarchiving tool. 绝对确保类FileUploadException确实在您要导入的JAR之一内:您可以使用取消存档工具直接查看JAR。

Also, change the com/otrocol/app/*.java to com\\otrocol\\app*.java - you should be using your system delimiter (not that this may affect your problem). 另外,将com / otrocol / app / *。java更改为com \\ otrocol \\ app * .java-您应该使用系统定界符(不是,这可能会影响您的问题)。

Create a simple HelloWorld in the same location as the file you're compiling, add the SystemOut mentioned above, and compile it the same way you're doing for the concerned file. 在与要编译的文件相同的位置创建一个简单的HelloWorld,添加上面提到的SystemOut,然后以与对相关文件相同的方式进行编译。

Read this http://commons.apache.org/proper/commons-fileupload/faq.html#class-not-found . 阅读此http://commons.apache.org/proper/commons-fileupload/faq.html#class-not-found Probably you have the fileupload jar but you also need commons-io.jar in your classpath as well. 可能您有fileupload jar,但在类路径中也需要commons-io.jar。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM