How to import Java class inside JSP file?
<%#page import="javaname.java"%> is not working in Eclipse Neon.
Already defined full path still not working.
We have an existing project that the java class is inside of WEB-INF/classes instead of src folder but when we try to do it on another project, we cannot import anymore using the same syntax (<%# page import="package.javaclass"%>)
Java class:
JSP:
Maybe it should be:
<%#page import="package.nameOfTheYouClass"%>
You don't need to add the .java ending to the class name.
The Totp.java source file doesn't belong in the WEB-INF/classes folder, it belongs in the fa folder under src so that Eclipse will compile it for you. At runtime the server is supposed to find the compiled Totp.class file there. I'm guessing that Totp.java is not actually in the source folder, meaning this was a correct error message all along.
If you've been adding files to, and directly editing files in, the WEB-INF/classes folder, you're doing it wrong. That folder is only ever supposed to hold classes compiled from the source folders like src and other resources copied there, by Eclipse, from the source folders.
check if the name of your class is right and that's it.
Related
As part of a project I was given three files, a partially written .java file where my work will go and two separate .class files. I created a new Java Project and added the .java file and started adding/editing the starter code.
How/where should I put the .class files?
I tried adding the class files to the bin folder and dragging/dropping them into the package in Eclipse.
You should go to the project's Java Build Path property page and add a Class Folder for those two files. The contents of bin will be erased and overwritten without notice.
I'm trying to create a folder called 'a' within a project that I'm currently in in VSCode. Within this folder, I am trying to create a file called Solution.java. When I create this file, I get an error saying "The declared package "" does not match the expected package "a"".
Resolving this issue is easy (just declare package a in Solution.java), but when I go an open the folder 'a' in a different VSCode window, I no longer get the package error in the Solution.java file within folder 'a', meaning I no longer need to declare a package.
Why is this? Why would changing the root project folder in VSCode change the need to declare a package?
screenshot of package error
error going away when switching root folders
You should add package statement like below to the top of the Solution.java.
package a;
That's because the identity of A changed.
VS Code recognizes the folder currently opened as project folder:
When you open A as the project folder, you can definitely create java files under it, and no statement needed;
When you open KICKSTART as the project folder, folder A turns to be a package and if you want to create java files under it, you should follow the java developing rules and add package a; on the top line of .java files which under folder a.
More information about package, please refer to Java-Package.
In order to fix the issue you must declare a package,
Syntax:
package package_name.sub_package_name;
(Declare a subpackage when you've created the file in a folder inside another folder) where the name of the package is the same as the folder in which you've created your java programme file.
I originally had all my .java files under a file named "GravityBallz", but I then created a folder called "src" inside the GravityBallz folder and put them all in there. Now it's giving me an error. I tried restarting but still didn't work.
Thanks
So here is the src folder I added
And here are all the problems I'm getting for all the .java files
Because you had put your java file in 'src' folder, so you need to add "package src" in every java file.
i know that this question was asked several times before but none of the solutions quite work for my problem (or i just dont know how to adjust them properly).
I try to program an application, that is supposed to open an image, which is located inside of the jar file of the application.
The jar file is created by maven, so originally the picture was in the src/main/resources directory of my maven project and it will finally be in the base directory of my jar file.
The program itself consist of two java files and an fxml file. The one java file is my main class (called imageviewer.java) and the other java file is my javafx controller (called Contoller.java).
The method, that is supposed to open the picture is in the Controller.java file.
The solutions I found were all using getclass().getResources... , but in this case it does not work (maybe because it is not a jar file that will consist of a single class). The name of the final maven-generated jar file will be imageviewer-0.0.1-SNAPSHOT.jar.
How can I access the image inside it?
Okay I did actually find the solution.
In Eclipse I was only able to acess the image while it was in the same folder as the java documents. After I moved it into the "Resources" folder (which is where it belongs in a maven project) i was not able to acess it with a relative path.
All I had to do was creating a new package inside of the resources folder that is called exactly the same as the package in which the java files are.
So my project structure now looks like this:
src/main/java/myPackageName/MyJavaFiles.java
and
src/main/resources/myPackageName/Imagename.jpg
After that i was able to acess is with getClass().getResourcesAsStream("Imagename.jpg");
I added the boilerpipe library directly to my src folder. Everything seems to be compiling when I run, but I get an error telling me that one of the classes in the boilerpipe library could not be resolved.
The ArticleExtractor class is what I'm trying to use, but Eclipse won't let me even though its class file is in the bin folder.
I'd post a picture, but I don't have the reputation. Boilerpipe itself is a folder containing several other folders, containing the .java files in the source folder, and .class files in the bin folder after I've tried to run. I couldn't find anything on this here so I though I'd ask.
without seeing the code I would say that you either haven't added it to the build path or haven't imported the code into your class.