Eclipse Java Resources Folder - java

I am learning Java Dynamic Web Development and have confusion about the folder structure created by Eclipse. I am running the latest Eclipse IDE 2021-03 JEE and noticing that, when creating new projects, the project structure appears to be different when comparing to the online tutorials I've seen. I am noticing a WebContent folder in which I believe I can simply rename the folder from "src/main/webapp" to "WebContent" in the Content Directory during the web project creation. But the Java Resources is one that I cannot seem to add manually and it is always appearing in every tutorial I've seen. I am hoping for some direction on this.
Thanks!

Related

WebContent folder does not exist, webapp instead

I'm taking the following course right now: "Develop websites with Java EE".
I encounter a problem when creating the Dynamic Web Project because instead of having a WebContent folder like on all the tutorials I've seen, I get a src/main folder...
What should I do to be able to have a WebContent folder
The Eclipse for some reason replaced WebContent with webapp folder.
It is basically a replacement for it, but if you really want WebContent you can download 2017 version.
Here is the one that I have
Eclipse Java EE IDE for Web Developers.
Version: Oxygen.1a Release (4.7.1a)
Build id: 20171005-1200
https://www.eclipse.org/downloads/packages/release/oxygen/1a
https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/oxygen/1a/eclipse-jee-oxygen-1a-win32-x86_64.zip
After this version WebContent is replaced with webapp
Here is also a picture of the project structure if you have an eclipse that creates webapp or WebContent, as you can see it is basically a replacement to make it look more like maven structure.
"WebContent" was replaced to form a layout more easily transitioned to building a .war file with headless tools like Gradle and Maven. No one should be deploying to a production environment from their IDE. "WebContent" was also fairly unique to Eclipse's Web Tools. There's nothing special about it.
You don't need an older version, only to enter a different value when the New Dynamic Web Project wizard asks you what you want to use as your Content Directory on the third page of the wizard (if you don't want to use the new default):

Strange Java web application in Eclipse

I am new to Java web programming and currently working with a Java web project. Although I have searched for days but still not able to figure out what kind of project is it and how to configure to get it run. It has a webapps directory and a web application inside. But the Java code is stored outside and under the root directory.
So what documents should I read to get familiar with this kind of project, and how could I configure to get it run on Tomcat?
You should check the .project file located in your case at mapsview/.project to get more insight about this project. It has builder and natures information which helps you understand what kind of project is.

Importing an API in Java (eclipse)

