How to add a jar library into another jar library - jar

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.

Related

java.lang.ClassNotFoundException: Could not load requested class : oracle.jdbc.driver.OracleDriver [duplicate]

How should I add JAR libraries to a WAR project in Eclipse without facing java.lang.ClassNotFoundException or java.lang.NoClassDefFoundError?
The CLASSPATH environment variable does not seem to work. In some cases we add JAR files to the Build Path property of Eclipse project to make the code compile. We sometimes need to put JAR files inside /WEB-INF/lib folder of the Java EE web application to make the code to run on classes inside that JAR.
I do not exactly understand why CLASSPATH does not work and in which cases we should add JARs to Build Path and when exactly those JARs should be placed in /WEB-INF/lib.
The CLASSPATH environment variable is only used by the java.exe command and even then only when the command is invoked without any of the -cp, -classpath, -jar arguments. The CLASSPATH environment variable is ignored by IDEs like Eclipse, Netbeans and IDEA. See also java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable.
The Build Path is only for libraries which are required to get the project's code to compile. Manually placing JAR in /WEB-INF/lib, or setting the Deployment Assembly, or letting an external build system like Maven place the <dependency> as JAR in /WEB-INF/lib of produced WAR during the build, is only for libraries which are required to get the code to deploy and run on the target environment too. Do note that you're not supposed to create subfolders in /WEB-INF/lib. The JARs have to be placed in the root.
Some libraries are already provided by the target JEE server or servletcontainer, such as JSP, Servlet, EL, etc. So you do not need put JARs of those libraries in /WEB-INF/lib. Moreover, it would only cause classloading trouble. It's sufficient to (indirectly) specify them in Build Path only. In Eclipse, you normally do that by setting the Targeted Runtime accordingly. It will automatically end up in Build Path. You do not need to manually add them to Build Path. See also How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
Other libraries, usually 3rd party ones like Apache Commons, JDBC drivers and JEE libraries which are not provided by the target servletcontainer (e.g. Tomcat doesn't support many JEE libraries out the box such as JSF, JSTL, CDI, JPA, EJB, etc), need to end up in /WEB-INF/lib. You can just copy and paste the physical JAR files in there. You do not necessarily need to specify it in Build Path. Only perhaps when you already have it as User Library, but you should then use Deployment assembly setting for this instead. See also ClassNotFoundException when using User Libraries in Eclipse build path.
In case you're using Maven, then you need to make absolutely sure that you mark libraries as <scope>provided</scope> if those are already provided by the target runtime, such as JEE, Servlet, EL, etc in case you deploy to WildFly, TomEE, etc. This way they won't end up in /WEB-INF/lib of produced WAR (and potentially cause conflicts with server-bundled libraries), but they will end up in Eclipse's Build Path (and get the project's code to compile). See also How to properly install and configure JSF libraries via Maven?
Those JARs in the build path are referenced for the build (compile) process only. If you export your Web Application they are not included in the final WAR (give it a try).
If you need the JARs at runtime you must place them in WEB-INF/lib or the server classpath. Placing your JARs in the server classpath does only make sense if several WARs share a common code base and have the need to access shared objects (e.g. a Singleton).
If you are using Maven:
Open the project properties, and under Deployment Assembly click Add...
Then select Java Build Path Entries and select Maven Dependencies
Resolved by setting permissions.
Had related issue using PySpark and Oracle jdbc. The error does not state that the file cannot be accessed, just that the class cannot be loaded.
So if anyone still struggles, check the permissions. Some might find it obvious tho'.
I want to give the answer for the folowing link question ClassNotFoundException oracle.jdbc.driver.OracleDriver only in servlet, using Eclipse
Ans: In Myeclipse go to Server-->left click on Myeclipse Tomcat7-->Configure Server Connector-->(Expand)Myeclipse Tomcat7--> Paths-->Prepend to classpath-->Add jar (add oracle14 jar)-->ok

import play framework module as jar into java project

I have created a play module, how I can import the exported jar to normal java project(not play project)?
When I tried it it gives error:
The type play.libs.F$Promise cannot be resolved. It is indirectly referenced from required .class files
You need to include the play libs as well. Have a look at the deployment documentation. activator dist allows you to create a standalone distribution for your entire play-app.
You can also search the jars in the output for the one which contains the classes you need and just add this one jar to your project.
Or: use sbt/maven to manage your dependencies and add the entire play-framework. (seems to be a bit of an overkill though)

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.

IDEA: create jar artifact from Android

I am building an Android app, and I would like to repackage some of its classes as a .jar library.
I have tried the "build artifact" from IDEA, but I get a jar that also contains the unsigned APK and all the classes.
What is the correct way of generating a Jar file out of a folder of classes?
Do I need to create a separate project for the library classes?
It's recommended to have a separate module with the library code and make your Android app depend on this module. Building artifact from this module output classes will not have any extra files.

In a talend job, how can I add a dependent jar file?

I want to make use of the utility methods from a jar file, in my talend job routines. How can add this jar as dependent to my current job?
Try using the tLibraryLoad component - it lets you load a jar file so you can add it in the beginning of your job and the library will be available thereafter.
tLoadLibrary will work, or you can also add dependencies to a job by right-clicking on the job in the repository too.

Resources