Setting up MySQL connector in Java [duplicate] - java

How do I import a jar in Eclipse?

You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar. A quick demo here.
The above solution is obviously a "Quick" one. However, if you are working on a project where you need to commit files to the source control repository, I would recommend adding Jar files to a dedicated library folder within your source control repository and referencing few or all of them as mentioned above.

Adding external Jar is not smart in case you want to change the project location in filesystem.
The best way is to add the jar to build path so your project will compile if exported:
Create a folder called lib in your project folder.
copy to this folder all the jar files you need.
Refresh your project in eclipse.
Select all the jar files, then right click on one of them and select Build Path -> Add to Build Path

Two choices:
1/ From the project:
2/ If you have already other jar imported, from the directory "References Libraries":
Both will lead you to this screen where you can mange your libraries:

Here are the steps:
click File > Import. The Import window opens.
Under Select an import source, click J2EE > App Client JAR file.
Click Next.
In the Application Client file field, enter the location and name of the application client JAR file that you want to import. You can click the Browse button to select the JAR file from the file system.
In the Application Client project field, type a new project name or select an application client project from the drop-down list. If you type a new name in this field, the application client project will be created based on the version of the application client JAR file, and it will use the default location.
In the Target runtime drop-down list, select the application server that you want to target for your development. This selection affects the run time settings by modifying the class path entries for the project.
If you want to add the new module to an enterprise application project, select the Add project to an EAR check box and then select an existing enterprise application project from the list or create a new one by clicking New.
Note: If you type a new enterprise application project name, the enterprise application project will be created in the default location with the lowest compatible J2EE version based on the version of the project being created. If you want to specify a different version or a different location for the enterprise application, you must use the New Enterprise Application Project wizard.
Click Finish to import the application client JAR file.

Just a comment on importing jars into Eclipse (plug-in development) projects:
In case you are developing Eclipse plug-ins, it makes sense to use Eclipse's native bundling mechanism instead of just importing the jar into a plug-in project. Eclipse (or better its underlying OSGi runtime, Equinox) uses so-called bundles which contain some more information than plain jars (e.g., version infos, dependencies to other bundles, exported packages; see the MANIFEST.MF file). Because of this information, OSGi bundles can be dynamically loaded/unloaded and there is automatic dependency resolution available in an OSGi/Eclipse runtime. Hence, using OSGi bundles instead of plain jars (contained inside another OSGi bundle) has some advantages.
(BTW: Eclipse plug-ins are the same thing as OSGi bundles.)
There is a good chance that somebody already bundled a certain (3rd party) library as an OSGi bundle. You might want to take a look at the following bundle repositories:
http://www.springsource.com/repository/app/
http://download.eclipse.org/tools/orbit/downloads/
http://www.osgi.org/Repository/HomePage

