How do you reuse sets of jars in an Eclipse webapp? - java

You can package up sets of jars e.g. all Hibernate dependencies into a User Library. In Eclipse if you go to Project - Properties - Java Build Path - Libraries, you can add your User Library. But in a webapp you need your jars to get copied to WEB-INF/lib. Is there any way to get Eclipse to do this automatically?

You can do what you want with the User Library.
Add the user library to project's build path.
Go to Project Properties -> Deployment Assembly -> Add -> Java Build Path Entries
Select your user lib from the list.
At this point, Eclipse will know that the contents of user lib should be packaged into your web app's WEB-INF/lib directory. Note that this will happen at deployment or export. You will not actually see these jars in your project's source WEB-INF/lib directory.
These instructions are based on Eclipse "3.6" Helios. The steps are slightly different for older releases.

Related

Setting up MySQL connector in Java [duplicate]

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.

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 a JAR to an Eclipse plugin I am developing?

I am developing an eclipse plugin. It has other plugin/feature dependencies. However I want to add my own favorite JAR/libriaries to it, like say logback for example. How can I do this so that when I eventually deploy it to an update site, it will have these jars on the classpath?
Also, I am currently using eclipse to run the plugin (it opens another instance of eclipse) to run this. This will also need to have the jar on the classpath.
You can try these steps :-
Use Import>File System to import the jar files into your plugin project, say in the /lib directory.
Use "Add..." to add the jars to the classpath section of the plugin.xml>Runtime tab.
Use "New..." to add "." library back (with no quotes, of course).
make sure your binary build exports the new jar files on the plugin.xml>Build tab.
save.
on the project, use context menu>PDE Tools>Update Classpath to correctly add the jars to the eclipse project classpath.
In plugin-manifest editor select Runtime tab and add you jar in classpath section.

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.

External jars in eclipse plug-in

I'm creating an eclipse plug-in and I'm having trouble with external jars. In my plug-in I start an application which requires some external jars. What do I have to do to export them automatically with the rest of the plug-in?
Thanks in advance :)
Open your plugin.xml
Go to Runtime tab and add your JAR in the classpath section
By following the steps below, the external JARs will be included when you export your plug-in:
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
Open the build.properties in your plug-in project and check the JARs you want to include in the build in the Binary Build section on the left.
This is an easy way, though it does create an additional plug-in.
In Eclipse:
Choose New>Other, then Plug-in Development>Plug-in from existing JAR archives.
Choose the jars you want to include.
On the next page, configure the plug-in.
In your plug-in's manifest, add the new plug-in as a dependency.
In your plug-in's Properties, add the new project under Java Build Path on the Projects tab.
Edit: You may be able to combine the jars into your plug-in by instead combining both suggestions of Zsolt and user714965 below.
This is what has worked for me. If they are truly external, and this is a project for your company that is not going to be in the "wild" and you control the environment, and you have them out on the file system say at /opt/java/lib/somedir/some.jar you can tell the bundle where to find them by adding them to the Bundle-ClassPath entry in the MANIFEST.MF under META-INF. The syntax is:
Bundle-ClassPath: .,
external:/opt/java/lib/somedir/some.jar,
external:/opt/java/lib/someotherdir/someother.jar
Also it would be prudent to use these in your build path so that you are working with the same jars in both build and runtime environments.
I have done this where the Jars are multi-purpose (such as apache-commons) on our file systems and again we control the environment.
Reference the following:
http://www.eclipsezone.com/eclipse/forums/t51870.html
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
..but as apposed to Zsolt Török (his solution did not work for me) I double-clicked on the plugin.xml, went to the build tab, at the bottom, I clicked Add JARs..., and hey presto, it showed my project, and I then navigated to lib and included the external jar, as per step 1.
The approach from Andy Thomas mostly works, but you also need to export the packages needed by the existing plugin in the new wrapper plugin so that they can be accessed by the plugin at runtime.

Categories

Resources