NoClassDefFoundError when run Java ME project which, use Bouncy Castle Library - jar

I wanna use decode Base64 function in Java ME project so, I add bcprov-jdk15on-149.jar to my project.(Bouncy Castle Library)
By Adding Hardware JAR Files, I got this error:
java.lang.NoClassDefFoundError: org/bouncycastle/util/encoders/Base64
Then, I try Adding Application JAR Files, I got another error; The project package got red cross and I cannot run the project.
I'm not sure what did I do wrong, you guy have any suggestion?
(I use Eclipse Java ME Nokia sdk 2.0, JRE1.7U17 , JDK1.7u17)

Related

Runnable Jar from a JavaFX 8 project, JavaFX compenents are missing

i created a Javafx project using JDK 8 and when i tried to export it to a runnable .jar file, i got surprised that it doesn't run using CMD, and gives the following error :
"Javafx compenents are missing"
while it works perfectly during the compiling time(using the IDE) when i accessed the .jar files, i found it has just .class files (that i made), and the needed library files that haven't been exported (i made sure to select the "extract need library files extract required libraries into generated jar" option in Eclipse), is there a reason behind of this? and a way to solve it? thanks in advance
Ps: i tried this using Eclipse and Intellij IDE
I just wanna mention once again that I'm using JDK 8 where it has JavaFX library inside of it.
Did you try this?
There are detailed instructions on how to configure your IDE to run JavaFX with newer OpenJDKs (which do not come with JFX components in it).
It also explains how to create a new JavaFX Maven project from archetype, with all the necessary plugins to easily build your application while including the minimal Java components for it (using jlink).
This will ensure that anybody using your application will have those components.

How to create a jar library (not aar) in android studio?

how can i create a jar binary library project in android studio that can be used in other projects (meaning - an sdk)?
if it is possible, i want it to contain both java files and native cpp code (java files will start audio listening and cpp files for analysis).
there is no resources/layouts in the library.
if i add an android library module, its ouput is an aar file and not jar.
i read that eclipse does not support aar and so that is why i want it to be jar.
thanks a lot!
What you need to do is to put aside the Android "nature" of Android Studio and just write and build a normal Java/C++ project with Gradle. Your first stops will be Java quickstart and Native support documentation of Gradle.
In gradle find command "createFullJarDebug"
This command will generate jar file under build\intermediates\full_jar\debug\createFullJarDebug\full.jar
then you could use it.

Java Compiler multi-platform

How could I compile a Main.Java program to something that I could run with OpenJDK Java 6 or 7 . The program doesn't contain anything besides displaying the message "Hello World"
I would like to compiler to .JAR
Also if I compile the program will it run in Windows or do I got to cross compile like C++ if I'm using Linux as the native developer.
I'm using the Linux Ubuntu OpenJDK Development Kit (JDK)
This is how you compile.
cristian#ubuntu:~/Java$ javac Main.java
but how would you compile to a .JAR file so I can run it in my Windows.
Any guides to learning Java are welcome and thanks for the help.
I'm using Linux Ubuntu.
You must specify your main class in the JARs manifest in order for it to be runnable. You can then invoke your application from it's jar as follows
java -jar application.jar
Current versions of the JDK for Windows will create a file association for .jar files so if you click on them they will execute.
For further details, take a look at Oracle's Jar Tutorial, specifically the section on Setting an Application's Entry Point
Edit
Regarding the need for cross compilation... Since Java compiler targets a virtual machine, you do not need to cross compile for different operating systems. (One of the early taglines for Java was "Write Once Run Anywhere".)
Here is a decent article on the basics of how the JVM does its magic: What Is The Java Virtual Machine & How Does It Work?
The Oracle Java Tutorials are an solid starting point for many things java related and I recommend reading through them if you are new to Java.
Java's JAR files are platform independent and only require an installed JRE/JDK.
OpenJDK does almost the same thing as Oracle JDK however you can also get the Oracle JDK on Linux Ubuntu by using third-party repositories such as ppa:webupd8team/java(details on how to use the repository are provided on the webupd8 website) i found i needed to switch to oracle java for performance issues.
Most common IDE's for java provide support for compiling and packaging to JAR/Runnable JAR.
A popular java IDE is Eclipse(http://eclipse.org) other popular IDE's include NetBeans and JetBrains IntelliJ IDEA.
Most programmers use IDE's for ease of use and other functionality such as IntelliSense(Autocomplete), error checking, Syntax highlighting and debugging.
A good guide to learning java is http://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28. Other guides such as java game development can also be found on Thenewboston's channel or thenewboston website.

How to add a jar library into another jar library

i am doing a java library that is using jaybird jar.
I want my library to be a jar with the jaybird in it so when I have to use it, I only import my jar.
How can this be done? I'm using Eclipse Version: Indigo Service Release 2.
Thanks in advance!
It can be done, but requires a special launcher using a specific classloader to extract the inner jar from the outer jar.
I would simply use the standard way of doing: deliver both jars, along with a startup .bat/.sh file used to start the application, the whole being packed into a simple zip file.

java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path

I'm trying to access a Berkeley DB database file (say Test.db) from the java code and then want to read all the pairs from it. I'm using the com.sleepycat.db.* and com.sleepycat.bdb.* packages ( NOTE: Not Oracle Berkeley DB JE )to do this task. For the implementation, I did exactly as described in this BerkeleyDB Java API Tutorial
So, when I run this project from eclipse I got this error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path
and from the stack trace, source for this exception occured from this line
env = new DbEnv(0);
I tried to set it from the java command
$java -D<name>=<value>
but still it didn't work.
My goal is to export this project into a jar file and use it to read BDBs anywhere . Anyone who knows how to get out of this, I appreciate your help. It would be great if I can be redirected to any working tutorial for accessing Berkeley DBs from java code too. Thanks !!
SOLUTION: After a lot of work, I found out that the Sleepycat API that I'm working on is using native libraries that are written in C/C++ through the JNI. Berkeley DB that is installed on my PC didn't have the shared object file db_java-4.2 (to be accurate, file name is libdb_java-4.2) which means that this BDB is not configured for java APIs.
So, the solution is to start the installation of BDB from scratch again by enabling the java configuration.
I had the same problem.
Like kK_Pulla mentioned, the sleepycat API using native libraries written in C/C++ through the Java Native Interface. So making Sleepycat API calls means the java code is ultimately going to call compiled C/C++ code.
If you are getting the "java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path" error then it is likely that, at least it was in my case, you have not included the relevant native libraries in your project.
I would describe what I did to fix it in my case. Firstly let me describe my environment.
IntelliJ maven Java project on a linux machine.
Built Berkeley DB version 18.1.40.
The Berkeley build included the --enable-java switch in the configuration phase.
I included the db.jar (found in the build_unix directory) as a module dependency through the Intellij menus File> Project Structure. I selected Modules under Project settings on the left pane and then under the dependencies tab I added the db.jar file as a dependency.
This was the state of my project before I encountered the UnsatisfiedLinkError. To fix that I added the native libraries (found in the unix_build/.libs directory) to the project. You can do this by selecting the File menu> then Project Structure. On the left pane under project settings select Libraries and then click the + sign on the right pane to add the directory for the native libs.
This fixed my problem.

Resources