Error in preparing standalone Java application with external libraries - java

I have made a Java serial Interface using RxTx libraries in Netbeans 7.2.1 which works fine.
Tested it with NULL modem and it works fine. Now I need to create an exe which I can distribute.
So,Now I am trying to make a jar file for my project. What I did-
and then clean and build to get jar at location
"D:\Glaswegian\Java\Slides\RxTx\SerialCommInterface\SerialCommInterface\dist"
with below structure
with lib having RxTx.jar
Now when I try to run from command prompt:
I get below error
Can anyone please let me know how to resolve this?
Have refered
Run jar file in command prompt
How can I include external jar on my Netbeans project
But not able to resolve it.

The system cannot find some native libraries (which probably are needed by RxTx).
Assuming that the native libraries (*.dll) are in the lib folder - try to run the app like this:
java -Djava.library.path=lib -jar SerialCommunicator.jar

Related

How to bundle jar file with jre to make an runnable application on mac using intellij?

I'm trying to bundle my jar file with a jre into an executable on mac so that users using my application don't need to have java installed on their machine. I'm using IntelliJ's built-in tool that automatically bundles the jar file into a platform specific package but whenever I try to build the artifact I get an error message of
jpackage: No archive found
I was able to create a bundled .exe file with the jar file on windows using launch4j but that tool can't create mac executables (unless I'm mistaken) and it would probably be more convenient to learn how to use the IDE to do it for me.
I can't seem to find out what it is I'm doing wrong, nor can I find anything online about this error message. Any suggestions? (I'm using java 16)
I was able to fix this problem by deleting and re-doing the configuration for the package artifact build. Everything worked smoothly afterwards

I cannot run the code with external jar in Terminal but I can run it in any IDE

So I am new to the java.
I have these external two jar files. I properly imported them into my IDE: exclips.
When I use the IDE the code, it is running and using the external jars. However, when I am trying to use the terminal of MAC, it is giving a mistake of no two jars like this
testten.java:3: error: package stdlib does not exist import
In my IDE the testten.java is running and I have the testten.class. but in Terminal
How can I solve it ??
Try exporting the program as a runnable jar file. Then on PC navigate to the location of the jar file in CMD and type "java -jar {Name of jar file}.jar". On a mac navigate to the location of the file in Terminal and type "java -jar {Name of jar file}.jar". Hope this helps :) if the issue continuous try checking out this: Java Test package does not exist

Couldn't load class com.mysql.jdbc.Driver by class.forName("com.mysql.jdbc.Driver")

I'm doing simple java application that interacts with mySQL database. It should run on the Ubuntu Server. I'm developing it in the Intellij IDEA, and it works great there.
However, when I generate jar file and launch it in the Ubuntu command line (both server and my home PC running ubuntu), nothing works.
I simply type java -jar %my_jar_filename% and get the error
"Couldn't load main class ... Class.forName("com.mysql.jdbc.Driver")"
I know that since java 5(i'm not sure here which version, I use 8) it's not necessary to write it, but if I don't write it I get
"No suitable driver found"
I googled this problem and the only solution I found was to make sure the driver actually exist on the PC and add that Class.forName("");
It doesn't help me. Driver exists, because in the IDE program works. I think the trouble is with java options.
I tried to add mysql connector via java -cp,
but it gave me the same error and even tried to compile the program in terminal from source via javac, but also the same issue.
On my PC mysql connector is in the folder usr/share/java/
The server where application should finally work has the same settings
What am I doing wrong?
**SOLVED:**Thanks everybody The solution was quite simple. This answer helped https://stackoverflow.com/a/45303637/9184305
This could be because you're using the wrong driver - we use this class instead:
com.mysql.cj.jdbc.Driver
Reading your description, you might also have the problem that your code is working in your IDE but not when you try to run it from the jar / command line.
In that case,
how are you creating your jar?
do you deploy all your dependencies along with your jar?
do you have a MANIFEST.MF file that indicates your Main class?
This looks like problem with class path , it may not have h jar file . I would suggest to use maven and create maven project and build jar file. Maven will take care of the dependencies and packaging.

Program runs in Eclipse but running jar does not run

I'm working java swing application.My program run successfully in Eclipse but when i create running jar,it's does not opened.
I created running jar like this
In my option ,problem is that I'm using 4 jar library jmrtd.jar,Scuba.jar and etc.
What am I doing wrong? How i can create jar file,when I use some support libraries(jar files) ?
Please use option "Package required libraries into generated JAR"

convert a java project (I used in it JLayer 1.0.1 to play mp3) to a runnable jar file

I built a java project and I used (JLayer 1.0.1) to play mp3 audio.
when I test my project with eclipce I find that it worked correctly 100% and the JLayer 1.0.1 libraries play my mp3 files efficiently.
but when I convert it into a runnable jar file it works with NO SOUND OR AUDIO.
It seems that my program can't reach for Jlayer 1.0.1 libraries.
So now,I need your help to resolve this problem.
with my thanks
You can do the following in order to test your application: export your project as a regular jar and copy it together with the JLayer.jar and other dependencies to a directory. Then, create a batch file (.bat on Windows, .sh on Linux) that would include something like this:
java -cp yourjar.jar;JLayer.jar;other_jars FullPathToYourClass
where FullPathToYourClass is something like com.something.else.ClassName
Also note the the separator on Linux is :
Once you see it working, you can start to do a build script to do the above automatically. I would suggest you build an Ant build.xml file for this.
This can be a JRE issue (Eclipse can be using a different JRE from what your system uses), or a packaging problem.
When packaging using Eclipse, make sure you package all libs together with your classes. Do to that, select the option "Extract required libraries into generated JAR".
Another option is to run your JAR setting the classpath: java -cp yourjar.jar;yourlib1.jar;yourlib2.jar com.your.package.YourMainClass (note that the ';' is platform dependent) instead of java -jar yourjar.jar.

Categories

Resources