My JSP instantiates a MovieDetails class. I am currently working using scripting to ensure everything is working fine, before I move to tags.
I am using Tomcat 8.0. Directory structure for MovieDetails.class: com/library/model/beans. A copy of the directory structure with the MovieDetails.class file is also placed under WEB-INF/lib (have tried putting a .jar for the file too)
In the JSP I have:
<%# page import="com.library.model.beans.*" %>
And later:
<%
MovieDetails movDet = (MovieDetails)request.getAttribute("MovieDetailsBean");
....
....
%>
I am getting:
java.lang.NoClassDefFoundError: com/library/model/beans/MovieDetails
Can anyone please tell me why the JSP can't find the class in spite of the class being in the /lib directory?
NoClassDefFoundError and ClassNotFoundException is two different exception
<c:url var="addAction" value="/user/add"></c:url>
warning:The tag handler class for "c:url"
(org.apache.taglibs.standard.tag.rt.core.UrlTag) was not found on the
Java Build Path
I have included the JSTL jar but still it gives same warning.
Is any other jar required?
You have to add standard.jar as well.
Did you include the jar files into the correct directory?
They need to be stored in the lib folder in WEB-INF (...WebContent/WEB-INF/lib/).
You may have just stored them in the WEB-INF folder.
I'm using a library that has a dependency on JSF.
When I try to run my project, it show following exception massage..
java.util.MissingResourceException: Can't find bundle for base name /Bundle, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:705)
Any ideas ?
The exception is telling that a Bundle_en_US.properties, or Bundle_en.properties, or at least Bundle.properties file is expected in the root of the classpath, but there is actually none.
Make sure that at least one of the mentioned files is present in the root of the classpath. Or, make sure that you provide the proper bundle name. For example, if the bundle files are actually been placed in the package com.example.i18n, then you need to pass com.example.i18n.Bundle as bundle name instead of Bundle.
In case you're using Eclipse "Dynamic Web Project", the classpath root is represented by src folder, there where all your Java packages are. In case you're using a Maven project, the classpath root for resource files is represented by src/main/resources folder.
See also:
Maven and JSF webapp structure, where exactly to put JSF resources
maven-tomcat-plugin
If you start the Project using the maven-tomcat-plugin / maven-tomcat7-plugin, you must place the Bundle.properties, or even the Resource.properties in src/main/webapp/WEB-INF/classes. Dont ask why, its because how the plugin fake a tomcat.
If you are running the .java file in Eclipse you need to add the resource path in the build path .
after that you will not see this error
In my case the problem was using the language tag "en_US" in Locale.forLanguageTag(..) instead of "en-US" - use a dash instead of underline!
Also use Locale.forLanguageTag("en-US") instead of new Locale("en_US") or new Locale("en_US") to define a language ("en") with a region ("US") - but new Locale("en") works.
I had the same problemo, and balus solution fixed it.
For the record:
WEB-INF\faces-config is
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<message-bundle>
Message
</message-bundle>
</application>
</faces-config>
And had Message.properties under WebContent\Resources (after mkyong's tutorial)
the pesky exception appeared even when i renamed the bundle to "Message_en_us" and "Message_en". Moving it to src\ worked.
Should someone post the missing piece to make bundles work under resources,it would be a beautiful thing.
In my case I was dealing with SpringBoot project and I got the same exception.
Solution is made by adding env.properties file into classpath (i.e. src/main/resource folder). What was making the issue is that in log4j configuration there was property like
<Property name="basePath">${bundle:env:log.file.path}</Property>
The Bundle.properties file must be in the directory of the .class files. If it is located in the src directory then you need to make sure to copy it to the bin (output) directory in the same package.
Bundle names have to be fully qualified, like if your bundle Bundle.properties
is inside x.y.z package, then you have to write ResourceBundle.getBundle("x.y.z.Bundle");
I had the same problem using Netbeans. I went to the project folder and copied the properties file. I think clicked "build" and then "classes." I added the properties file in that folder. That solved my problem.
I use Eclipse (without Maven) so I place the .properties file in src folder that also contains the java source code, in order to have the .properties file in the classes folder after building the project. It works fine.
Take a look at this post: https://www.mkyong.com/jsf2/cant-find-bundle-for-base-name-xxx-locale-en_us/
Hope this help you.
The problem must be that the resource-bunde > base-name attribute at the faces-config.xml file has a different path to your properties. This happened to me on the firstcup Java EE tutorial, I gave a different package name on then project creation and then Glassfish was unable to find the properties folder which is on "firstcup.web".
I hope it helps.
Make sure you didn't add the properties files in the wrong resources folder as there is one under 'Web Pages' and one under 'Other Sources/...'. They needed to be under 'Other Sources/...'.
I was able to resolve the issue, the resource was in my project directories but when the junit utility tries to load it, it was returning an error of MissingResourceException. And the reason was the resource was in the not on the classpath of the test class package so when I added the cfg/ folder to my classpath path entry in eclipse and set the output directory in the build conf to the same class package the issue was resolved.
When you try this approach just make sure, the classpath conf file shows the classpath entry of the resource directory (eg. cfg/)
In maven, folder resources, create the same package structure where the configuration files are located and copy them there
I inherited 2 JSP projects (tomcat) in my eclipse with common code that is duplicated.
I wanted to externalize the duplicate code to common library/project and reference it from both JSP project.
So I did the following:
I created a new Java project "JSP-Common" with the following package "com.mycompany.jsp.common". There I create a class "ExternalClass" with a public "test()" method that returns a string.
in JSP1 project(one of the 2 JSP projects):
I added the JSP-Common project to the build path projects tab
I added to the jsp file in it the following import:
<%# page import = "com.mycompany.jsp.common.*" %>
I added to the jsp file in the body somewhere
<% ExternalClass ec=new ExternalClass(); %>
After building and publishing the project, I get a "ExternalClass cannot be resolved to a type" error on the line with the instantiation above in my page.
Am I missing something ? Help ?
I want to make it so when I build my JSP1 project it will automatically take the callses from the JSP-Common project.
You have to add JSP-Common project in Deployment Assembly: go to Deployment Assembly page under project properties. Hit Add and select "Project" option.
I'm trying to run old servlet under resin. I have deployed it as a war file. After starting resin there is a dir ic. It contains Webcontent dir with WEB-INF/lib/ic.jar (fatjar), jsp etc. While extracting this ic.jar I see there package com/x/y/z but while trying to access servlet page I'm getting an error: package com.x.y.z does not exist.
Can anyone give me any clue?
The jar needs to be in WEB-INF/lib, not in WEB-INF.
When extracting the JAR file, you should see
com/x/y/z/ClassName.class
not
com.x.y.z/ClassName.class
Assuming that what you wrote wasn't a summary of what you saw (or a typo).