IntelliJ IDEA resolving web paths in JSP - intellij-idea

How can I set where IntelliJ looks for files referenced in a JSP? If I have
<jsp:include page="/foo/bar" />
it cannot resolve directory foo.
It looks like Settings > Web Contexts deals with this, but when I go there, it says
No web directories found

You should configure a web facet in your project settings, then configure the directory containing foo as a "Web Resource Directory". If this is your root directory, set the "Path Relative to Deployment Root" to /.
See the official doc for more info.

Related

How to make IntelliJ understand the Next.js `public` directory structure?

I am using IntelliJ to edit a Next.js website.
IntelliJ IDEA 2020.2.1
Next.js 9.5.3-canary.23
Next.js static file serving uses a /public directory as a container for static assets, but when publishing a Next.js site, the contents of the public directory are hosted at the root of the site.
So, as shown in the linked doco, an image that exists in the codebase at /public/my-image.png is addressed by an URL path of src="/my-image.png".
This confuses IntelliJ and it shows a warning that it can't resolve the directory of the img src:
I tried marking the /public directory as a "Source root" or a "Resources root" - but that didn't make the warning go away.
I also tried adding the /public directory as a "Content root", but IntelliJ doesn't want to do that because it overlaps with the root directory of the module, which is already a content root.
Is there any way to tell idea to look in the /public directory for statically referenced assets like this?
I've had the same problem. In my case, "Mark Directory as > Resource Root" worked well.
Before...
Right click ./public. Then Mark Directory as > Resource Root
After...
Image loads.

unable to include external files in a project

I have created the default play application in IntelliJ in directory P. I have over-written the default index.scala.html with my own html code. The html code refers to some css and js files which are outside the directory P. To include these external files, I added the directory of these files using project configuration settings.
My webpage doesn't load properly as the server returns 404 for the css and js files. What am I doing wrong?
When you added your directory using project structure, you only say:
Hey, IDEA, please consider this folder part of my project, consider
its contents source code and display it when I open my project.
However, when you deploy or run your app, you only deploy the usual folders to the server, which contain the resources which will be available for clients to access.
The external directory is not part of these directories and will not be deployed.
What you can do is to copy the file from the external directory as a part of your build process before deploying the application.
EDIT: Detailed answer here: What is intellij's build process for play applications

How to configure resources root for web project in IntelliJ IDEA

I am working with a project with a single "Static Web" module in IntelliJ IDEA 13.1.4 with the PHP plugin (NOT PHPStorm).
Given the following directory structure:
-ProjectX
--application
--www
I marked the "www" folder as "resources root". The "ProjectX" folder is the "content root".
HTML references to resources are correctly resolved only in files from within the "www" folder, not when the "application" folder. Annotated screenshots:
This works in PHPStorm, but not IntelliJ IDEA. How do I get the desired behavior in IntelliJ so references will resolve from all project folders?
After playing with it for a while, I may have a solution.
It appears that BOTH "ProjectX" and "www" have to be marked in order for this to work. If you first mark "www" as a resources root, and THEN mark the parent/content-root folder as a resources root, the reference will resolve.
If this was obvious to anyone out there, please explain. Or is there a more appropriate solution?
SCREENSHOT:

intelliJ 13 not recognizing external configuration in navigation bar

I'm trying to set up a grails application and I've noticed that intellij doesn't recognize an external configuration file that i Have set up. When looking at another application, that I did not set up, an external configuration will display when listing project or project files in intelliJ's navigation panel on the left side. I believe I have my configuration file setup in the correct location with the correct naming convention. Grails looks for configuration files in the following locations
grails.config.locations = [
"classpath:${appName}-config.properties",
"classpath:${appName}-config.groovy",
"file:${userHome}/.grails/${appName}-config.properties",
"file:${userHome}/.grails/${appName}-config.groovy",
"file:${userHome}/.grails/${appName}/${appName}-config.properties",
"file:${userHome}/.grails/${appName}/${appName}-config.groovy"
]
I looked at the application.properties file and checked the app.name variable. It had a value of (as an example) website. So I set up my configuration file as such.
<root>\Users\<username>\website\website-config.groovy
when I open the project in intelliJ and ran the application (for good measure), i do not see the external configuration file listed in the navigation bar like my other project did. Do I need to enter that manually?

How to change the path that jar files use in java Web Applications

I have written a java Servlet web application, using NetBeans 7.2.1. The program have some jar file libraries that I have attached to the project. The application runs fine using NetBeans and Apache Tomcat 7.0.27.
My problem is that some of the jar file libraries that I am using in the project, need to access to some folders and files. I put these folder and files on the same directory as the whole NetBeans project is. but I got this exception:
Exception: java.lang.RuntimeException: java.io.FileNotFoundException
So I used these codes to find out where should I put them:
out.println("current directory: " + new File(".").getAbsolutePath());
out.println("current directory: " + System.getProperty("user.dir"));
out.println("current directory: " + getServletContext().getRealPath(("/")));
So I figured out that the current working directory is:
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27\bin
My question is that how can I set different directory address for each web application? I have many web applications and some of them use the same resource file names. I can't just put all of them in one directory.
Please note that I don't have access to the source code of jar files to change the. I just need a way to set the absolute path that the jar files use.
I have the same problem when I put the WAR file on the unix server. The extracted WAR file is in this location on the server:
/data02/tools/Apache/Tomcat/apache-tomcat-6.0.37/webapps/BANNEROnline
But I figure I should put the resource folders and files in this path (moosavi3 is my username!):
/home/moosavi3
How can I change the path?
The working directory is the directory from which java.[exe,bin] is started. I assume the bin directory is where the tomcat start-up script is? If the jars are all using this working directory I don't believe there is a way to make different web-apps have different working directory, they're all loaded on the same jvm (java.exe) from the same working directory.
A working directory is the directory from which a binary is started, it is not some arbitrary value that you can change.
I suspect these jar files where meant to be run as standalone applications and expected the filesystem resources they are trying to access to be in the same location as themselves.
Any filesystem resources would have to be moved to the location of your java.exe so that the correct file path resolution can result from your jars.
Standard Servlet project requires external libraries to be placed in the 'WEB-INF/lib' directory under project root. You can search google for 'servlet directory structure' and do your own research for more information. Shared libraries between web applications can be placed in the 'lib' directory under tomcat root, they should be picked up by tomcat jvm. My recommendation would be to keep the dependencies project specific, because you may need different versions in different projects in the future.
Update:
Read this page on the tomcat documentation, it will explain exactly how the project should be structured, and how to add a library that will be shared across all web applications:
http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html
Update 2:
The following Stackoverflow link explains several options how to add a static file to your web application, that will available at runtime.
https://stackoverflow.com/a/2161583/940754
Update 3:
Add a path to the classpath using the project's manifest:
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html