简体   繁体   English

如何正确导出用于运行小程序的jar?

[英]How to properly export a jar for running an applet?

I have been adding modifications to a Java application that runs on a server using an applet. 我一直在对使用applet在服务器上运行的Java应用程序进行修改。 On the server, there is just the jar file, and an index.html page that opens the applet. 在服务器上,只有jar文件和一个可打开小程序的index.html页面。

Now, I am trying to test the new version of the app on my computer before putting it on the production server, and it doesn't work : the application doesn't connect with the MySQL DB (when I just run it from Eclipse it works, it is when I try to run the jar file from my browser that it doesn't work). 现在,我正在尝试在计算机上测试该应用程序的新版本,然后再将其放置在生产服务器上,但它不起作用:该应用程序无法与MySQL DB连接(当我只是从Eclipse运行它时)起作用,就是当我尝试从浏览器运行jar文件时,它不起作用)。 I tried running the old app on my desktop the same way and it runs just fine, so I guess the problem is in my jar file. 我尝试以相同的方式在桌面上运行旧应用程序,并且运行得很好,所以我猜问题出在我的jar文件中。

I have opened the 2 jar archives to see what's inside, and here's what I get : 我打开了2个jar存档,以查看其中的内容,这是我得到的:

Old jar : 旧罐子:
Different folders for the different packages of the app 应用程序不同包的不同文件夹
bin folder bin文件夹
com folder com文件夹
META-INF folder META-INF文件夹
org folder org文件夹
.classpath file .classpath文件
.project file .project文件
java.policy.applet file java.policy.applet文件
mysql-connector-java-5.0.8-bin.jar mysql-connector-java-5.0.8-bin.jar

And now, here is what's inside the new jar : 现在,这是新罐子里面的东西:

Different folders for the different packages of the app 应用程序不同包的不同文件夹
META-INF folder META-INF文件夹
.classpath file .classpath文件
.fatjar file .fatjar文件
.project file .project文件
java.policy.applet file java.policy.applet文件
mysql-connector-java-5.0.8-bin.jar mysql-connector-java-5.0.8-bin.jar
settings.fatjar file settings.fatjar文件

So my archive doesn't have the bin, com and org folders. 因此,我的存档中没有bin,com和org文件夹。 It also has 2 additionnal files. 它还有2个附加文件。

I don't know which settings should I use when exporting my jar in Eclipse to obtain the same content ? 我不知道在Eclipse中导出jar以获取相同内容时应该使用哪些设置?

Also, my new jar isn't signed, could this have something to do with my problem of database access ? 另外,我的新jar未签名,这与我的数据库访问问题有关吗?

I'll answer my own question, as I found the solution : 找到解决方案后,我将回答我自己的问题:

The jar needs to be exported as a runnable jar 该罐需要导出为可运行罐
The option "extract required libraries into jar" must be selected 必须选择选项“将所需的库提取到jar中”
The jar must be signed (self signed works as it is an internal app, so no need to pay a certificate) 罐子必须签名(自签名的作品是内部应用程序,因此无需支付证书)

Now it works :) 现在可以了:)

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

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