jar file not working for imports in Eclipse - eclipse

I am following a tutorial from AndroidHive on how to login to Twitter from my app.
The tutorial uses the twitter4j library, so I download it from here and save the zip file to my desktop. In my project I drag the twitter4j zip file into my projects libs folder. Then I Refactor -> Rename the file from a zip to a jar (only changing the extension)
However, when I want to import the classes into my project, it does not seem to be working. I try to do
import twitter4j.Twitter;
But this option is not available. See screen grab.
Can anyone please tell me where I am going wrong with this?
Also, as per the tutorial I have also just added the twitter4j-core file to the project but still imports wont seem to work.

The tutorial clearly says "Download and Extract" That does not mean "Download and Rename". It means download the file and then Use a file compress/uncompress utility to extract the zipped files format. Search in the extracted files to find the relevant jar file and import that file.
1. Download & extract twitter4j library from twitter4j-android-2.2.6.zip (slimmed version for Android platform). Here is the direct link
If you uncompressed correctly then do the following
Right sure that the folder where you copied the twitter library shows up in the Lib path for the project. Right click on the project --> Select 'Properties' ---> Select 'Java Build Path' From the Left hand Menu ---> Select Libraries Tab. Review List of Libraries(expand if needed ) to see if the twitter jar files show up here.
If not Select 'Add Jar' browse to the Jar file. Add it. Refresh your project. Clean it and build. You should now be able to import twitter components.

Related

Download ZIP file from GitHub and import in eclipse

