As your screenshot shows, the mysql jar doesn't appear under the Web App Libraries node. Paste the jar in WebContent/WEB-INF/lib, and it will be automatically added to the build path and to the runtime classpath of the webapp (and it will appear under Web App Libraries).
As your screenshot shows, the mysql jar doesn't appear under the Web App Libraries node. Paste the jar in WebContent/WEB-INF/lib, and it will be automatically added to the build path and to the runtime classpath of the webapp (and it will appear under Web App Libraries).
Just now I troubleshoot this issue.
- Just go to
propertiesof your project. - Select
Deployment Assembly->add->Java Build Path Entries.
And you are done !
How to add jar to web app libraries for a specific project? - Genuitec
How to use java jar Libraries in an Eclipse dynamic web application - Stack Overflow
java - Eclipse | Dynamic Web Project | JAR File - Stack Overflow
java - How can I add JAR files to the web-inf/lib folder in Eclipse? - Stack Overflow
When you are creating web project it's not necessary to add your libraries in WEB_INF folder.
Solutions:
- You wrote that you don't want to use maven "because my company only allows specific libs and versions of those libs"
You can install your libraries to your local maven repository, to your local machine. So the dependencies will be retrieved from your local computer. It's very simple:
mvn install:install-file -Dfile=[file_path] -DgroupId=[your group id] -DartifactId=[artifact id] -Dversion=[version] -Dpackaging=jar
Also you can yous Nexus or Jfrog artifactory server to retrieve jars. This servers will be only for your company. So the jars will be accessible only for your company.
- Also you can extract dependency from your your JAR/EAR/WAR too (but it depends what technology you use - Spring, EJB or just Servlets); For example let's write example for Spring framework:
By default, spring boot plugin packages all dependencies of the project in the executable JAR with the following structure:
- JAR
- BOOT-INF
- classes (contains java packages and classes)
- lib (contains dependency jars)
- META-INF (contains the MANIFEST.MF)
- org (spring runtime support packages)
- BOOT-INF
MANIFEST.MF is responsible to find JAR files. In Spring we have the following lunchers: JarLauncher, WarLauncher, and PropertiesLauncher. Their purpose is to load resources. The JarLauncher is only able to locate and load classes inside BOOT-INF and JARs inside the lib directory. But you can use PropertiesLauncher to specify jar files outside the project. So lets' do it! first off all you should use ZIP layout.
Maven:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
</configuration>
</plugin>
Gradle:
springBoot{
layout = "ZIP"
}
Then everything is just simple. Now run the web application:
java -Dloader.path=lib,external-jar.jar -jar starter.jar
Now we have web application without WEB_INF folder and we have all the dependence jar files outside the application. Finally we have many projects that uses same library jars that is outside the project.
You should not rely on Eclipse to build the deployment package (.war file). Use a build tool such as Ant, Maven, Gradle, ...
If the company has a standard set of authorized libraries, the company should create an internal Maven Repository containing those libraries (e.g. using Artifactory), and you should use Maven to get the libraries needed for your particular project from that repository, and to build deployment package.
Advantage: Libraries are all in a common location, and not in a version control system.
If you can't get company to create a repository, but have a "common" project with all the libraries, then use Ant to build your project and create the deployment package.
Advantage: Project build is reproducible as batch build.
Gradle is a valid alternative to both Maven and Ant.
- Add the jar file to your WEB-INF/lib folder.
- Right-click your project in Eclipse, and go to "Build Path > Configure Build Path"
- Add the "Web App Libraries" library
This will ensure all WEB-INF/lib jars are included on the classpath.
Found a solution. This problem happens, when you import a project.
The solution is simple
- Right click -> Properties
- Project Facets -> Check Dyanmic Web Module and Java Version
- Apply Setting.
Now you should see the web app libraries showing your jars added.
I found the following solution that works for me on Eclipse Luna
Project B "Project Facets" : select "Utility Module" instead of "Static Web Module" or "Dynamic Web Module"
Project A "Deployment Assembly" : remove "B" and add it another time.
=> The "Deploy Path" of B is now B.jar
The easiest way is: File -> Export... -> Java -> Jar File
To use ant: open project properties, the go to Builders, Click new, selec Ant Builder, etc.
This means, all under src (source) will end up in the web-inf/classes (compiled!), and all under WebContent will be in your root (html,jsp, images, etc as the path layout you have organized!). And finally that your libraries will be in web-inf/lib. This way you can also do an export of the WAR / EAR and verify the bundle setup!