导入 org.apache.commons Java
我一直在尝试将 apache commons 导入到我的 jar 中,但无法做到这一点。下面的代码是我正在使用的代码:
import java.applet.Applet;
import org.apache.commons.io.*;
public class Java extends Applet
{
public void init()
{
String str1 = "testing.html"
String str2 = System.getProperty("java.io.tmpdir");
try {
URL url = new URL("http://www.facebook.com");
File destination = new File(str2 + str1);
FileUtils.copyURLToFile(url, destination);
} catch (IOException e) {
e.printStackTrace();
}
}
}
我用命令提示符编译了它:
set /p c=Please choose a signature name:
keytool.exe -genkey -keyalg rsa -alias %c%
keytool.exe -export -alias %c% -file Certificate.crt
javac.exe Java.java -cp commons.jar
jar.exe cvf Java.jar *.class commons.jar
jarsigner.exe Java.jar %c%
最后我们得到了运行它的 HTML 代码:
<applet width='100px' height='200px' code='Java.class' archive="Java.jar, commons.jar">
</applet>
现在,当我运行它时,它不会下载文件并将其放在临时文件夹中。这是为什么?
I've been trying to import the apache commons inside my jar, but can't see to do it. This code below is the code I'm using:
import java.applet.Applet;
import org.apache.commons.io.*;
public class Java extends Applet
{
public void init()
{
String str1 = "testing.html"
String str2 = System.getProperty("java.io.tmpdir");
try {
URL url = new URL("http://www.facebook.com");
File destination = new File(str2 + str1);
FileUtils.copyURLToFile(url, destination);
} catch (IOException e) {
e.printStackTrace();
}
}
}
I compiled it with the command prompt:
set /p c=Please choose a signature name:
keytool.exe -genkey -keyalg rsa -alias %c%
keytool.exe -export -alias %c% -file Certificate.crt
javac.exe Java.java -cp commons.jar
jar.exe cvf Java.jar *.class commons.jar
jarsigner.exe Java.jar %c%
Finally we got my HTML code to run it:
<applet width='100px' height='200px' code='Java.class' archive="Java.jar, commons.jar">
</applet>
Now when I run it, it wont download the file and place it in the temp folder. Why is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎正在尝试将
commons.jar
放入其他 JAR 文件中;那是行不通的。您需要将其放在网络服务器上与其他 JAR 文件相同的目录中。浏览器无法下载服务器上不存在的文件,并且服务器上的任何代码都不会解压该 JAR。You appear to be trying to place the
commons.jar
inside your other JAR file; that won't work. You need to place it on the webserver in the same directory as your other JAR file. The browser can't download a file that doesn't exist on the server, and no code on the server is going to unpack that JAR.