I created a Dynamic Web Project in Eclipse and wanted to use some font faces in the JSP files. I added a .css file to the project in Eclipse and put the following code in the file:
#font-face{
font-family: "Font Name";
src: url("FontName.ttf") format("truetype");
}
I put the FontName.ttf file manually (NOT by adding it using Eclipse) in the WebContent folder. .css file also lies in the same folder.
Problem:
I am using Tomcat server and whenever the browser requests this file, server responds with 404 Resource Not Found . Why does this occur?
Checks done:
The web.xml in of Tomcat contains appropriate mime types to handle the .ttf files. Specifically, these lines are present in this file:
<mime-mapping>
<extension>ttf</extension>
<mime-type>application/x-font-ttf</mime-type>
</mime-mapping>
I also put the FontName.ttf file in the main project directory. That was also not working.
I had thought that the problem was caused because of not adding the .ttf through Eclipse? If this is indeed the case, how can I add this file to the project using Eclipse? I could not find an appropriate way.
Related
I have a NetBeans project that uses the GSON library. I've tried including the GSON.jar file without requiring future users to separately download it. However it doesn't seem to work. The project looks for the file from the relative path of my computer so the file isn't found on another user's computer. Is there a way to include GSON.jar and "Export to Zip" and keep the reference in the project itself? I'm lost!
Thank you
Exporting a Project to ZIP zips up the project folder only, and not anything outside of the folder, including dependencies. If you include the GSON.jar file in the project folder, then the JAR file will be included in the .ZIP file. It's a good practice anyway since NetBeans will use a relative classpath and thus if you move the project itself NetBeans won't give you an error message when loading the project.
I want to include a file (text, image, etc) in the root directory of an Eclipse plugin.
When I run the program using a test main method, I can find the file in the working directory.
But when I run the plugin as an Eclipse application, the working directory contains different files depending on the operating system and I can't find the text file.
I tried adding the file to the binary build in the build tab of the xml (build.properties). It doesn't work still.
How will I find the path to the text file? How can I make sure that the text file is exported with the plugin?
Thanks
When you build your Eclipse plugin everything in the plugin is put in to a jar file in the 'plugins' directory. As long as your file is listed in the 'build.properties' (the build tab) it will be included in the jar.
To access a file in the jar use:
Bundle bundle = Platform.getBundle("your plugin id");
URL url = FileLocator.find(bundle, new Path("path in plugin"), null);
The URL returned is suitable for passing to various Eclipse APIs but cannot be used with normal Java APIs such as File. To convert it to a file URL use:
URL fileURL = FileLocator.toFileURL(url);
This will copy the file out of the jar in to a temporary location where it can be accessed as a normal file.
You can also get the Bundle using:
Bundle bundle = FrameworkUtil.getBundle(getClass());
which avoids having to include the plug-in id.
I have an eclipse (juno) workspace with some maven projects, the source directories always appeared under a folder called "java resources".
because of some migration at the office, I had to create a new workspace and reimport the projects. now the "java resources" folder is gone and the source directories appear directly under the project root.
This is messing with some linked resources in jsp files I have. there is a jsp file in a project which is imported in many other files, in other projects. There is a link in those extra projects to where the file is so that it can be found. previously the link was found ok, but now instead of looking the file starting in the root of the source directory, it is looking it in the root of the project:
<%#include file="/common/includes/global.jsp"%>
and I'm getting Fragment "/common/includes/global.jsp" was not found at expected path /MYPROJECT/common/includes/global.jsp
update- I thought that the problem with the linked resource was caused by this configuration. I already solved the java resources issues and the jsp still doesnt find the file
I looked for the configuration files in the old workspace and I found that the org.eclipse.wst.common.component file under .settings was different. the tag defaultRootSoruce as incorrect, since the jsps in my project are not under the standard maven layout.
This fixed it:
I'm creating a new dynamic web project in Eclipse and was wondering what best practices are for folder taxonomy. Here's what I believe it is <> are folders. Can someone please verify?
<Eclipse project name>
<src>
-- .java files
<WebContent>
-- .html pages
<images>
<css>
<js>
<META-INF>
MANIFEST.MF
<WEB-INF>
web.xml
<app name>
-- .jsp pages
Here is a sample folder structure of a dynamic web project:
As you can see all static files are placed as sub-folders under the WebContent folder. By naming conventions .css files are places in the css sub-folder. JavaScript .js files are placed under the js sub-folder and any image files such as .jpeg or .png are placed in the images sub-folder. I also have an extra lib sub-folder where I placed an angularjs library to be used.
By default after creation of a dynamic web project your web.xml file looks like so:
`<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>`
meaning it will first call the listed default name files when you run your application. This is why most projects will name the files as index.html or index.jsp. NOTE: that my index.html file is directly below the WebContent folder and not in a sub-folder
Finally you can call/include your static files (.css .js and image files) from your 'index' file like so:
<link rel="stylesheet" href=css/bootstrap.min.css>
<link rel="stylesheet" href=css/bootstrap-theme.min.css>
<script type="text/javascript" src="lib/angular.min.js"></script>
<script src="js/contactsApp.js"></script>
Also your .java files will properly go in the Java Resources -> src -> {place java files here}
Put your pages under WEB-INF folder, in that way they cannot be accessed directly.
Also look at maven directory layout http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html.
To what Aleksandr M said,
WebContent folder:
The mandatory location of all web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory(or in a sub directory structure under this directory), the files will not be available when the application is executed on the server.
WEB-INF
Based on the Sun Microsystems Java Servlet 2.3 Specification, this directory contains the supporting Web resources for a Web application, including the web.xml file and the classes and lib directories.
Source: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html
I am not sure why having an app-name directory under WebContent would be considered a "best practice".
Other than that, one primary rule you should be following when coming up with a directory structure is to have all static resources under one directory. In your example, I would have a subdirectory called static under WebContent, and place the js, css and images directories under it.
That way, it'd be easier for you to (later on) configure your HTTP server to pick static resources directly from the file system rather than route requests for static resources through the servlet container.
I had this question too and can't comment yet, but Upendra Bittu's answer helped me.
http://help.eclipse.org/neon/index.jsp
Search 'jsp', click on "Creating JavaServer Pages (JSP) files"
Create a dynamic Web project if you have not already done so.
In the Project Explorer, expand your project and right click on your WebContent folder or on a subfolder under WebContent. Note that
if you choose any other folder in which to create the JSP, then it
will not be included in the WAR file that is deployed to the server.
In addition, link validation will not encompass files that are not
under the WebContent folder.
From the context menu, select New > JSP. The New Java Server Page window appears with your folder selected
I'm trying out tutorials and get lost when people don't say where they create their files, and this helped me understand what's going on, so I'm just passing it on.
I am new to JavaEE but struggling hard to learn it.
I noticed one thing which is not working that is Code Assist in Custom Tag files in Eclipse. Same working in IntelliJIDEA current version. Both screen shots below.
Someone help me to enable Code Assist in Eclipse Indigo Service Release 2.
Edited
NetBeans & Esclipse don't show code assist for custom classes when I type ${user.} which is EL. Only IntelliJIDEA supports that.
Eclipse
IntelliJIDEA
JAR files
1) Try Window / Preferences / Web / JSP Files / Editor / Content Assist.
Make sure the HTML and XML Tag Proposals checkboxes are checked.
2) Can you specify it as a taglib instead of a tag import?
<%# tablib prefix="user" uri="/WEB-INF/tags/User.tld" %>
3) Do you have the right libraries in the classpath?
Enabling content assist for JSP files
Having the proper files defined in the Java™ build class path is essential for content assist to work properly in JSP files. It is also essential for the links builder to be able to correctly resolve links to servlets or Java beans in JSP and HTML files.
To enable content assist for JSP files:
To determine whether the build path is correct, select Properties from the
project's pop-up menu. Select Java Build Path, and then the Libraries page. You should see the following files:
j2ee.jar
rt.jar
servlet.jar
webcontainer.jar
If they are not present, add them as External JAR files. You may have your own versions of these files, depending on the level of JDK or Servlet API for which you are developing. If your Web applications reference other JARs, you can place them in the build path as follows:
Use the Add JARs button on the Library page.
You must ensure that the JAR file is available to the server by properly
configuring the server.
Add the JARs to the WEB-INF/lib directory.
They will be automatically added to the build path and deployed to the
server in as part of the project WAR.