Why every project that I download as a zip file from Github i can't import in Eclipse?
This is how I try it...
Of course, firtst I download it as a ZIP. (download it to desctop, for example)
Then, import existing project...
But then even if there is a project for sure, and special this project, it shows me warning "No projects are found for import" like this:
This is problem for every project that I try to import like this. Is there any other way to import projects or...?
(I repet this project work 100% on my friends laptop, but I can't even import it)
Make sure you have uncompress the zip archived first.
Then check the content of the folder where you uncompressed the zip file.
If there is no .project file, do create a new project in Eclipse, and point the sources to that folder, instead of trying to import it.
See "How to import a java project missing .project .settings .classpath files into eclipse".
maybe you can see the following:
you have to select the folder where the project is created.
you are sure that is a project, maybe are only the files
Pls attach the link of git to check this.
Regards.
I was trying to do the same for GitHub download project. I figured out that if this is a maven project then you will not find these .project files. So instead of using import -> Existing project to Workspace use Existing Maven Project.
I imported zip file in my STS , first of all i click on import project then click on General import some menu showed up enter image description here , then click on Projects from Folder or Archive , then choose from Archive file click finish enter image description here

Facing issue after importing project into eclipse

I am downloading the source code, which is in zip form. When I unzip the folder using Peazip and import it into eclipse, I don't find any contents in the project. Please provide solution for this
You have to map the source folder to your project.
Right click on your project and click project. Add link to source folder.
Now you can see the source code of your project.

Eclipse jar file is not exported with project

I have a simple project that I need to be very easily imported into eclipse and started. When I export my project and import it again it comes with an error saying it is missing a required jar file. This jar file is added to the build path, but does not carry over when the project is exported. Why is this? I have been searching all day for an answer on Google and none have helped.
Would I just have to send the jar file along with the project and have the users manually add it?
Things I have tried:
Going into build path order and export and clicking the jar file.
using a clean workspace for the import / restarting eclipse.
For anyone with a future problem like this one. I was putting the jar in the lib folder and also adding it to my build path, but the jar would not export over. When I added the jar to the WEB-INF / lib folder it successfully carried over with the export.
You may want to try this:
Right click on the imported project select Build Path -> Configure Build Path -> Java build Path -> Libraries Tab and check if the jar file which eclipse says missing is present in the Libraries tab.
If it is present then select it and click Edit, a "File dialog" will pop up, find the desired jar which is in your computer's directory. and click Ok then wait for eclipse to build
the workspace. If it is not present then add it through Add JARs... or Add External JARs...
Export it as an Archive file of the project rather than a jar. Then it's just a matter of someone else importing it as an Existing Project. Exporting it as a jar is only something you do when you want to deploy the jar and run it.

Import Libraries in Eclipse?

I just recently downloaded the dom4j library, but for the life of me I have no idea how to access it. I dropped it in the plug-ins folder and rebooted Eclipse, without success. For some reason finding a straight answer for this is more difficult that I thought it would be.
No, don't do it that way.
From your Eclipse workspace, right click your project on the left pane -> Properties -> Java Build Path -> Add Jars -> add your jars here.
Tadaa!! :)
Extract the jar, and put it somewhere in your Java project (usually under a "lib" subdirectory).
Right click the project, open its preferences, go for Java build path, and then the Libraries tab. You can add the library there with "add a jar".
If your jar is not open source, you may want to store it elsewhere and connect to it as an external jar.
For the Android library projects, I do it as in the attached screenshot:
Right click the project, select Properties->Android and in the library section click Add. From here you can select the available libraries.
If you are importing a jar file, then importing them as jar or external jar, as other posters posted would work. I prefer to copy/paste jar file in the libs folder (create one if it doesn't exist) and then import as jar.
If you want to get this library into your library and use it, follow these steps:
You can create a new folder within Eclipse by right-clicking on your project, and selecting New Folder. The library folder is traditionally called lib.
Drag and drop your jar folder into the new lib folder, and when prompted select Copy Files.
Selecting the Project tab at the top of the screen, and click Properties.
Select Java Build Path followed by the Libraries tab.
Click the Add JARs… button and select your JAR file from within the lib folder.
Your JAR file will now appear in both the lib and Referenced Libraries folders. You can explore the JAR's resources by clicking Referenced Libraries.

How do I open the GWT samples in eclipse Helios and GWT 2.1.1?

What is the straight-forward way of importing one of the GWT samples in eclipse Helios + GWT 2.1.1. It seems like the content of the zip file doesn't contain any project files for eclipse.
I tried the following:
create a GWT project 'bla'
Delete the src ad war folder and
replace it with the src and war
folder from the sample
refresh the project in eclipse
hit 'run'
[ERROR] Unable to find
'bla/bla.gwt.xml' on
your classpath; could be a typo, or
maybe you forgot to include a
classpath entry for source?
So I go to the run configuration and remove the path for the example projects from the arguments list. I also changed the name of hosted html page to the one in the sample. Hit 'run' and:
[ERROR] Invalid version number "2.0"
passed to external.gwtOnLoad(),
expected "2.1"; your hosted mode
bootstrap file may be out of date;
Now I need an out of date version of GWT to run these samples? What is going on, I just want to look at a sample to learn a new concept.
Reading the readme.txt in the GWT samples directory I came across a solution that works on Eclipse 3.7. Assuming you have ant installed on your machine, execute the following from the sample's directory:
ant eclipse.generate
This will generate both the .classpath and .project files needed to import the sample into Eclipse and run it.
Here the relevant excerpt from README.txt:
-- Option A: Import your project into Eclipse (recommended) --
If you use Eclipse, you can simply import the generated project into
Eclipse. We've tested against Eclipse 3.4 and 3.5. Later versions
will likely also work, earlier versions may not.
If the directory containing this file does not have a .classpath or
.project file, generate them by running 'ant eclipse.generate'
In Eclipse, go to the File menu and choose:
File -> Import... -> Existing Projects into Workspace
Browse to the directory containing this file, select "Mail".
Be sure to uncheck "Copy projects into workspace" if it is checked.
Click Finish. You can now browse the project in Eclipse.
To launch your web app in GWT development mode, go to the Run menu and
choose:
Run -> Open Debug Dialog...
Under Java Application, you should find a launch configuration
named "Mail". Select and click "Debug".
You can now use the built-in debugger to debug your web app in
development mode.
In eclipse 3.7, instead of Run -> Open Debug Dialog..., its Run -> Debug Configurations. I got both the showcase and mail samples running following those commands. Should work for all of the other samples as well.
The examples that come with GWT SDK were built in different ways. Some are Maven builds, others use Ant. Eclipse can handle these common builds directly, but you have to choose the right option.
So, if you want to open the Expenses project in eclipse, you would look in the projects root directory (i.e. ../gwt2.4/samples/Expenses) where you'll find a file called pom.xml. That is a Maven build file. To import it into your Work space select:
File->Import...
Open Maven->Existing Maven Projects, and click on Next > button
Browse your file system til you reach the Expenses folder. Click on it and Select OK.
At this point it will show you the Projects in that directory in the Projects: area of the window...only one in this case: /pom.xml com.google.gwt.sample.expenses:...etc.
click on the checkbox for that project, Next>
Finally, it ask you to map plugins. You'll need to select in the drop down menu under Actions the required plugins (such as m2e).
In other project folders you may find a build.xml file instead. That's an Ant build file. To import that you do something similar, but different (of course!):
File->New->Project...
Open the Java folder and select "Java Project from Existing Ant Buildfile", Next >
Click the Browse button, dig through your directory to the project folder and select the build.xml file, and Open it.
Project name should fill in automatically, just select the declaration to use in the middle window and click Finish.
Since those tutorial only include the src and war directory, the idea remains to:
create a new project following this tutorial
remove any created class part of the example files which are automatically added (see Issue 1547)
Unfortunately the Google Plugin does not allow to created a new Web Application Project without creating template files. The template files are nice for the first try but annoying if you want to start from scratch with a new GWT application.
copy the src and war directory in place within the now empty project
Following your ticket 5847 (No easy and straight-forward way to make examples work in eclipse),
as xo4yhamope comments, you need the right GWT option.
and did you consider the Issue 5038 about the error message:
Unable to find 'xxxx.gwt.xml' on your classpath;
could be a typo, or maybe you forgot to include a classpath entry for source?
This message usually means you attempted to refresh the browser before dev mode has had a chance to finish loading the module.
The uppercase/lowercase confusion happens because the module has been renamed to 'stockwatcher', but dev mode cannot map 'stockwatcher' to "StockWatcher' until it has finished loading the entire module.
So, it's just a matter of waiting a few seconds longer after the Development Mode pane says I should go to http://127.0.0.1:8888/StockWatcher.html?gwt.codesvr=127.0.0.1:9997 ?
That seems a little messed up. It should wait until it's actually ready before telling me it's ok, because users (like me) are going to go there as soon as the UI says it's ready.
The other confusing part is that the server begins serving the host page as soon as that message in the UI comes up. Because this was happening, I assumed that the server was completely up, even though (as it turns out) it wasn't.
Anyway, waiting a few more seconds seems to resolve the "Unable to find 'stockwatcher.gwt.xml' on your classpath" problem. Thanks!
I'm beginning to suspect this is a bug in the samples. I am adding this answer so it can be marked as an answer when I get confirmation about that.
I was trying out some other samples and came across this page. At the top is a little explanation for how to download and import the sample.
Before you begin
The StockWatcher project
This tutorial builds on the GWT
concepts and the StockWatcher
application created in the Build a
Sample GWT Application tutorial.
If you have not completed the Build a
Sample GWT Application tutorial and
are familiar with basic GWT concepts,
you can import the StockWatcher
project as coded to this point.
Download the StockWatcher project.
Unzip the file.
Import the project into Eclipse
From the File menu, select the Import... menu option.
Select the import source General > Existing Projects into
Workspace. Click the Next button.
For the root directory, browse to and select the StockWatcher
directory (from the unzipped file).
Click the Finish button.
If you are using ant, edit the
gwt.sdk property in
StockWatcher/build.xml to point to
where you unzipped GWT.
Now this is what I call straight-forward and easy.
At that point I had already built the StockWatcher in a previous tutorial but I got intrigued by the fact that it was explained exactly as I tried it the first time. So I downloaded the project and it had the correct eclipse project structure. I tried to import it 'et voila' I have the project in eclipse. I runs out of the box (with warnings). That is how expected the samples to be.
This experience leads me into thinking that the sample projects are malformed (as eclipse projects) and need to be updated. Let's hope my issue report leads to results.
-- Option A: Import your project into Eclipse (recommended) --
If you use Eclipse, you can simply import the generated project into Eclipse.
We've tested against Eclipse 3.4 and 3.5. Later versions will likely also
work, earlier versions may not.
If the directory containing this file does not have a .classpath or .project
file, generate them by running 'ant eclipse.generate'
In Eclipse, go to the File menu and choose:
File -> Import... -> Existing Projects into Workspace
Browse to the directory containing this file,
select "Mail".
Be sure to uncheck "Copy projects into workspace" if it is checked.
Click Finish.
You can now browse the project in Eclipse.
Copy from readme.txt supplied by samples. I tried this method, it's OK.
To import GWT showcase(2.5.1) I did following steps:
Create a new Google Web Application Project
New –> Other –> Google –> Web Application Project
Provide the project name “Showcase” and the Package name is com.google.gwt.sample.showcase
Click Finish
Go to eclipse plugin folder and traverse to the gwt
Under that folder go to gwt-2.3.\samples\Showcase
Copy (Ctrl C) all the contents. The contents are
a. src
b. test
c. war
d. build.xml
e. README.txt
In the eclipse, right click on the Showcase project and paste. Overwrite all the files
The files should start copying without any problem
Right click on the Showcase and Run As “Web Application”
You should have your Showcase working like Gem!
For me it worked like a charm ;)
Ref : http://simplestepswebdev.wordpress.com/2011/05/16/import-gwt-samples-into-eclipse/