Can I add predefined jars to WEB-INF/lib in Eclipse project? - eclipse

When I am designing normal Java project in Eclipse, I can add predefined libraries to it's Build Path. Can I do the same way when putting jars into WEB-INF/lib folder of Web project? I.e. can I ask Eclipse to put some predefined library jars there?

Just copy / import a Jar there; it will be added to the build path automatically. You will find it in the package explorer within the Web App Libraries (or in the build path in the project properties). The project has to have the Dynamic Web App nature.

This is what I did. I copied the jar files into my WEB-INF/lib folder. Then, I added these jars into my build path using: Properties -> Java Build Path -> Add Jars -> Select the jars from the WEB-INF/lib folder.

Related

Automaticly add 3rd pary jars to Tomcat's lib folder

I'm using Eclipse Neon 4.6 and Tomcat 8. I have my deployment assembly set with external jars via user libs and dependent projects. When I clean and build the project only the dependent project's jar files are added to Tomcat's WEB-INF/lib folder, not the 3rd party external jars even though they are specified in user libs and the lib is in the deployment descriptor. Any ideas as to why Tomcat isn't automatically coping the user lib jar files? One interesting note is that if I put the jar files in the project's WEB-INF/lib folder they are not picked up at run time either. I have also tried adding WEB-INF/lib to the deployment descriptor without any luck.
So I figured this. Turns out I correctly had libraries as dependencies in the project but did not mark them for export in Project | properties | Java build path | Order and Export. I had to check the libs for export. Now they are included in the WEB-INF/lib folder when I create the project WAR file.

Making Eclipse Maven repository inside the project

I'm a real beginner to Maven and Spring framework in eclipse so excuse me if this sounds trivial..
I have created a MVC web project in eclipse using the STS plugin on my windows computer, but my problem is that the location of the jar and configuration files that maven is set to by default is: C:\Users\MyName.m2\repository
This is a problem for me because eventually I'm going to make a WAR file out of my project and deploy it on a Linux machine, which does not have Maven installed on it.
My question is, is it possible to take all the jar files in my Maven repository, and make a local repository on the project itself rather than on an absolute path on the machine (sort of like a lib folder within the WEB-INF in the project that will hold all the maven jars and that maven will direct itself to it), and thus making the transition to the Linux machine smooth
I understand there is this classpath variable named M2_REPO, but doesn't seem to be editable or accept relative path rather than absolute.
Thanks in advance
Since you are using maven and you are adding your dependencies on your pom.xml, then all the dependencies with a scope of "compile" will be added to your final war file created by the maven war plugin under the WEB-INF/lib folder, this means that you should not worried about having maven in your linux server, since the war file that you are going to deploy will contain all the necessary dependencies. If you want to confirm this, just create a package of your project using "mvn clean package" and check the "target" folder generated by maven, you will see a "war" file, and you can unzip your file to check what contains.

How to include JAR to Liferay portlet in Eclipse

How to import jsoup.jar to Liferay portlet, through Eclipse IDE?
just copy your jar file into docroot/WEB-INF/lib folder of your portlet. if you create your portlet correctly using eclipse and Liferay IDE(plugin), eclipse automatically recognize your lib folder and jar files under it into classpath
liferay has ivy settings. you could just locate the ivy.xml file in your liferay-plugin-sdk-6.2 folder (this normally reflects in eclipse as a project folder with your version). add this line <dependency org="org.jsoup" name="jsoup" rev="1.8.1"/>
and then build "all". You'll see it download the dependency. When done, navigate to liferay-plugins-sdk-6.2/.ivy folder, look up the downloaded jar and copy it to your project's lib folder i.e /lib. Go to project properties, then Java Build Path. In the libraries tab, click Add JARs and navigate to /lib and add it.

Adding jars to a Eclipse PlugIn

I try to build a Eclipse plugin that has to use a self written jar which is dependent on other jars, but I don't get the point where to start with handling jars as seperate PlugIns. Anywhere I have to use just the .jar files or am I wrong?
I think I found a proper solution; the trick is that you have to implement all the files via Eclipse. I just copy here the solution which was posted to news.eclipse.platform:
Include the jars in a plugin:
Use Import > File System to import the jar files into your plugin project, say in the <project>/lib directory.
Use Add... button to add the jars to the classpath section of the plugin.xml > Runtime tab.
Use New... button 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.
What is a self-written jar?
Normally you turn 3rd party jars into bundles using an OSGi MANIFEST.MF (See New>Plug-in Development>Plug-in from Existing JAR archive) or you include them in your plugin.jar and add extra Bundle-ClassPath entries as mentioned by TomaC.
If you mean at runtime your plugin will create a new jar and needs to load it, that's different, though.
Project Properties -> Java Build Path -> Add External jars. Is this what you are looking for?

Using java library in eclipse

I'm a bit new to eclipse and want to use the following libraries so that I can use their implemented objects (HttpClient and Java csv). How do I import these libraries so that I can write some java with them?
http://hc.apache.org/downloads.cgi
http://sourceforge.net/projects/javacsv/
What you're looking to do is add the libraries to your project's build path (the class path that will be used while compiling). In Eclipse, you can do this by right-clicking your project and choosing Properties (or hitting [Alt]+[Enter] when the project is selected in Project Explorer, Navigator or Package Explorer views) and then Java Build Path from the sidebar and the Libraries tab where you can add JARs.
Note the difference between Add JARs and External JARs is that External JARs will add an external dependency in your project since the absolute path to the JAR on your filesystem will be put into your project's configuration. With Add JARs you can select JARs from within your workspace.
I find it to be a good practice to create a lib folder (at the same level as my src folder) and put all my JARs in there and then add them to the build path with the Add JARs option. This makes the project portable since there are only relative paths referring to resources within the project rather than absolute paths or resources from other workspace projects.
You add the .jar files you want to use in your projects build path. You access this windows by right-clicking your project. Choosing "Build path" -> "Configure build path".