I seem to have a strange issue which is most likely to be caused by not understanding how the including of additional libraries in java work.
I wrote a program that uses jnetpcap.jar to work with pcap files. The application is running fine when I start it from eclipse and has also worked many times by exporting a runnable jar (copying required-libraries to sub-folder). It even worked on other computers.
As mentioned in jnetpcap doc, the computers running windows have put jnetpcap.dll into C:\Windows (according on every machine the x86 or x64 dll)
Anyhow, the following scenario is reproducable on my and other machines:
running the complete eclipse project works
running from cmd with java -jar pcapdump.jar works
double-click jar the gui etc. works - but the "main work" is not done, so no pcap file is used.
I don't see any errors in my logs.
Configuration in eclipse:
added an external user library. pointing to my local jnetpcap.jar and source-jar.
When exporting as runnable-jar with copying libs to sub-folders the jnetpcap.jar gets copied into a separate sub-folder. Like I did it many times before.
Anyhow the described problem exists today and I don't know what I am doing wrong or what may be wrong.
Related
Our CE project includes a .jar file which is written for Windows only for some reason. Unfortunately, I do all my coding related projects on Ubuntu and I'm really not willing to install VS on windows and start over on a new environment and lose a lot of efficiency.
The jar file requires some other files to work but the directory formats differ in Linux so I'm getting errors of it not finding the files when I try to open it from Linux.
I've already asked for the source code or a more compatible version but the TA's aren't really cooperative in my case.
Is there any way I could circumvent this problem and fix the incompatible directory formats issue(For example by running through wine)?
Edit: I tried decompiling the jar, but it wasn't fully successful and some of the files came out corrupted.
Because the original maintainers didn't think that this JAR would be run on other OSes, you're stuck placating their arbitrary requirement. You're going to want to use a VM (Wine isn't an emulator and you're going to run into significant pain using it and Java to run a JAR) to set this up and execute their JAR.
Once you get a hold of the source, you can build a new JAR which asks the OS which file separator to use instead of allowing the code to assume Windows. Or use NIO.
I have a weird problem - I have a javafx program that I compile and package using maven (for windows I use Inno setup to create a setup package). After upgrading from Java 8 to Java 10 (updating the plugins in the pom.xml file and updating the configuration) - iv'e gotten to a point where the build completes successfully.
The problem is that after installing the package on windows - the exe file that's starts the program won't run properly. It starts for a split second and then stops.
The weird part : if I try to run the same exe from the target\bundle folder (the folder where maven prepares the files for the packager) - it runs fine!
the two folders - target\bundle and Programs files(x86)/vendor/appname are identical (files and the configuration file content).
I checked the permissions of the exe under Programs files(x86)/vendor/appname and they seem fine.
I'm testing on a windows 8.1 machine (an on others which display the same behavior, which leads me to believe this a real problem and not a mis configuration of my testing machine).
the same script is used for creating an installation package for MAC OSX and everything works fine on OSX so it's not a problem with the code.
Any ideas as to what's causing this and how to fix it?
Additional info :
This has only started to happen since moving to Java 10. Java 8 and 9 work perfectly.
My app does not write to any files in the program files installation folder. configuration and log files are written to in the %user%/AppData folder only.
I found the problem by creating a working setup package manually with the Inno setup wizard and then comparing it to the one I had that was not.
After doing this I compared the iss file (Inno config file) that the wizard created with the only that wasn't working. It turned out that the bouncy castle jar files created a problem. The iss script from the previous version copied them to the lib/ext folder and that created a duplicate classpath problem for the java class resolver as there were two copies of the jar.
This is not needed in Java 9 and Java 10. Removing the manual addition of the bouncy castle jars from the iss file fixed the problem.
Hope this helps someone in the future :)
I wrap my Java project's JAR file to an .exe file using launch4j, which works fine on my dev machines and several other computers. However, one user reported he cannot run the .exe file on his machine, as a popup message tells him
Could not find the main class.
Interestingly, the user is able to run the JAR file directly on the same computer, either by calling it via java -jar from command line, or directly by double-clicking the JAR file in the Windows explorer (or via shortcut). That user has installed latest JRE.
I have seen on other threads here that this problem could occur because of invalid Manifest files, e.g. if the main class is missing there. However, I think this is not the case, because it's working fine if the JAR is called directly as said.
So I assume the problem is somewhere with my launch4j configuration. There I have not specified a custom Manifest file, only the input JAR file and the output .exe file.
I thought my launch4j config would be fine, because the .exe is running on several machines using different Windows versions. This is the first time I encounter that problem, but as said with the .exe file only.
Any ideas?
We just found the problem with that one client machine. It had the 64 bit version of the JRE installed, that was causing the problem. After replacing it with the 32 bit JRE version the .exe file can be correctly started again.
Yes,even I faced this problem. I used jar2Exe instead of launch4j. It's working fine.You better use it.
This is my first question, so apologies for any mistakes. I'll try and give all the info I can. Basically I've written a simple swing application which just loads in image into a JPanel and displays it. I'm using Netbeans 7.1 and I have the latest version of the Java SDK.
Anyway, I've used the "Build" feature in NetBeans 7.1 to deploy my application into a Jar file. When I double click the Jar File on my PC, it runs without a problem. However when I put it on other computers (Tested on 2 others so far, both with the most current JRE) it fails to open, citing the following error:
could not find the main class: swong.Startup. Program will exit
swong is my package name, and Startup is the location of my main method. I have checked the manifest file which is created with Netbeans' build, and it[the manifest] does indeed contain the location of my main method class.
From searching, I've come across similar issues in which the classpath is set wrongly, but I don't understand how this could cause my particular error.
If someone could help me, I would be over the moon. I've been studying java for a year or so, and I've got a good handle down, but I've NEVER been able to make a Jar that runs on a computer which wasn't my own. So, 10 points and thanks in advance.
xo.
EDIT: Thank you for the responses. I'm doing shift work and swamped, but I will test and poke with these responses tomorrow and provide more information. Thanks again. xo
I had d same problem while distributing my app. There is 1 solution that you create a batch file with 'java -jar AppName.jar' and asking user to double click on this batch file to execute your app. What i did was to provide a JRE installation exe(eg: jre_1.7.0) with your app.
Now create a Batch file (install.bat) in which write following commands
jre_1.7.0 -> this will install jre on user's pc
set path="C\Program Files\Java\jre_1.7.0\bin"
java -jar yourAppName.jar
Why i installed JRE because different people have different JRE versions installed. So this makes it difficult to set path to the installed JRE's bin folder & calling the 'java -jar' command. Hence as you know which folders your JRE installation will create hence it is easy to set path and execute your jar file with 'java-jar' command.
Check that your jar file has the following structure (at least)
jarfile.jar
|---------- swong
|---------- Startup.class
|---------- META-INF
|---------- MANIFEST.MF
It seems like the class "Startup" is missing. Maybe your jar only contains the .java files, not the compiled classes.
This error message can be a mistakable java7 error, when you try to start java7 compiled classes with a different Java Runtime Environment then java7. Have you validated, that your .jar is started within a Java7 environment on those other test machines? Sometimes it happens, that you have installed different versions of JREs and you might not be sure which one is actually started.
To check which enviroment is used, you can check in your registry for the following value:
HKEY_CLASSES_ROOT\jarfile\shell\open\command
this should point to your latest JRE. Or if you'd like to stay compatible to java6 as well, define the appropiate compile level in your build environment.
I have installed the Java 3D API on PC via the exe installer, which simply created a new directory with j3dcore.jar, vecmath.jar, j3dutils.jar in a lib sub-directory and j3dcore-ogl.dll in a bin sub-directory.
Netbeans had no issues and my code compiled and executed smoothly, however once I built my project and tried to run it from the command prompt I got an UnsatisfiedLinkError saying that no j3dcore-ogl in java.library.path.
Google came to the rescue and gave me 3 viable solutions:
by copying the dll file into my JRE's bin directory
by adding the path of the dll file to the library path (java -Djava.library.path=dllpath)
load the dll in the program with System.load() (I couldn't get this one to work, actually)
My question is: Is there an elegant solution to this problem, that I missed?
It seems tedious that for each different PC someone would like to use this program on, he'd have to either copy the dll or add it to the library path before it can run. (Side question: How come Netbeans didn't have a problem with the dll?)
Making my Java program easily distributable
If you mean 'easy for the end user' look to Java Web Start.
A passer-by asks:
Can you package the dll dependencies with Web Start?
Yes, but much, much better. You can package the natives for each platform in separate Jars, and supply them only to the platform that uses that native, even so far as partitioning the download between 32 & 64 bit versions of the natives.
JWS puts the natives on the run-time class-path of the application, ready for loading in code.
This all happens automatically for the end user, they click a link, approve the trust dialog(s) when asked, and the application installs - possibly with desktop integration, and appears on screen like magic.
JWS apps. that use natives need to be distributed as all-permissions security level, because the JVM cannot guarantee the actions of anything that 'goes native'.
Edit - After re-reading your question, your issue sounds different. However I'm able to get my running like so, by just dropping all dll files in the same directory as the .bat file starting the java process:
java -classpath ./YourJar.jar;./lib/j3dcore.jar;./lib/vecmath.jar;./lib/j3dutils.jar package.MainClass
And that works on multiple user's PCs, so I know simply dropping it in the working directory works.
I believe it depends on the version of Java being used - 64 bit or 32 bit. The correct dll file (of the same name) needs to be in the working directory.
I think I was getting a similar problem when the wrong dll was being used, and it's not OS-dependent (if your 64 bit OS has 32-bit Java installed, you'd need the 32 bit j3dcore-ogl.dll file).
So the question is, which version of Java are you using (when running outside of your IDE), and which version of the dll are you putting (if any) in the working directory? I don't need any dll files in my path settings to get this working on other's PCs, and did not use System.load(), and did NOT copy files into my user's JRE/bin directory - so I know this is possible without the 3 options you mention.
If you put the dlls in the same directory than you Jar, does it work?
If yes, you could consider distributing it like this.
I guess DLL are searched in all folders in %PATH% on windows. (LD_LIBRARY_PATH for UNIX flavors)
Could you try by adding the path to dll to %path% variable?
It appears that you are trying package a product with many jars as dependencies. You may benefit from One-Jar. It claims to have native dll support.