I have a .jar on my desktop that my friend coded. I ahve opened the .jar in winrar to get all the .class files and things like that for it. How would i add them to a package in Eclipse.
If this is not possible is there anyway i can just open a .project file?
Thanks.
In your place, I would just copy the .jar as is somewhere in your project and add it as a dependency by:
Right-click on project -> Project properties -> Java Build Path -> Libraries -> Add JARs...
That way you can build new code depending on your friend's code.
I assume you are just beginning with Java or Eclipse, when you feel yourself more comfortable you may be interested in learning dependency management with automated tools as Ivy, Maven or Gradle
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
http://www.gradle.org/docs/current/userguide/dependency_management.html
http://ant.apache.org/ivy/history/latest-milestone/reference.html
project -> properties -> java build path -> libraries -> add external jars
I hope that will work
If you want to decompile your .class and use it as code, you can look at this question
How do I "decompile" Java class files?
Supposing that jar is a library you want to use, import It into your project root then go to build path and select import jar to link to it
Related
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.
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 ?
I got a .jar file which I need to import into Eclipse. However, I don't want to have the jar as a referenced library. I need the .jar to be included like a "normal" project, with packages(!) and .java files.
I tried to do the following:
New Java project -> Import -> General -> Archive File. In this case, when I place this jar also as a referenced library, it is imported but with .class files.
New Java Project -> Import -> General -> File System. Imports the .java files, but the packages are lost and are normal folders. Also, the files are somehow strange, because the "j" in the icon looks differently, and errors are not noticed (no underlining)
Importing "Existing Projects into Workspace" doesn't work at all, it says that there is no project. I also tried to import the jar as a zip after extracting it, this gives me the -java files, but it destroys the packages.
Does anyone know how to import this correctly?
I have managed it this way:
New Java Project -> Java settings -> Source -> Link source (Source folder). There I added my decompiled jar and it was imported correctly :)
You can also create a new Java Project and then do File -> Import -> General -> Archive File. This will save you a step of unzipping your jar and adding as a linked source folder.
You cannot import a jar that way, unless it has the source code packed in the jar. If you really need the source code, you'll have to find an archive somewhere. But of course, not everyone is willing to share his source...
I tried the below and it worked.
Create a New Java Project
Goto File > Import > General > Archive File
Select the required Archive file(.jar in this case) from your local system.
Select the project you created in Step 1 and click Ok
This will save you a step of unzipping your jar but if there are .class files, eclipse won't convert them to .java files. This has to be done seperately.
Below helps in all recent eclipse.
Please try below eclipse plugin to import jar as project :
Step 1) Eclipse Help > Eclipse Marketplace
Step 2) Install the plugin "Import Jar As Project"
Step 3) Restart Eclipse
Step 4) File->Import->Other->Jar without source
Step 5) Select a jar/war file and click finish
New project will be created from the jar
https://marketplace.eclipse.org/content/import-jar-project
Thank You.
How to include (NOT ONLY reference) JAR file into existing project? I added it by using Project properties - Build path - add external jar's. But when I export my project, and then import it in another computer, this library was missing.
Drag it into your project view so it appears in the project as any other file.
Right-click the jar in the project view and add to build path.
Put your jars into a directory of your project e.g yourproject/lib so that external libraries are accessed through a relative path. And then use "Add JARs" option to add the jar to build path as in eboix's link.
You want to export your project as an archive (Export -> General -> Archive File), and then import your project as an existing project (Import -> General -> Existing Projects into Workspace). This way the project will be identical to the exported version and all of the configuration will be right.
Oh, and do what the other people suggest and copy the Jar file into the project so you don't have to reference it as an external Jar file (and everything is in one place).
I am now going to use the .jar file on http://code.google.com/p/google-api-translate-java/. However, after I download it, I tried to import it in my current project folder (in Eclipse)
the two import statements
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
always get complained by the compiler saying couln't find such class
Could any one help on how to correctly import this .jar file into a project in Eclipse?
You need to add it to your build path. Right-click on the project in Project View, select Build Path->Configure Build Path, then Libraries tab. Now, use one of available options there to add a JAR.
Use "Add JAR" if you copied the jar to your project folder or "Add External JARs" to add it by poiting to a path in filesystem. (Anyway, it is better to copy the jar to the project folder, in which you want to use the jar).
HTH
see How to import class into existing Java project, with Eclipse
Copy the google-api-translate-java-0.92.jar file to your project /WEB-INF/lib/ folder and refresh your project (right click on project and select "refresh").
Google Translate API v1 is deprectaed and will shutdown soon.
You can use Google Translate API v2 Java. It has a core module that you can call from your Java code and also a command line interface module.
Hy I have faced the same issue and fixed it
Step1: download google-translate-api jar file
step2: paste into your app library file
step3: Goto project structure > app > select dependencies -> then add path of your jar file...
Enjoy now you can acess google api services