How to properly export a jar for running an applet? - java

I have been adding modifications to a Java application that runs on a server using an applet. On the server, there is just the jar file, and an index.html page that opens the applet.
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). 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.
I have opened the 2 jar archives to see what's inside, and here's what I get :
Old jar :
Different folders for the different packages of the app
bin folder
com folder
META-INF folder
org folder
.classpath file
.project file
java.policy.applet file
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
.classpath file
.fatjar file
.project file
java.policy.applet file
mysql-connector-java-5.0.8-bin.jar
settings.fatjar file
So my archive doesn't have the bin, com and org folders. It also has 2 additionnal files.
I don't know which settings should I use when exporting my jar in Eclipse to obtain the same content ?
Also, my new jar isn't signed, could this have something to do with my problem of database access ?

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
The jar must be signed (self signed works as it is an internal app, so no need to pay a certificate)
Now it works :)

Related

Creating war from its component folders

I have deployed my war file on a remote linux server. I run this war using jetty-runner. Its not feasible for me to push this war multiple time. Its size is huge and it takes aprrox 45 min to push a fresh war onto the server. To handle this issue I thought of using the following steps(with commands) :
unzip:Unzip war to its corresponding files/folders : WEB-INF, META-INF, index.jsp.
Updating new class file in WEB-INF.
zip:Repacking these folder into a war again.
But the newly created war does not work. Is there a standard/correct way to pack these files into a war. Also, jar command is not available on the server.
Please suggest.
P.S. Already looked into various SO questions but didn't find any useful solution.
The zip command does not work as expected. The war packed by that command did not work. Instead, we have to use the JAR command.
I was able to generate the war after modifying the contents by using :
jar -cvf webproject.war index.jsp META-INF/ WEB-INF/
Note: If the jar command is not available on the server, specify JAR path using installed java on the server:
PATH_TO_JAVA/bin/jar -cvf webproject.war index.jsp META-INF/ WEB-INF/

Gradle - JARs copied into WEB-INF getting overwritten by GoogleAppEngine?

I'm currently using Gradle to compile and upload my Java code to GoogleAppEngine. It compiles fine locally, the problem is that the JAR libraries that the code is dependent upon are not within the "WEB-INF" folder on GAE.
I'm currently using War to copy the JAR files to WEB-INF using:
copy {
from 'libs'
into 'build/exploded-war/WEB-INF'
include '**/*.jar'
}
The problem is that if it does this before the "gaeUpdate" command then the WEB-INF folder is overwritten and the JARs are deleted and thus not uploaded. If it does it after the gaeUpdate command then it's too late, the files have already been uploaded to the server and they are thus not uploaded.
It's important to note that if I enter "gradle" in the console without the "gaeUpdate" then the JARs don't get deleted, it's only when the "gaeUpdate" is added that they appear to get removed.
Is there way to upload the files after the "build" folder has been created but before the server upload?

execuable jar file does not work in different folders

I have a big project and runs well in Eclipse. I build a runnable jar file by eclipse. When I put the jar file directly on the desktop it runs well, however if I make a new folder and move the jar file to the new folder, it does not work correctly, the output file is empty.. No errors appear.

Jar to Exe - Main class not found

I made a small game in Java.
It had about 5 different classes and the main class being in Game.java
I compiled it into a jar file and I did everything correctly with my manifest.txt which gives the name of the file where the main class is in.
The jar file worked on my computer so I then converted it into an exe file and sent it to someone else.
When My friend tries to run the exe file, it gives him an error saying:
Could not find main class game. Now exiting.
The exe and jar file work fine on my computer but not on a different computer.
We both also run Windows 7.
What went wrong?
I think you need to have every library used in your application beside your EXE file in lib folder. interestingly enough, when lib files are missing, the error shown is about main class, which is so not the case ;) anyway, I had the same problem and got it resolved by including lib folder beside my exe file. this is part of readme.txt generated by net-beans in dist folder, that might be helpful to you:
======================== BUILD OUTPUT DESCRIPTION
when you build an Java application project that has a main class, the
IDE automatically copies all of the JAR files on the projects
classpath to your projects dist/lib folder. The IDE also adds each of
the JAR files to the Class-Path element in the application JAR files
manifest file (MANIFEST.MF).

How can i create executable apple .app file from my java .jar file?

I have created an executable java Swing .jar application. It works fine on Windows. The application hierarchy is :
application.jar
images(Folder) .......... Contains all images the application uses.
libraries(Folder) ....... Contains all external jar libraries the application uses.
bundles(Folder) ......... Contains all bundle files the application uses.
database(Folder) ........ Contains the database files the application uses.
All the above folders exist outside the jar file. Now i am trying to create a Mac executable file (.app) from "application.jar" to run it on Mac so i used the "Jar Bundler" as specified here but when i run the output application.app file nothing happens, nothing runs and i can't even debug it.
I think the main reason is that it can't see the external folders. So is it impossible to create a .app file if the application has external folders ?
And is there a way to debug the .app file to see what's going on ?
Nothing runs, and i can't even debug it.
Diagnostic output from the launch process may be obtained as follows:
$ export JAVA_LAUNCHER_VERBOSE
$ ./YourApplication.app/Contents/MacOS/JavaApplicationStub
There's a related example here.
Most likely the problem is your working directory.
When you run an executable JAR file by double-clicking it, the working directory is the parent directory of the JAR file.
By default, the working directory of an application bundle is its parent directory. If you package the external folders into the application bundle they will be located under $APP_PACKAGE/Contents/Resources.
So the assumption about the working directory that you make for an executable JAR file does not hold for an application bundle.
In order to set the working directory to the resources directory, add
<key>WorkingDirectory</key>
<string>$APP_PACKAGE/Contents/Resources</string>
to the Info.plist file of your bundle.
In case you know nothing about application bundles, please read this document.
This might help: AppBundler by Josh Marinacci
I am not sure about your exact directory hierarchy. But on a Mac with Xcode installed is an application called "Jar Bundler". It exist for exact that purpose you are asking for.
BTW, Mac application use the suffix .app, that is right. But they are not files. Thery are directories.

Categories