I'm trying to import an API that I found online - joda time - into my program.
I've downloaded the files, stuck them in my source folder, but obviously since it isn't integrated into my program they won't work.
I've spent a lot of time googling around for different methods (maybe I'm searching for the wrong thing?) as well as just randomly doing a bunch of different things inside eclipse (I'm developing with eclipse) that include the word "package" or "import", to no avail.
I don't know if it's worth mentioning but my program is being built with the google app engine, and all their stuff is organized in a nice com.xxx.xxxx format, which I think is ultimately what I need to get my stuff into - I just don't know how.
Anyway, sorry if this is a ridiculously trivial question, and thanks in advance to anyone that helps.
You should just have to put the joda-time jar file inside the WEB-INF/lib folder of your project. This folder contains all the libraries that must be delivered with your application, and are automatically added to the build path of your project by Eclipse.
Since you are using Eclipse, you can use the library functions to add in external packages.
Right click on your project, and then choose Build Path --> Configure Build Path.
Click on the Libraries button at the top, and then click the Add External JARs... button.
Select the JAR file in your JODA directory.
If you are using the Eclipse deployment tools, this will automatically package your JAR file in to your web application. If it doesn't do that automatically, add that same JAR file in to your WEB-INF/lib directory (copy it in to your project).

JavaEE compiling files

I feel like a 4-year old who has a slice of bread with pb and a slice with jelly and is asking how to make a sandwich..
I've been given the responsibility of maintaining a javaEE website that was done by our parent company that no loner supports us. I'm relatively new to JavaEE and I'm trying to figure out how to recompile the files that need to be modified from within the root folder of the site.
I downloaded NetBeans to help me with this, but still can't figure it out. My problem is that the java files can't find any of the packages and resources they are dependent on. As far as I know, the resources are there.. although, I do see some packages starting with "com." and "javax.", and I don't see a 'com' or 'javax' folder anywhere.. I believe my problem has something to do with setting the class path in the project properties in NetBeans.. I tried that but either I'm not doing it right, or its not working. This whole Java compilation is so foreign to me, it'd be really great if someone could lead me in the right direction of getting this website compiled.
I posted a pick of the folder hierarchy of the website to help:
I'm trying to compile the RecordAdd.java file here specifically at the moment. Some of the packages it is trying to import come from its parent folder, asp, of the folder it is in, easp. The file is also trying to import com.icesoft.faces.component.*; where '*' consists of several different imports of the parent packages. I don't see a com folder like I mentioned, but I do see icefaces.jar files in the lib folder in WEB-INF folder. I've tried putting these folders in NetBeans Library-Compile category classpath, but that didn't do anything.
I'm not doing something right, that is probably a basic knowledge of compiling java projects, but I'm just not getting it. I really appreciate any help, just please don't be too harsh. Thanks!
Try to find out which IDE the original devs used. I see a nbproject folder which indicated Netbeans (unless that was created by you) so try opening the project in Netbeans as a Java EE project. I'd also try to open it in Eclipse, it has good importing capabilities and can sometimes figure out the classpath on it's own. Download the Java EE version of Eclipse and install the Web Tools Project. You can also try to see if there is a build file that will compile and generate a war file for you (something like build.xml).
It should be simple if the project was created in netbeans. Just go to File -> Open Project. Navigate to where the project is located. You will know if the folder is a project, because netbeans recognizes it and a different icon is displayed instead of a regular folder icon. Once you open your project, you can right click compile the project.
You don't use java compiler yourself to compile java files in a project. Compiling and building are done by tools like ant, maven... It's automated.
Importing existing projects into netbeans is a great way to loose a half a day.
I'm assuming that since there's a nbproject directory, this was built through netbeans, which should give you a leg up.
In the "Open Project" wizard, the top level of your application (not necessarily the sources) should have a friendly globe icon for a web application (.war) or a triangle for EE application (.ear). Open the triangle if there is one. Web applications can be packaged with EE applications through netbeans, so if the Web App you're trying to compile belongs to one, some of the build properties may be associated with it.
Looking at the file nbproject/build-impl.xml should give you hints about where your libraries folder was located. Make sure this path matches in your project properties under the Libraries header. These libraries can be shared among projects and therefore likely out of this projects directory structure and referenced or native to this project alone in which case jars are copied in to your lib folder.
There may be additional reference or server issues that netbeans detects (and gives a paltry error message for) which can be found in the project context menu under "Resolve Reference Issues" or "Resolve Missing Server". In netbeans projects are built against the servers they're run on right in the IDE. Check that you have the servers you want configured under Tools-> Servers, then ensure that server is linked in your project properties under Run.
This may not solve all your problems, but is a good start. Good Luck!

Java eclipse directory structure and tomcat

I have a java application hosted on tomcat, which has a directory structure like :
webapps/my_aapp/WEB-INF/CLASSES/SERVLETS/xyz.java
webapps/my_aapp/WEB-INF/CLASSES/SERVLETS/xyz.class
so that's how classes are referenced .
Now (I am new to eclipse), it generates a different directory strucutre, in which all .java files are outside the code and I don't know where class files are stored.
The result is that when I upload the files, and compile, I get errors like this:
javac -Xlint servlets/Ajax.java
warning: [path] bad path element "/usr/java/jdbc7.2dev-1.2.jar": no
such file or directory
warning: [path] bad path element
"/usr/java/mysql-connector-java-3.0.16-ga-bin.jar": no such
What's the best way to understand this java directory path issue? Better yet, how to synchronize this structure?
I want to keep my eclipse directory structure on tomcat.
Typically eclipse stores all class files under bin directory located under your project near src directory.
I personally like name classes more than bin, so I always change it when I am creating project or later using project properties (right click on project -> properties -> build class path.)
Check your disk, I believe your class files are there. Unless you are using some pluging that can change this behavior.
What kind of project are you using in eclipse? A WEB project? An ANT-build project? MAVEN build? The way it builds classes depends on it. There is not much that I can help you. Because you do not provide enough detailed information with your question, but I will try.
Anyway, you can configure your output dir to be web/WEB-INF/classes (which is not statndard and not recommended, but I am doing it in one old project ;D) if you have it configured as java project.
1. Right click on project,
2. Go to Java Build Path
3. go to source tab, select source folders and select output folder (in my project mypoject/web/WEB-INF/classes ).
4. If you want to run and debug on apache tomcat from withint eclipse using this configuration, you can use eclipse sysdeo tomcat plugin.
Other thing is: You have specified absolute links to libraries (I suppose looking at your error messages), please copy them to web/WEB-INF/lib and change links in project settings. (If you are using maven that you should learn maven, if you are using ant, than just rewrite the part thaht uses these libs). And check if you already has this libs in tomcat/shared or tomcat/lib classes.
Another way is to learn to work with standard way of creating web-projects in eclipse, and add a build and package tasks to your build process (whatever it is make, ant or maven). Then you should deploy your PACKAGED application (let it be *.jar).
My suggestion, please, read "Head First Servlets & JSP by Kathy Sierra, Bert Bates, Bryan Basham" this is great book. It has everything you should know about HTTP, JSP, servlets, tomcat, and web-application directory structure. It will make things much easier for you (at least it worked for me, it really helped me much to understand things, and it is great fun to read).

Categories