Converting a Java Project to a Dynamic Web Project - java

I'm using Eclipse Ganymede to create a web application, but the project's currently just a standard Java project. I want to convert it to a Dynamic Web Project and I need a hand in doing that.
I've had suggestions given to me about editing the .project file, but when I restart Eclipse it refuses to open the project claiming the file is corrupt. There's also no facet management options in the project properties.
Any suggestions?

Although this question is already answered I'd like to say that I managed to convert my project into web project by changing project facets Properties->Project Facet and just checked Dynamic Web Module

Well. I'll tell you why, folks. It's because a lot of these guides miss out some fundamental things.
Yes, you need to change the .project file to add some missing natures and builders (create a new Dynamic Web Project and examine the created .project file to see what's missing).
You also need to add things to the .settings folder. It'll be missing two or three files, one of which is a key xml file. They're all required for it to understand the new natures you've given it.
Huzzah for computers.

When you cannot add the "Dynamic Web Module" via "Project Facets" make sure you unlock and disable the "Utility Module" since they are mutually exclusive.
I've spend quite sometime (re)editing the raw .project-file (according to the earlier mentioned sites) until I discovered this. It was probably was set when I was messing with my maven configuration.

Run on server option is not displaying in eclipse .
The solution for it that i found is " check Project properties / Project Facets / Dynamic Web module" . For this we need to unlock utility module and then check Dynamic Web Module.
But , Utility module is also necessary for Java EE Application. So how to select both Utility and Dynamic Web Module to make it Dynamic Web Project so that we can get Run On server Option.
Note : I have already copied necessary things in .project file and files in .settings folder.

Related

Domino Designer : Eclipse Project Loses External Jar References

I'me developping a java agent with Designer 8.5 with external jars in the project.
It works fine except when I close and reopen the project.
Then something quite strange happens: in the project build properties the references to jars are present but not taken in account, so there are compilation errors.
Then if I save a source file and come back to the project properties the references have gone.
So I must use the button "Add external jars" to redeclare them.
Has someone had this problem?
Mikkel Heisterberg has a great summary of the options available to you in regards to Managing external Java dependencies in Domino Designer
Basically, it boils down to:
Include the classes in the agent/web service you are writing
Put the classes in a Java script library and include the script library
Use the JavaUserClasses notes.ini setting
Put the classes in the jvm/lib/ext folder
Was that the information you were looking for? If not, please describe where/how you are using the external jars (Agents, Xpages, Managed Bean, ...).

Eclipse: Is it possible to publish Javascript edits to an external Tomcat instance

I am converting an application from Flex to Javascript. My workflow within Eclipse for Flex was to use Maven to start my Java web app in Tomcat and then have Eclipse configured to compile edited Actionscript files to a SWF and save it to my exploded WAR directory (that Maven/Cargo uses).
It worked very well for a long time allowing me to edit actionscript source code, flip over the browser, refresh the screen and see the changes.
I am new to Javascript however, and am struggling to get the same workflow up and running. The part I don't understand is how to tell Eclipse that I would like my edited Javascript files to be written out to a particular directory (that contains the exploded WAR). In my WAR project (a WTP dynamic web project) there is something that looks like a Javascript build path called "Javascript resources", but there is no output directory.
I would really like to continue to run Tomcat and Jetty via Maven if at all possible. I realize I can do what I want via WTP (M2E-WTP), but would prefer to use Maven/Cargo.
Denis's suggestion to create custom builder is probably best solution if you want to continue using pure Maven/Cargo approach with Eclipse.
If you are deploying to an exploded war directory, then another similar idea would be to use a File Synchronization plugin. These will automatically copy modified files to configured folders. See:
http://andrei.gmxhome.de/filesync/
https://wiki.onehippo.com/display/CMS7/Use+Filesync+Eclipse+plugin+for+faster+turn+around
-------------
FWIW, I don't think Maven:Tomcat/Cargo plugins are ideal for real-time web development, especially on the frontend side of things. They are useful mainly for controlled deployments or bootstrapping a server without initial setup. My thoughts:
Eclipse WTP used to be great for real-time web development, but I stopped using it a few years back as it just got way too hard to make it work correctly in a Maven environment. Fwiw, my preferred approach these days looks like this:
Do not install or use Eclipse WTP.
Use m2eclipse to integrate Maven with Eclipse.
Use Maven to do clean builds and generate exploded WAR directory in target folder.
Setup independent Tomcat server to load webapp from the exploded target folder.
I suspect the tomcat setup/startup could be integrated into Maven. It's not worth the extra complexity to me though.
Then, I configure JRebel (automatically via Maven) to handle java and web resource file changes. With this setup, I almost never have to redeploy or restart Tomcat. All changes (java, html, js, etc.) are seen immediately.
I think the same setup could be used without JRebel (for non-java files only) by configuring the web source folders as source folders in Eclipse with custom target output path being the corresponding directory in the exploded war directories. If that didn't work, then it would definitely work by using the custom builder or file synchronization solutions mentioned above.
Eclipse introduces the concept of "builder" to build a project. It comes with hardcoded builders such as the java compiler or the war builder of WTP.
But eclipse also enable to setup your own Builder using ant files : on your project, right click the project properties, go to section Builders, click on the new button.
You can use arguments to your ant file and use variables defined in by eclipse to build them
Do not forget to fill the refresh tab if you want eclipse to by notified of the produced files.
Do not forget the fill the Build options tab, section "Specify working set of relevant resources" in order to have your builder called each time a source used by the build file is changed inside eclipse.
Also go to the "targets" tab to specify during which type of build phase your ant file is called and which target is called.
I knwo this solution may not be the best for you since your build process will be described more than once but it may help you achieve your goal.

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).

