This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Clean way to combine multiple jars? Preferably using Ant
Include java libraries into own library
I have created a jar containing some custom code and a bunch of 3rd party jars. I don't want to explode the 3rd party jars that are in the jar created by me. I want to use this jar to build my webapp. Am using ant to do this. Please suggest a native/open source solution.
Since you are building a web app, you should be putting all the jars into the WEB-INF/lib directory of your war, using the ant <copy> task. The comments above are for putting jars inside other jars, but for your case, that is not what you want to do.
just export runnable jar file from eclipse adding library to the jar. when name of jar is asked under the textedit are three radio button where you can choose if you want to add jars, in app next .jar or inside it, or don't add it :)
Related
This question already has answers here:
Including dependencies in a jar with Maven
(16 answers)
Closed 5 years ago.
I'm trying to develop a plugin for an FOSS application written by someone else. All I need to do is take a single class I've written, package it in a JAR file, and copy the JAR file to a directory in a pre-existing installation of the application.
When the application sees my JAR file, it should load it on startup.
Problem is, it doesn't seem to be able to load my JAR file.
According to their docs, my manifest may need a CLASSPATH specified.
My JAR file structure is simply: MyJarFile.jar/MyClass.java
It's literally just a JAR file with a single JAVA class file inside it.
I'm new at this, and all the manifest file examples I'm seeing on Google seem to reference other JAR files.
Do I even need to have a CLASSPATH in the manifest?
If so, how do I reference MyClass.java?
I'm using IntelliJ and Maven (for the first time).
Thanks.
Check out the article "Setting an Application's Entry Point" in the java docs:
https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
You need to add a line to the manifest like "Main-Class: MyClass" if you haven't already in order to run the jar.
Do you need to reference classes from another JAR from within your JAR?
If so, you will need to add to the JAR's classpath. See https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html for how to do that.
In general, I would suggest reading the java docs info on JARs
https://docs.oracle.com/javase/tutorial/deployment/jar/index.html
If you still need help after reading that, please explain your specific use case in more detail, e.g. share actual code or error messages
Try this: Click "File" -> "Project structure" -> "Artifacts" -> right click your jar file and choose "Put into output root"
This question already has answers here:
How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
(16 answers)
Closed 6 years ago.
I am modifying behavior of a web-app(server & client) running on web-sphere. I have de-compiled the code and just need to make minor changes and redeploy the code.
For this I made a simple Java Project with Eclipse EE and loaded all the de-compiled code. I only need the *.class files which I will convert to a JAR and place them at their proper place. The thing is there is a dependency which is not being resolved javax.servlet.http.HttpServletRequest so my project is not building
How to resolve this dependency?
If this dependency cannot be resolved than my guess is I could just get the JAR file for javax.servlet.http.HttpServletRequest and add to the Project's Build Path as an external JAR.
Where can I find the JAR for javax.servlet.http.HttpServletRequest
p.s. I am new to JAVA so I don't know much about HttpServletRequest also I am using Java 1.6 JRE.
A long time ago I used to manually add the servletapi.jar into my eclipse project, but that is a bad practice.
Now I just create a Dynamic Web Project, then add a server (usually Tomcat), then right click on the new project - select properties - select project facets and add the Tomcat Server as the runtime. It has the files you need. Once you hit the apply button and okay button it will resolve the missing import files.
Here is a step by step description from a similar question on SO: How do I import the javax.servlet API in my Eclipse project?
You'll want to add the Servlet API as a "provided" dependency. That is, you only use it to compile the code, but you don't need to package it with your web application since your web container will already contain a copy of it.
Just Download Servlet.jar file from below link.
http://www.java2s.com/Code/Jar/s/Downloadservletapi30jar.htm
add this jar file into your project using build path in eclipse.
This question already has answers here:
How can I use external JARs in an Android project?
(12 answers)
Closed 9 years ago.
I am new in using jar files in Android application. While checking code for Android apps code.google.com suggested the jar files. I don't know how to use the classes from jar files. Please help me!
Thanks
Just put the jar in the libs folder of the project, then it will automatically be added to your project by Android SDK.
Now the code from the jar is accessible in your code.
If you added a jar containing the package org.jartest with the class IAmAnObject. You should be able to write IAmAnObject test = new IAmAnObject(), right click IAmAnObject in eclipse and select import org.jartest.IAmAnObject.
Create a folder that is called /libs at the root directory of your project, and put your jar files in there.
I don't know about eclipse.
The way you use a external library in an android project is by creating a 'libs' folder in the projects source folder and putting the jar files in their.
Don't forget to add the path of libs to the build path so they are available when building the final project (in eclipse it's right click the jar and select 'add to build path'
It has already been answered and a definite duplicate but I cannot seem to paste the answer URL.
I have a java main project and a java library project which is added as a library in the main.
The library has some .jars with essential content for both (the main and the library). I thought the main project could access these jars, but apparently not. Am I correct?
So... I thought I would have to dupplicate the .jars from the library and put them also in the main project. But this is quite awful. So I found the "Adding external .jar" from eclipse which let me add this .jar from the library, but my question is: "What will happen when I build an unique .jar? Will the .jar be added to the library and also to the main dupplicating itself?"
Also, can I import as a library an open project wihout having to compile it into a jar and be able to edit the project in real time?
Thanks
When you build a unique jar for your own code, it will not include the classes from the other jar. If you want other people to run your program, they will either need that jar themselves, or you will have to distribute the additional jar with your own jar (assuming that's allowed).
You could unpack the jar on which you are dependent and put it in your own jar, but this is unusual and not recommended. If the people who wrote that code corrected bugs and distributed a new jar, people who got their new jar would get the fixes and improvements, but not people who were using your packed version unless you distributed a new one.
I have no idea what your last question means...
You can certainly have one project depend on another, which sounds like what you mean by "can I import as a library an open project wihout having to compile it into a jar and be able to edit the project in real time?".
To share the jars from the library project, go to the "Order and Export" tab in the Build Path dialog, and tick the jars you want to make available.
If I have an environment variable named JAR_FILES with a semicolon separated list of jar files, is there a way to have Netbeans to automatically add all of these jar files to my project libraries so that I do not have to manually add each one? I ask because there are many and they are not in the same directory.
The only thing I can think of is to manually edit some of the build scripts (such as build.xml or those in nbproject), but I am assuming these may get overwritten by the IDE.
Why not use your own Global Library? You can create a new one using the Library Manager (Tools->Libraries), you can add the required jars to it and then have all your projects use the same global library.