我所下载任何东西都无法安装,因为jar 找不到或无法加载jar这个程序…

I started to ask this question and then figured out the answer before submitting it. I've decided to post the question anyway so that other people who run into the same problem will be able to learn from my mistakes.
I'm having a problem with an applet (a
actually) unable to instantiate another class which is included in the same jar as the applet. The exception I'm seeing on the Java console is:
Exception in thread "thread pany.program.cm.hmi.MediatorApplet-1" java.lang.NoClassDefFoundError: com/company/program/cm/cs/JDataStore
pany.program.cm.hmi.MediatorApplet.getMediator(MediatorApplet.java:63)
pany.program.cm.hmi.MediatorApplet.init(MediatorApplet.java:49)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: pany.program.cm.cs.JDataStore
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 4 more
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/TransportHMI/pages/com/company/program/cm/cs/JDataStore.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 8 more
I know that the JDataStore class is included in the jar. If I list the contents using jar tvf CM_Library.jar I can see that it is there under the proper package. However, the chained exceptions above lead me to believe that the class loader isn't searching the archive for JDataStore, and is looking for the JDataStore.class file on the web server instead. Why is this? The class loader knows to load the MediatorApplet class from the jar, why doesn't it check it for JDataStore as well? In case I haven't specified the parameters correctly on the applet tag, I'll include that here as well:
&applet id="mediator-applet"
height="0"
codebase="./"
archive="CM_Library.jar"
code="pany.program.cm.hmi.MediatorApplet"&
解决方案 Found the answer from looking at
posted for a . Eddie's answer didn't solve that particular problem, but it did give me the solution for mine.
What isn't particularly obvious from my question is that the JDataStore class inherits from another class which is contained in a different jar. I hadn't had to deal with the implementation details of JDataStore in a couple of months, so I completely forgot that its parent class, org.json.simple.JSONObject, wasn't in CM_Library.jar, but was in json_simple-1.0.2.jar. The fix is fairly simple, just copy the missing jar to the codebase directory and add the missing jar to the comma-separated list of archives in the applet tag's archive attribute:
&applet id="mediator-applet"
height="0"
codebase="./"
archive="CM_Library.jar, json_simple-1.0.2.jar"
code="pany.program.cm.hmi.MediatorApplet"&
That fixes the error. The exception message is not particularly helpful. It would lead you to believe that it can't find the class at all, when the actual problem is that it cannot load the super class for the requested class.
本文地址: &
的我开始问这个问题,然后提交前想出***。我决定无论如何要发布问题,这样谁遇到同样的问题,其他人就可以从我的错误中学习。的
我在与一个小程序有问题(一的实际上)无法实例包括在同一个瓶子的小程序的类。我看到在Java控制台的例外是:异常螺纹“线程applet的pany.program.cm.hmi.MediatorApplet-1”java.lang.NoClassDefFoundError的:COM /公司/程序/厘米/ CS / JDataStore的
在pany.program.cm.hmi.MediatorApplet.getMediator(MediatorApplet.java:63)
在pany.program.cm.hmi.MediatorApplet.init(MediatorApplet.java:49)
在sun.plugin2.applet.Plugin2Manager $ AppletExecutionRunnable.run(来源不明)
在java.lang.Thread.run(来源不明)抛出java.lang.ClassNotFoundException:引起pany.program.cm.cs.JDataStore
在sun.plugin2.applet.Applet2ClassLoader.findClass(来源不明)
在java.lang.ClassLoader.loadClass(来源不明)
在java.lang.ClassLoader.loadClass(来源不明)
在java.lang.ClassLoader.loadClassInternal(来源不明)
... 4个java.io.IOException异常:引起开放的HTTP连接失败:HTTP://本地主机:8080 / TransportHMI /页/ COM /公司/程序/厘米/ CS / JDataStore.class
在sun.plugin2.applet.Applet2ClassLoader.getBytes(来源不明)
在sun.plugin2.applet.Applet2ClassLoader.access $ 000(来源不明)
在sun.plugin2.applet.Applet2ClassLoader $ 1.run(来源不明)
在java.security.AccessController.doPrivileged(本机方法)
... 8个我知道 JDataStore的类包含在瓶子里。如果我列出使用罐子TVF CM_Library.jar内容我可以看到,它是有正确的包下。然而,上述铅我链式例外相信类加载器未搜索 JDataStore的档案,并寻找Web服务器上的JDataStore.class文件,而不是。为什么是这样?类加载器就会知道从罐子里载入MediatorApplet类,为什么没有检查它的JDataStore的呢?如果我没有指定正确的applet标记的参数,我会包括在这里也: <小程序ID =“调解员的小程序”
宽度=“0”
高度=“0”
codeBase的=“./”
归档=“CM_Library.jar”
code =“pany.program.cm.hmi.MediatorApplet”>< /小程序> 解决方案 找到了***,从看的发布的related问题。埃迪的***并没有解决这个特定的问题,但它确实给我我的解决方案。什么是不是从我的问题特别明显的是,JDataStore的类从它包含在一个不同的罐子另一个类继承。我还没有处理JDataStore的在几个月的实施细则,所以我完全忘记了它的父类,org.json.simple.JSONObject,是不是在CM_Library.jar,但在json_simple-1.0 .2.jar。该修复程序相当简单,只是缺少罐子复制到codeBase的目录和丢失的jar添加到在applet标记的归档属性档案的逗号分隔列表 <小程序ID =“调解员的小程序”
宽度=“0”
高度=“0”
codeBase的=“./”
归档=“CM_Library.jar,json_simple-1.0.2.jar”
code =“pany.program.cm.hmi.MediatorApplet”>< /小程序> 这是修正错误。异常消息是不是特别有帮助。这将导致您认为它无法找到类可言,当实际问题是,它无法加载超类的请求的类。
本文地址: &
扫一扫关注官方微信android 知识点(143)
使用第三方jar包
除了我以下介绍的方法,别的方法我基本上都试验过,均会出现编译或运行错误。以下方法经测试编译和运行都完全没问题。
方法1:Eclipse下,
右键工程,
Build path,
java build path,选择libraries
在右边的按钮中点击“Add Library”
选择“User library”,点击“下一步”
点击“User librarys”按钮
在出现的界面中点击“New..”按钮
在弹出的界面中随便起一个名字,点击“确定”
点击“Add jars”按钮选择第三方jar包,点击“确定”完成。
后面的步骤很重要,如果不进行后面的操作。在Eclipse里显示编译通过,不会有错误,但在模拟器或真机上运行的时候可能就会出现java.lang.noclassdeffounderror之类的错误:
1、在Android项目根目录下新建一个libs文件夹;
2、把你需要的导入的第三方Jar包复制进这个目录;
3、在libs目录上点右键,选Bulid path&&-& Use as source folder。
方法2,android源码环境下,
1,将out/target/common/obj/J***A_LIBRARIES/powersave_intermediates下的classess.jar文件放在自己的工程目录下。out/target/product/ventana/system/framework目录下的jar包用以下方法经验证是不好使的,因为他已经打成dex文件了,在工程里引用其包是不行的;
2,修改android.mk文件,如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_J***A_LIBRARIES := libpowerjar libpowersave
LOCAL_PACKAGE_NAME := testPowerjar
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)
##############################################
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_J***A_LIBRARIES := libpowerjar:classes.jar libpowersave:testlily.jar
include $(BUILD_MULTI_PREBUILT)
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
解释:LOCAL_STATIC_J***A_LIBRARIES :=&libpowerjar和LOCAL_PREBUILT_STATIC_J***A_LIBRARIES :=&libpowerjar:classes.jar其实libarity是个名字可以随便取,两个属性的值要一样就好了,但是后面那个冒号里面就一定要写你的jar包名,你的jar包一定放在工程的根目录就好了。我这里是使用两个jar包的例子。
3,源码目录下编译即可:# mmm package/app/testPowerjar,如果出错提示说找不到jar包所打的package,那么请#touch&classes.jar&即可.
生成jar包:
方法1:Eclipse下,
1. 创建java 或android project;
2. 工程属性java build path-&Libraries中加入android.jar
3. package explorer中右键点击工程,export java-&jar file.
方法2:Android源码环境下
1,修改Android.mk文件,
LOCAL_PATH:= $(call my-dir)
# the library
# ============================================================
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := powersave.java&&&&&&&&&&&&
LOCAL_MODULE := powersave
include $(BUILD_J***A_LIBRARY)
# additionally, build unit tests in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))
2,编译 # mmm powersave(自己的模块)
其中,BUILD_J***A_LIBRARY代表生成jar包,包的位置放在out/target/product/ventana/system/framework和out/target/common/obj/J***A_LIBRARIES/powersave_intermediates(自己的模块)下,
参考:/thread-.html
以上内容转自:http://blog.csdn.net/leehong2005/article/details/9407111
1)Android java.lang.NoClassDefFoundError的原因 是由于工程配置出错导致,只要在android project底下添加一个名字叫libs的文件,eclipse环境就会自动把他导入到 Android Private Libraries文件底下,如果没有就要参考上面的做法进行配置。
2)Android eclipse 添加第三方lib库工程的时候,需要注意一点,主工程的android:targetSdkVersion=&19&一定要大于或者等于lib库工程的android:targetSdkVersion,否则就会出现引用失败的问题。
3)android eclipse 添加成功的lib库工程成功之后,都会被添加到 Android Dependencies文件底下。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:122544次
积分:2761
积分:2761
排名:第9659名
原创:131篇
转载:187篇
(6)(2)(3)(3)(2)(4)(8)(3)(5)(1)(14)(5)(2)(1)(9)(1)(12)(10)(22)(8)(6)(23)(11)(3)(7)(12)(21)(49)(43)(8)(2)(5)(1)(4)(3)Java打包jar找不到资源文件
&我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等)。在单独运行的时候这些简单的处理当然不会有问题。但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不出来了。看看下面的代码:
Java代码 &
//源代码1:
package&edu.
import&java.io.*;
public&class&Resource&{
&&&&public&&void&getResource()&throws&IOException{
&&&&&&&&File&file=new&File("bin/resource/res.txt");
&&&&&&&&BufferedReader&br=new&BufferedReader(new&FileReader(file));
&&&&&&&&String&s="";
&&&&&&&&while((s=br.readLine())!=null)
&&&&&&&&&&&&System.out.println(s);
//源代码1:
package edu.
import java.io.*;
public class Resource {
void getResource() throws IOException{
File file=new File("bin/resource/res.txt");
BufferedReader br=new BufferedReader(new FileReader(file));
String s="";
while((s=br.readLine())!=null)
System.out.println(s);
这段代码写在Eclipse建立的java
Project中,其目录为:(其中将资源文件res.txt放在了bin目录下,以便打成jar包)
&& 1、src/
src/edu/hxraid/Resource.java
&& 2、bin/
bin/resource/res.txt
bin/edu/hxraid/Resource.class
很显然运行源代码1是能够找到资源文件res.txt。但当我们把整个工程打成jar包以后(ResourceJar.jar),这个jar包内的目录为:
& edu/hxraid/Resource.class
& resource/res.txt
而这时jar包中Resource.class字节码:ldc &String
"bin/resource/res.txt"& [20]
将无法定位到jar包中的res.txt位置上。就算把bin/目录去掉:ldc &String
"resource/res.txt"& [20]
仍然无法定位到jar包中res.txt上。
这主要是因为jar包是一个单独的文件而非文件夹,绝对不可能通过"file:/e:/.../ResourceJar.jar/resource
/res.txt"这种形式的文件URL来定位res.txt。所以即使是相对路径,也无法定位到jar文件内的txt文件(读者也许对这段原因解释有些费解,在下面我们会用一段代码运行的结果来进一步阐述)。
那么把资源打入jar包,无论ResourceJar.jar在系统的什么路径下,jar包中的字节码程序都可以找到该包中的资源。这会是幻想吗?
当然不是,我们可以用类装载器(ClassLoader)来做到这一点:
& (1) ClassLoader
是类加载器的抽象类。它可以在运行时动态的获取加载类的运行信息。
可以这样说,当我们调用ResourceJar.jar中的Resource类时,JVM加载进Resource类,并记录下Resource运行时信息(包括Resource所在jar包的路径信息)。而ClassLoader类中的方法可以帮助我们动态的获取这些信息:
● public URL getResource(String name)
&&&&&&&&&&&
查找具有给定名称的资源。资源是可以通过类代码以与代码基无关的方式访问的一些数据(图像、声音、文本等)。并返回资源的URL对象。
&& ● public InputStream
getResourceAsStream(String name);
返回读取指定资源的输入流。这个方法很重要,可以直接获得jar包中文件的内容。
ClassLoader是abstract的,不可能实例化对象,更加不可能通过ClassLoader调用上面两个方法。所以我们真正写代码的时候,是通过Class类中的getResource()和getResourceAsStream()方法,这两个方法会委托ClassLoader中的getResource()和getResourceAsStream()方法
。好了,现在我们重新写一段Resource代码,来看看上面那段费解的话是什么意思了:
Java代码 &
//源代码2:
package&edu.
import&java.io.*;
import&java.net.URL;
public&class&Resource&{
&&&&public&&void&getResource()&throws&IOException{&&
&&&&&&&&&&&&&&//查找指定资源的URL,其中res.txt仍然开始的bin目录下&
&&&&&&&&URL&fileURL=this.getClass().getResource("/resource/res.txt");&
&&&&&&&&System.out.println(fileURL.getFile());
&&&&public&static&void&main(String[]&args)&throws&IOException&{
&&&&&&&&Resource&res=new&Resource();
&&&&&&&&res.getResource();
//源代码2:
package edu.
import java.io.*;
import java.net.URL;
public class Resource {
void getResource() throws IOException{
//查找指定资源的URL,其中res.txt仍然开始的bin目录下
URL fileURL=this.getClass().getResource("/resource/res.txt");
System.out.println(fileURL.getFile());
public static void main(String[] args) throws IOException {
Resource res=new Resource();
res.getResource();
运行这段源代码结果:/E:/Code_Factory/WANWAN/bin/resource/res.txt&
(../ Code_Factory/WANWAN/..
project所在的路径)
&&&&&&&&&&
我们将这段代码打包成ResourceJar.jar ,并将ResourceJar.jar放在其他路径下(比如
c:\ResourceJar.jar)。然后另外创建一个java
project并导入ResourceJar.jar,写一段调用jar包中Resource类的测试代码:
Java代码 &
import&java.io.IOE
import&edu.hxraid.R
public&class&TEST&{
&&&&public&static&void&main(String[]&args)&throws&IOException&{
&&&&&&&&Resource&res=new&Resource();
&&&&&&&&res.getResource();
import java.io.IOE
import edu.hxraid.R
public class TEST {
public static void main(String[] args) throws IOException {
Resource res=new Resource();
res.getResource();
&&&&&&&&&&
这时的运行结果是:file:/C:/ResourceJar.jar!/resource/res.txt
&&&&&&&&&&
我们成功的在运行时动态获得了res.txt的位置。然而,问题来了,你是否可以通过下面这样的代码来得到res.txt文件?
&&&&&&&&&&&&&&&&&&
&& File f=new
File("C:/ResourceJar.jar!/resource/res.txt");
&&&&&&&&&&&
当然不可能,因为".../ResourceJar.jar!/resource/...."并不是文件资源定位符的格式
(jar中资源有其专门的URL形式: jar:&url&!/{entry}
)。所以,如果jar包中的类源代码用File
File(相对路径);的形式,是不可能定位到文件资源的。这也是为什么源代码1打包成jar文件后,调用jar包时会报出FileNotFoundException的症结所在了。
我们不能用常规操作文件的方法来读取ResourceJar.jar中的资源文件res.txt,但可以通过Class类的getResourceAsStream()方法来获取
,这种方法是如何读取jar中的资源文件的,这一点对于我们来说是透明的。我们将Resource.java改写成:
Java代码 &
//源代码3:
package&edu.
import&java.io.*;
public&class&Resource&{
&&&&public&void&getResource()&throws&IOException{
&&&&&&&&//返回读取指定资源的输入流
&&&&&&&&InputStream&is=this.getClass().getResourceAsStream("/resource/res.txt");&
&&&&&&&&BufferedReader&br=new&BufferedReader(new&InputStreamReader(is));
&&&&&&&&String&s="";
&&&&&&&&while((s=br.readLine())!=null)
&&&&&&&&&&&&System.out.println(s);
//源代码3:
package edu.
import java.io.*;
public class Resource {
public void getResource() throws IOException{
//返回读取指定资源的输入流
InputStream is=this.getClass().getResourceAsStream("/resource/res.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(is));
String s="";
while((s=br.readLine())!=null)
System.out.println(s);
我们将java工程下/bin目录中的edu/hxraid/Resource.class和资源文件resource/res.txt一并打包进ResourceJar.jar中,不管jar包在系统的任何目录下,调用jar包中的Resource类都可以获得jar包中的res.txt资源,再也不会找不到res.txt文件了。
已投稿到:我的m811下载的程序都无法*** 显示什么出于安全考虑
你的手机已经设置为禁止***来源不明的应用 无法设置
已有2个回答
[特聘专家]
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因×
擅长领域:
参与话题:
设置里的未知来源没打开,这种情况下是不能***第三方软件的,只能***Android自身的系统软件和手机生产商指定的软件。在设置--安全里面有一个未知来源,点击勾选就可以了,这个就是限制第三方软件的一个设置。话说Android机是有这个选项的,苹果手机是没有的哦。
留下你的评论
请根据此专家回答质量,为他分配您赏赐的元赏金额度
回答都不满意,申请
备注:撤回的赏金由编辑审核后,在5个工作日内进行退回。为避免个别用户故意撤回打赏在审核阶段,如果编辑认为回答中有完整并且正确的回答,编辑有权将打赏分配给回答者。
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因×
擅长领域:
参与话题:
& & 设置--安全和隐私--未知来源即可开启,如果还是不能***软件的话建议你重置系统。
留下你的评论
该内容由系统自动生成
参考价:¥699.00
主屏尺寸5英寸
电池容量2500mAh
主屏分辨率像素
电池类型可拆卸式电池
后置摄像头800万像素
CPU频率1.2GHz
前置摄像头120万像素
CPU类型高通 骁龙Sna
名网友点评分数
对于中国移动如果你还停留在单单的运营商层面上你就OUT了,其实从很早中国移动就尝试对硬件设备的开发和生产,比如3G时代的定制的一些移动上网设备。从近几年不断...
微信公众账号ZOL问答堂
关注微信,随时随地解答您的疑惑
ZOL问答堂官方微博@ZOL问答堂
关注成功!该问题被回答后,将给您发送站内短信。
您也可以通过关注问答堂微信,及时获得您关注问题的回答。
微信关注问题方法“”

参考资料

 

随机推荐