I am trying to create a WebServices REST project with IntelliJ IDEA. The idea is to supply some files to the user, but it seems that I can't find them in Tomcat's directory. For now I am trying to serve just a simple index.html page, but Java reports that the file could not be found. My current project structure is this: I thought that any data should be in the WEB-INF folder, or have I put it in the wrong place? Also, this is my GET function with the class I'm using: Any idea what I am missing?
Related
i have a problem when run Spring MVC on Eclipse
but when i clear the extra path it works properly
whats the main problem here?
In the first image, I can see that you used HomeController.java in url. You cannot make url in that way. Homepage path need to define in the web.xml file. By default web.xml contain path as project name so your project is working fine with project name in the url path which is absolutely correct.
However, remember that java never execute .java file. Java execute .class file which is created through compilation of .java file. I hope this will help to understand java better.
I have a maven web project in eclipse. I need to get the project's path, actually have to get list of files under src\main\resources\someFolder in project.
Tried String dataDir = "src\\main\\resources\\someFolder";, on running this directory structure is created inside eclipse folder like F:\softwares\eclipse\eclipse\src\main\resources\someFolder. Same when using / instead of \\.
Tried System.getProperty("user.dir")and new File(".").getAbsolutePath(), they return F:\softwares\eclipse\eclipse.
I need to access the project folder in my workspace F:\workspace\Project\src\main\resources\someFolder
But when created a core java app and used System.getProperty("user.dir")and new File(".").getAbsolutePath(), I am getting project path in workspace, F:\workspace\Project. This src\\main\\resources\\someFolder also works fine then.
Why this odd behavior from eclipse?
As mentioned here the directory user.dir is the place where the JVM is started. As web applications are mostly jar/war/ear packages placed somewhere within the folder of the server eclipse handles them in a different way because the behaviour of such a web application is different. You cannot expect to have file access from outside the jar/war/ear file. Within the jar/war/ear file everything from within src/main/resources will be available just by using getResourceAsStream as described in many other stackoverflow articles. This way you mustn't use src/main/resources/myfile.txt but myfile.txt.
Don't try to guess or use what the user.dir / JVM/server start folder is!
Grails newbie here. My application is in Grails, my IDE is IntelliJ IDEA. I configured my project (in IntelliJ) to say that my resources folder is under root\src\resources. I have an image file in there that I need to load into an InputStream / BufferedImage. However I can't seem to get to those resources from my Grails controller. This is what I was trying:
def image = this.getClass().getClassLoader().getResourceAsStream("image.png")
But that just returns null. I use this exact same convention in Java projects (well, except I have to declare image being of type InputStream), and it does work there. I was under the impression that I could essentially drop Java code in a Grails project and it should just work. What do I need to do differently to get this to work in my Grails controller? I need to access that static resource file.
If you mark a directory as a source directory in IntelliJ IDEA, Grails won't know about it. You have to configure Grails properly by either adding your new directory as a source directory or move the resource to one of the standard source directories.
I've never actually added a new source directory myself, but the answer to this stackoverflow question looks promising.
Other than that, you can just add resources to any source directory and it will be included, for example: grails-app/conf, src/java, src/groovy and more. In addition, any file in web-app/META-INF/classes will also be in the classpath of the application. The last one is great to know about if you need to copy a java or groovy source file (i.e. just copy, no compilation).
Try this
servletContext.getResourceAsStream("/WEB-INF/resources/yourfile")
I am using spring MVC validation for my login form in eclipse.
Here i want to add my jar files (Hibernate-validator,javax.validator etc..) into the lib folder in the WEB CONTENT.But if every time i add it will get into Javascript Resources.
I do found these question in forum but still cant get the right answer.Can any suggest me want i have to do.
Check if any copy of it is actually physically being copied to your javascript resoures at runtime. If so there might be some setup which is doing so, otherwise there is no possibility of your jar files being copied to your javascript resources.
I am doing a project in which one part is openid authentication. I am using Java.
I downloaded the code from the below site:
http://www.ibm.com/developerworks/java/library/j-openid/index.html, it said that he used wicket.
I tried to execute with tomcat server. I am able to compile the java files successfully.
But when I tried to run the openidregistration.html and put www.myopenid.com or (http)://pratap533.myopenid.com, it is not at all responding.
I am in big trouble as I have to complete the project to get my degree.
I included the openid4java.jar, joda-time.jar and wicket.jar file and the C:\Downloads\FileServe Manager\openid4java-sample-app\src all these files in classpath.
So I compiled them and was successful.
I created the wicket folder in webapps and in which I put web-inf. In web-inf I created classes folder and also copied the web.xml in web-inf folder.
In the classes I put all the 4 classes of wicket folder.
When I tried to run the openidregistration.html and put www.myopenid.com or (http)://pratap533.myopenid.com
it was not at all responding..
in web.xml file it is with servlet tags. those tags i did not include them.
Please any body help me..
I think I need to use eclipse, but I am not getting what is the problem.
I tried the following steps with the sample code you have mentioned and its working fine for me except i was getting connection failure error which might be due to the proxy network.
here are the steps for you
Create a dynamic web-application in eclipse IDE.
copy the jars from sample to the jar lib folder in your new project (created in step1).
replace the web.xml from the one from sample application.
copy the SRC folder from the sample application to the one created by you.
If you want to see what is happening inside the application copy the log4j.properties file from sample application to the src folder.
Follow the above 4 steps and you will get a running application what they have in there tutorial.
hope this will work for you.