Eclipse -> Preferences -> Java -> Build Path -> User Libraries -> New(Name it) -> Add external Jars
(I recommend dragging your new libraries into the eclipse folder before any of these steps to keep everything together, that way if you reinstall Eclipse or your OS you won't have to rwlink anything except the JDK) Now select the jar files you want. Click OK.
Right click on your project and choose Build Path -> Add Library
FYI just code and then right click and Source->Organize Imports

Jar File in the system path is:
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar
ojdbc14.jar(it's jar file)
To import jar file in your Eclipse IDE, follow the steps given below.
Right-click on your project
Select Build Path
Click on Configure Build Path
Click on Libraries, select Modulepath and select Add External JARs
Select the jar file from the required folder
Click and Apply and Ok

first of all you will go to your project what you are created
and next right click in your mouse and select properties in the bottom
and select build in path in the left corner and add external jar file add click apply .that's it

In eclipse I included a compressed jar file i.e. zip file. Eclipse allowed me to add this zip file as an external jar but when I tried to access the classes in the jar they weren't showing up.
After a lot of trial and error I found that using a zip format doesn't work. When I added a jar file then it worked for me.

Right Click on the Project.
Click on Build Path.
Click On Configure Build Path.
Under Libraries, Click on Add Jar or Add External Jar.

If you are having a trouble on udemy course of chad on springboot for the importing the jar. Then follow these steps.
Right click on the project.
You will see a option of Build Path, click on it.
You will have a option of Configure Build path, click on it.
Go to libraries.
Then go to the place where you have a jar files make them into a new folder and upload on a new place.
Then click on Add External Jars, you will surely be able to upload it which will help on classpathxmlapplicationcontext as well.
Thank you.

Related

How can I include other downloaded packages in eclipse

I've found Javaluator, and it looks like something I'd like to use in my java project. When I go to the downloads page, there are 2 options, maven or a zip folder containing lots of .JAR files. I'm very new to eclipse and java programming as a whole, and was wondering how I could sort of "Import" or include them in my project. Any help appriciated, thanks!
Follow the below steps to add externally downloaded java packages(JAR) file to an Eclipse Project.
Right click on your project.
Select Build Path.
Click on Configure Build Path.
Click on Libraries and select Add External JARs.
Select the jar file from the required folder.
Click and Apply and Ok.
All done.

jars are not automatically deploy in tomcat using eclipse keplar

Till now we are using myeclipse to for development.
Now we started development using eclipse keplar.
My first problem is jars are not deployed in webapps lib directory
which we solved by referring [link] Adding 3rd party jars to WEB-INF/lib automatically using Eclipse/Tomcat
but every time if want to add third party jar's dependency then we have to add in build path and Deployment Assembly
so please let me know if there is any workaround to add entry only in build path and this jar is automatically deployed in tomcat directory.
Thanks in advance.
Suppose here we have an example to add an external jar using eclipse kepler:
suppose we have have a project here RIGHT-CLICK on it and select its PROPERTIES...
Then click on JAVA-BUILD-PATH..
click on LIBRARIES tab and click on ADD-EXTERNAL-JARS...
now select whatever you want to add an external jar or API and click ok
after taht you will see on libraries CONGRATS you have successfully added a jar file..
go to Run > Run Configuration create a configuration node if there isn't any, go to the Classpath tab and add whatever you want: Projects, JARs, External JARs, then they would be deployed, when you run your tomcat.
Darshan,
As you have added a "myeclipse" tag, I guess you are using MyEclipse. In this case, just use the deployment assembly to add dependencies, whether it is another project or an external jar file. When added this way, it will automatically be added to the build path (you will see it in the "Web App Libraries" container in the Package Explorer, under the project).
The MyEclipse developers are looking at the possibility of synchronizing the deployment assembly when adding to the build path directly but it's not clear that this is possible. So, just use the deployment assembly, in future, for adding dependencies to web projects.

How to add all external jars to library on eclipse export to war

Now that i've been doing some research I understand that I need to be placing my dependent external jars in the web-inf/lib folder for a dynamic web project in eclipse. Unfortunately until now I have simply been importing them in on the build path within eclipse and then again in the runtime config for my testing server.
Is there a simple way to copy all of the dependent jars to the web-inf/lib folder upon export or do I have to manually find each one, and place it in the folder? Is there a better way to manage external jars during development so I don't have to be concerned with importing them to the build path, and then the runtime, and then the library folder? I've tried using Project >> Properties >> Java Build Path >> Order and Export and checking all the jars, but they still don't seem to export with the war.
I am using tomcat as my production server and figured all of this out when I couldn't start the project due to defclassnotfounderror's in the log file.
Right Click on the project -> properties. On properties window
select "Deployment Assembly" on the left hand side
Click "add"
select "Java Build Path Entries".
Select all the required libraries
Right Click on the project -> export. Select Web -> .war file.
You will find the libraries under /WEB-INF/lib
In the future you should always create a copy of your depencies in the web-inf/lib folder.
When they are there just right click them and select "Build Path -> Add to Build Path".
For your current project I would disable all current external jars that live outside of that folder and then copy them into it.

Eclipse IDE- Add jar? Add External jar? Add Library?

I want to integrate TwitterAPIME to my Blackberry project. I have 3 Jar files provided by TwitterAPIME. I am not sure how to link these 3 Jar files to my project.
My basic doubts are
What is an External Jar ? What is a Library ?
What's the difference between Adding jar, Adding External jar or Adding Library ?
What is an External JAR?
External as the name suggest is a Jar file that is not built by the currently developing code. It is a utility Jar file that is added externally for extra features. It could be an API Jar file provided from the external site, just as in your case the 3 Jar files will be going to call External Jar Files.
To add an External Jar file in Eclipse, follow these steps: Right Click on Project -> Select Build Path -> Select Configure Build Path -> Library Tab in the following Dialog box.
What is a Library?
A Library is a in-built Jar file from the JDK Directory or any other software e.g. J2ME-Polish as you can see in the Image above. Normally these Library files are developed by a manufacturer.
What's the difference between adding JAR, Adding External JAR, and Adding Library?
Adding Jar File: When you have more than one project in Eclipse and you add another project's Jar file, that is called adding Jar File. There is a first Button in the Photo above, it only allows you to add Jar file from the other Project.
Adding External Jar: When you add any API Jar file provided by the site or another manufacturer. In your case the 3 Jar files are External Jar Files. You can add then by using second Button "Add External JARs".
Adding A Library: Clicking on the 4th Button will open a dialog box as below.
You can add different libraries installed on your system. You can also add your own Library, by selecting "User Library".
JAR: A JAR File in your workspace.
External JAR: A JAR File in your file system. Use it for test purposes only, otherwise your project would be quite untidy.
Library: Built-in libraries such as JUnit. You don't need to know their location, these come with Eclipse.
In addition to the excellent answer given above by Lucifer, I recommend that people looking to develop or use Libraries, review the following BB supplied KB article:
Working with Libraries - shared, bundled, releasing, and using 3rd Party SDKs
Where the API is available as source or a Jar, I have found it significantly easier to include the source directly in the application. For example, in this case, rather than include the TwitterAPIME jar, you could include the TwitterAPIME source as a separate project in the application. As well as being easier to build, this can help in debugging or at least understanding issues with the API.
You might also find this sample, and in fact the containing Thread, useful:
Twitter + Facebook Sample Integration
Also building on Lucifer's answer, I have used "User Libraries" to bundle jars that are used across projects and dependent on a 3rd party service. Specifically, in my case, JMS jars. If I upgrade to a new JMS, or a different provider, etc, I can simply change the jars in my User Library and all projects referencing this are updated. Rather than changing jar dependency in every project.
An external Jar is a Jar in a path outh of your Eclipse environment: i.e. outside of both Eclipse jars and projects generated jars.
A libraray is a collection of jars prepared by someone for you.
You can cerate a User Library by selecting a group of external jars: that is useful if you have a group o jars that should logically work togehter.
A further advantage of creating a library is that you can "reuse it's definition" by referencing it in multiple projects.
Use:
Project->Properties->Add library-> select "User library" and press Next->User libraries->New
insert a new name and later us "Add Jar" that adds any jar you need to you library definition.
Later use this library in your project.
Sometimes adding jars directly in the blackberry project might cause some build problems. Here 's a solution that works (90%):
You have your blackberry project. Now create a new simple Java Project.
Right-click on it > Properties > Java Build Path and choose Libraries tab and click on Add External Jars to add the 3 jars that are in your system and you want to use. Then OK.
Now go back to your blackberry project and Right-click on it > Properties > Java Build Path and click on the Projects tab, click on Add and select the project you just created and OK.
Now go back and build your Blackberry project.
I hope this help.
If you add the JAR within the Eclipse workspace, say /myproject/WebRoot/WEB-INF/lib but Eclipse does not display the /lib when using the Select Jar pop-up, exit the wizard and refresh WebRoot (rtClick and take Refresh or F5): Eclipse only shows new libraries not already added to the project and usually needs a manual refresh first.

How Can I Add the Apache POI Library in and Eclipse Project?

I download the Apache POI from apache.org but don't know how use it with one of my existing project in Eclipse.
There are several ways, some good, some bad...
Add external Jar - as jjnguy says will work. However, not a good option...
The problem is that if you share your project with someone else and they have the jar in a different spot, they'll get build path errors
Add variable - similar to add external jar, but much more flexible. You can define a classpath variable (under Java prefs) that represents the dir containing jar. In your project, when you add variable, you choose the var you defined and press "extend" to specify the actual jar. As long as you and other developers of your project define the variable, you can have the jar in different spots if you like
Add the jar to your project - create a dir in your project (optional, maybe call it lib) and import the jar into it using File->Import or if your OS supports, drag it as an icon into the folder (On windows I open an explorer window and drag it from there into the folder in eclipse). Then, right-click the jar and select Build-Path->Add to build path.
Add the jar in a separate project and reference it. Add the jar as mentioned in the last bullet to a separate project for that jar. Choose Build-Path->Configure Build path from the project. Go to the "order and export" tab and make sure the jar is checked. Now you can configure your project to reference the new project. This makes things more modular.
Create a user library - under Java prefs you can define a "user library" that contains the jar. This is somewhat similar to a classpath variable, but can reference multiple jars and you only have to add it once to the project.
Create a classpath container plugin. This is more complex, but is a nice option if you are providing a set of plugins for folks. A classpath container can be added like a library to a project and it can manage the jars, even searching for them if you want it to.
You can find the option to add external jars to a project in: Project > Properties > Java Build Path > Libraries tab.
Click on 'Add External Jar' and find where you have the POI library.

Categories

Resources