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.
Related
I deleted my project permanently and I want to import my old executing .jar into eclipse.
Eclipse import function does not find anything it the jar file.
Can someone give me a tip or recover the file?
Here is a screenshot of eclipse
Thank you
Click here for the file to recover
You cannot recover the project. You did not set to export source files while exporting, there are only .class files.
For future reference select Export Java source file and resources while exporting the project.
Reference: http://www.albany.edu/faculty/jmower/geog/gog692/ImportExportJARFiles.htm
I am curious to know if it's jar why do you want to import as a project?
You can import external jar as a "APP Client Jar File" which is under Java EE.
I tried this with your attached jar and I am able to import it and able to see the content in it.
You are mixing a few things. If you deleted your project source you won't be able to recover it unless you decompile it, and it will be obfuscated even though.
What you have is the compiled project, resulting from taking your source (.java) and compiling it to .class files.
The Import option in Eclipse is made for importing .project files, that hold your project's information. Also you could create a new project from your existing code but as far as I know you just can't create/recover a project from it's compiled jar.
I'm trying to add http://www.json.org/java/ to my java project as a module on IntelliJ. I cloned the source code from the git repo on this link, and I put the folder with all of the component .java files on my desktop.
When I try to add this as a module in Intellij, it allows me to, and the files show up but I cannot import them or do anything with them. Can someone shed some light on the proper procedure on how to attach these .java files to my project?
Probably it is because the .java files are not recognized as source files but regarded as any file.
I suggest, you create a module in IntelliJ first, and move these files to the source directory of the new module.
Create a new module by clicking File -> New -> Module -> Java
Give it a name such as json-java
Clone from git repo directly into the new module's source folder. (json-java/src by default). IntelliJ should now recognize them properly as source files.
This should allow your java project to import the .java files.
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
I read this article which shows how to import/export projects in Eclipse (although it seems a little outdated and I'm using 3.7 Indigo).
To export a project, you go to File >> Export and it creates some kind of "project archive" file on the local file system. You could then email it to someone else, who could then import the archive as a new project or into an existing project.
But what if you don't have an "archive" file to begin with?!? What if you just have the project files and directories but without all the Eclipse-metatdata (.project file, etc.)? Is there anyway to tell Eclipse to look at, say:
/home/myuser/some/path/to/project/root/
src/main/java
SomeObject.java
build.xml
...and get it to read that as a new Java project?
Try the steps below:
Create a Java Project in Eclipse as below:
Load the project contents from your file system as below:
Hope this works for you.
.project and .classpath files are the base of the project structure. Without a .project file Eclipse won't recognize your project. The .classpath is important too but that one changes between environments. Should you use the files from another environment you'll have to reconfigure some settings.
Rather than emailing code, I suggest you use a Version Control system and, also, some Eclipse plugins. SVN + Subclipse for example.
If you trully want to send the project to another person just send him the project's folder and import it as an existing project by doing right click on the project explorer and selecting Import > Existing Project into workspace.
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