Eclipse: Have multiple Dynamic web projects contribute to a single war file?

I am in a situation where I basically want to be able to have a web project in Eclipse where the WebContents folder is merged from multiple projects instead of only a single dynamic web project.
If I have "a.jsp" in project A, and "b.jsp" in project B, I would like to end up with a single web application in the web container where "a.jsp" and "b.jsp" sit next to each other in the same folder. It would be perfect if all files, not just the jsp-files, could be merged like this.
This is to be able to have a core version of our application but being able to handle customer specific changes easily.
I know I can do this with suitable ant magic, but we want to have something that works well for our current Eclipse based development process. We will use JSR-330 dependency injection on Java classes, and essentially I'd like something along the lines of dependency injection but just for any resource and not just classes.
Can Eclipse do this?
If Eclipse cannot, would an EAR deployment be suitable perhaps? I currently have experience with WAR's only.
If using Maven is an option, then Maven overlays would be perfect here and it should theoretically be supported by the m2eclipse plugin. But I don't have any experience with that and there might be some issues (see MNGECLIPSE-599) so this would require some testing.
Nevertheless, the comments of MNGECLIPSE-599 are pretty interesting, especially this one:
Any love for this issue? Our entire team has moved to Netbeans for WAR development because of this. We are basically waiting for Servlet 3.0 to solve this issue for us (Servlet 3.0 would effectively negate our need to do overlays in Maven) Our company is big on reducing copy-paste so we use overlays to manage WAR media that must be common in our apps.
The way Java EE 6 would make overlays obsolete is not crystal clear for me (through Web Fragments?) but the fact is that Eclipse's WTP release with Java EE 6 support has been delayed to June 2010. So, until then, you'll need extra tooling (e.g. maven overlays) or should maybe consider switching to NetBeans.
I had a similar use case which I successfully resolved by using (as Pascal suggested) Maven.
I have a root web project (which also works standalone) and for each client I have a separate web project which is configured to overlay with the root web project. Furthermore, since each client has several environments I created a maven profile for each environment (test, prod, local, ...). I documented this a bit so if ever you are interested I don't mind mailing you the doc.
you don't need to change your "eclipse based development process" to use ant. Just register an Ant builder (right click project > Properties > Builders) and integrate the ant script with your eclipse process
you can use maven's multi-module options. (The maven plugin for eclipse is very good as well)
use can also use FileSync - not industry-standard but pretty powerful. It's used for developing on localhost, of course.
Here are a few tips for using FileSync:
setup which files/file patterns/dirs to copy to a target directory (Tomcat's webapps/application in your case). So as soon as you press "save", the files are copied.
make all absolute paths in the FileSync.xxxx.prefs relative by introducing a Linked Resource (preferences > workspace > linked resources), and using the link resource variable in the prefs file (lets call it WEBAPP_HOME)
commit the FileSync.xxxx.prefs file
tell each developer on the team to configure the WEBAPP_HOME variable. Thus the setup will not be valid for only one machine, but for each machine in the team.
I recommend to use the servlet 3.0 "Resources in bundled jar files" feature.
With this feature you can include web resources (html/xhtml/css/js/jpg/etc) in jar files (along with java class files, of course) and the web server will search the "META-INF/resources" folders of the jars for the resources.
More details here:
http://alvinjayreyes.com/2013/07/28/servlet-3-0/

Categories