How to reuse classes with static methods as libraries, in Java? [duplicate] - java

I have Tapjoy sources sources, which have such sructure: Tapjoy/src/com/tapjoy/*.class
It must be compiled with Android API Level 9 and higher.
My project is in version Android API Level 8.
So I need to make from sources of Tapjoy -> tapjoy.jar file and include it to my main project.
How can I make .jar file properly with command line or from eclipse?

In Eclipse IDE, it's very easy to create a JAR file.
Just right click on your package > Export > Java > JAR File (and follow the wizard!)

Or from command line
jar cvf tapjoy.jar Tapjoy.class

both are possible
you can also use ant or maven for this kind of functionality.
check for the jar tool for commandline approach!
check eclipse ant build for eclipse approach and check the ant jar task for ant approach

In Netbeans IDE, you can easy create own jar library,
Projects on Right click -> Clean and build
Thats it. You can use it now your "Project Location"/dist/MyApplication.jar
All you need to do create new project and import your jar file How to import Jar File ?

Related

How to export a java project from eclipse that contains all libraries required to compile?

For a project I completed a game in Java on Eclipse using LibGDX. I now need to turn in the source code to my professor. When I export the project and try opening it on a new computer, about a dozen libraries are missing.
I would like to export my entire project so that when the project is opened in eclipse, it will still compile. Is there any way to do this? I know that runnable jars come with the .jar files of the dependencies and no source code, but I need both.
Thanks in advance
Libgdx required number of dependent jars so it's hard to manually add all jars into project.
Make your project gradle based so that When you import your project through gradle into another System then gradle do most of your task* for you.
*gradle try to find dependent jars in file system if already exist then link with your project if not then it download from given repository and link them in your project. Make sure your system is connected with internet when you build your project.
I highly encourage to use Android Studio or IntelliJIDEA.
On window, by default all jars are stored inside
C:\Users\User_name\.gradle\caches\modules-2\files-2.1
In Mac OSX
/Users/User_name/.gradle/caches/modules-2/files-2.1
When you want to deploy or packaging for the desktop run this command on your IDE terminal.
gradlew desktop:dist
You can use maven or gradle to build your project, take a look of one of the tool and it's won't take you too much time. these tool could help you define your own way for build
A much easier way you could use "fat jar". this is an old tool for build a jar with all lib you need and could be run in any place.

Eclipse Java Build Path Jar Library classes not found even if available in jar

Recently I wanted to add the nebula shelf to my eclipse plugin. Therefore I added the org.eclipse.nebula.widgets.pshelf.source_1.1.0.201701302244.jar the build path of my eclipse project.
Sadly eclipse can't find the class files inside of the jar, even after cleaning and rebuilding the whole project.
Picture:
Checking the same jar file with jd-gui results in:
Picture:
I exported the *.java files with jd-gui and copied them to my project. Using this method my project built successfully and worked as expected.
Can someone tell me how I can use the jar file without exporting all of the java files manually? Thanks for your help! :-)
Do not use source jars. You can tell eclipse while debugging to use the source jar.
Add the jar to build path: right click on jar -> build path -> add to build path
Don't try to add Eclipse plugins directly to the build path of another plugin as it won't work.
Instead add the plugin to your target platform or import it in to your workspace.
Then add the plugin to your plugin's Dependencies. In the MANIFEST.MF editor you do this on the 'Dependencies' tab in the 'Required Plug-ins' list.

Create a single jar that will contain compiled classes and javadoc without Maven

When I build a jar with Eclipse, sometime I'd like to include source or JavaDoc with the .class files in a single .jar file. I found how to do that with Maven. Is it possible to do it just using Eclipse?
TIA,
You can import a maven project into Eclipse. That's one way. Just import your maven project and perform the maven steps you do to create you jar file.
You can also export a Java project, which includes the sources and all that you mentioned using Eclipse under the File -> Export option. You will see a wizard that allows you to choose the target (war, jar, ear, ...) and the resources that should be included.
Mode details: http://www.codejava.net/ides/eclipse/how-to-create-jar-file-in-eclipse

Java executable

I am creating an executable jar file for my program in java.
The program uses jtds.1.2.jar and javacsv-2.0.jar.
Is it possible to include the external jars when I create my executable jar file??
Please help.
Thank you.
Try this, this is the way to create a jar or runnable jar in eclipse, all your external libraries in the project will be included
File -> Export-> Java ->Runnbale JAR file
Launch configuration : your Class containing the public static void main(String[] args)
Export destination : Target place
Library Handling:
Package required libraries into generated JAR
FINISH
Yes it is possible.
You may use eclipse export jar function doing this
Sure it's possible! Just add the classes of the Jars to your Jar!
You can either do this by hand (unsuggested), or any build tools like Ant ( target) and Maven (search for shading plugin) can do that for you.
If you don't want to bother creating any scripts, just use the IDE to do it for you (newer Eclipse versions have a checkbox for including libraries automatically, for older ones just install a plugin that does the job for you automatically, like the FatJar plugin).
It's possible to create a folder structure like this
main directory:
your_app.jar
subdirectory:
other jar files
Then add the dependencies to your jarfile's manifest and "zip" the whole thing together, to move it to the computer where you want it to be. Netbeans, for example, supports this kind of deployment.
For a more general / "foolproof" solution, you will have to create a setup program.

How to distribute java project built in Eclipse?

Till now, I have been using Netbeans IDE for Java Applications. To distribute applications made in Netbeans, I just click on clean and build and it packs the application in .jar file which resides in a dist directory.
Now I have made a java project in Eclipse. Is Eclipse has any functionality similar to clean and build functionality of Netbeans by which we can pack java applications to distribute them.
You can right-click the project, select Export and choose Java, then JAR as the format.
File -> Export...
And choose Java -> JAR File. You will get a wizard to export any of your projects
Yes it has a clean and build functionality.
clean which clean all the developed a classes from the specified location
build which builds the class files at the same specified location respectively.
To distribute a project as a jar then you have to right click on the project and select export and in that select as jar.
Eclipse has a function to export the whole thing as a exetutable jar. It is under file>export.

Categories