facebook

Help with classpath configuration

  1. MyEclipse IDE
  2.  > 
  3. Installation, Configuration & Updates
Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #209524 Reply

    richsn
    Member

    Hi Folks,

    I’ve been doing Struts based web applications for a couple years but am new to both eclipse and MyEclipse. In the past I’ve done my development work using JBuilder. Unfortunately JBuilder doesn’t support Tomcat 5 so I’m looking for alternatives.

    My problem is with classpath configuration. My company’s source code is structured in an unconventional way and for the life of me I can’t figure out how to get the classpath configured in MyEclipse/Eclipse. I’ve spent a lot of time in the java build path section of the web project properties dialog and am not really making any progress. Any help you can provide would be greatly appreciated.

    We have our source code and our web application in 3 completely different trees (common Java code, application Java code and the web application (i.e jsp pages, and other web resources)). And just to keep it interesting all of this stuff is under CVS.

    The java common code lives at

    /apps/src/common/com/mycompany/

    Here we have shared actionBeans, utilities, and security code that shared between applications. So they look like:

    /apps/<b>src/common</b>/com/mycompany/actionBeans
    /apps/<b>src/common</b>/com/mycompany/security
    /apps/<b>src/common</b>/mycompany/utils

    The java application code lives at

    /apps/<b>src/website</b>/com/mycompany/actions
    /apps/<b>src/website</b>/com/mycompany/actionForms
    /apps/<b>src/website</b>/com/mycompany/actionBeans
    /apps/<b>src/website</b>/com/mycompany/actionMappings

    The web application code lives at

    /apps/<b>webapps/website</b>/
    /apps/<b>webapps/website</b>/images
    /apps/<b>webapps/website</b>/WEB-INF

    So what is the best way to get this mess configured? If you’d like I can described what I’ve done (which is long, involved and didn’t work). Please let me know what additional information you need.

    Thanks in advance

    – Rich

    #209533 Reply

    Riyad Kalla
    Member

    Rich,
    Lets take your “/apps/src/common/com/mycompany/actionBeans” as an example. I don’t know what the package statement looks like inside of these files, but I will assume it is something like “com.mycompany.actionBeans”, and the source root is actually “/apps/src/common”, is this correct? If it is, then you need to add the “/apps/src/common” and “/apps/src/website” paths under the “Source” tab on the “Java Build Path” properties panel. This will tell Eclipse to treat these two dirs as root source dirs, and everything under them as Java source files. (Please adjust the paths accordingly if I guessed the packages and such wrong above).

    Next you will need to open up the Navigator view (Window > Show View > Navigator) and find the .mymetadata file. Now open it, and look for the “webrootdir” property, and set its value to “apps/webapps/website” and save the file. Then close and reopen the project, right click on the project root > Properties > MyEclipse-Web and make sure the “Web-root folder” is correct. Also setup a context path here if you plan on deploying locally to Tomcat 5 (e.g. /webappname).

    Now, go back to your Java Build Path page, and set your output dir to: /apps/webapps/website/WEB-INF/classes… all your common and app-specific Java source code will get compiled in here, which is what we want.

    Now go to your libraries tab and hit “Add JARs” and make sure to add any JARs from within your project you need… additionally you might need to do “Add External JAR” and add the servlet-api.jar and jsp-api.jar files from your <Tomcat install dir>/common/lib directory. I would suggest adding these and REMOVING the default added “J2EE 1.3 Library Set” that MyEclipse adds. You won’t need the library set, and the versions of the Servlet and JSP APIs in Tomcat 5 are different than the 1.3 Library Set we ship, so you should use the newest version provided by your app server.

    I’m not sure if I forgot anything, so let me know if that helped.

    #209568 Reply

    richsn
    Member

    Riyad,

    Thanks for the quick follow up.

    Let’s start slow.

    Yes you have the paths correct for the java source (“/apps/src/common” and “/apps/src/website”). However when I look at the source tab I can’t figure out how to add them. If I click ‘add folder’ neither path appears. The only things I see are .myeclipse, src, and website (which is JSPs and other website stuff). So I think I’m still missing something.

    I’m not sure it matters but I’ve selected both projects (common and website) as project references for webapps.

    – Rich

    #209570 Reply

    Riyad Kalla
    Member

    Hmm ok lets backup here and collect some more info. I am assuming that you have created 3 projects in Eclipse:

    • /apps/src/common (Java Project)
    • /apps/src/website (Java Project)
    • /apps/webapps (Web Module Project)

    Is this correct? I will refer to these projects as “common”, “website” and “webapp” from now on. Common and website are normal Java code that webapp relies on (possibly application libraries or something along those lines), is this correct?

    Lets start from the beginning… I would suggest closing all your projects in Eclipse, then just opening common. Now navigate to the Java Build Path dialog and setup any libraries that this project needs to compile. Once everything is setup, double check that your Source and Output directories are set correctly (Source is likely “/common” and output is probably something like “/bin”).

    Now open your website project and do the same thing, again the Source is likely “/website” and the output is probably something like “/bin”. Make sure its libs are setup correctly as well and everything compiles cleanly.

    Now open your webapp project. Right click and go to properties, then go to the Project References panel. Here check your two Java projects “common” and “website”. Now navigate to the Java Build Path panel and on the Projects tab, check the two Java projects. Also, cleanup your Library tab by removing any JAR files that are references from either the common or website projects… I think Eclipse will pull up the classpath’s from the dependent projects for you into your top level project (if I’m wrong, add them back). Now hit OK. Did everything build alright? If not, what is wrong? Did you set your webroot like I mentioned in the previous post? Are you getting any errors anywhere? Is something not working?

    Lets go from here. The good news is that the situation you have is pretty common and I’m sure we support it, its just a matter of learning Eclipse and MyEclipse at the same time that can be confusing.

    #209597 Reply

    richsn
    Member

    Riyad,

    We’re making slow but steady progress. My old website and common projects were not java projects (thus no build path in properties). So this is fixed. I have two new projects which build and put their output in a bin folder. These projects are called src-common and src-website.

    I’m still having trouble with the website proper. I’ve added the two java projects to the website ‘Project References” and to the Projects in the project tab in build path. I think the libraries are setup properly and I’ve got everything checked in the Order and Exports tab. Finally I have modified my .mymetadata file (hopefully correctly). Here is how it looks:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <project-module context-root=”/website” name=”webapp”
    archive=”webapp.war” type=”WEB” id=”myeclipse.1089314250576″>
    <attributes>
    <attribute name=”webrootdir” value=”f:/eclipse-wsc/wscWebApps/webapps/website”/>
    </attributes>
    </project-module>

    I’m still get undefined references. I’m still getting the errors like ‘com.wsc cannot be resolved’. My package is ‘wsc’.

    What’s next?

    – Rich

    #209602 Reply

    Riyad Kalla
    Member

    Where is wsc from? Is it from src-common or src-website? Or is it from your website proper project? You’re web project can also have its own source folders as well if necessary (here is an example layout of a exploded war that works out of the box with ME: http://myeclipseide.com/FAQ+index-myfaq-yes-id_cat-30.html#111)

    So for example, if in the website proper project, you *do* have a src folder, you want to make sure to add it to your Source tab, and also set its outpath path to /website/WEB-INF/classes.

    #209606 Reply

    richsn
    Member

    wsc is from both common and website. It’s the ‘mycompany’ in my original post. We even have the overlap of classes in the packages.

    For example, we have a set of shared classes which implement our database stuff located in the src-common project under com.wsc.actionBean. We also have application specific database classes which are located in the src-website project and are under its com.wsc.actionBean. What we want to happen is when the stuff is asembled in the web project’s WEB-INF/classes directory we get the union of all classes in the resultant com.wsc.actionBean directory.

    To answer your other question, no we don’t put any actual java source in the webapp project (i.e. actual website).

    #209607 Reply

    Riyad Kalla
    Member

    wsc is from both common and website. It’s the ‘mycompany’ in my original post.

    Ok, if you navigate to your Java Build Path > Libraries tab, and click “Add Class Folder” and then add the /bin directories from both of the common and website projects, does the “class not found” error go away?

    #209608 Reply

    richsn
    Member

    nope. I even selected the ‘recompile all jsps’ command from the myeclipse menu in the navigator. No Joy. sigh.

    #209609 Reply

    richsn
    Member

    I just tried it again. This time it turned into xdoclet-build.xml and did some magic. THen it told me that it build successfully. However, if I go back and look at the problesm tab, it still tells me I have 58 errors.

    Does this mean we’re making progress?

    #209610 Reply

    Riyad Kalla
    Member

    What are the errors? Are there tons of duplicates or are they all different? Please list which ones you are referring to so I can help more accurately.

    Yes we are making progress, and what you are trying to do certainly isn’t black magic… I wonder why its giving us so much hassle.

    #209616 Reply

    richsn
    Member

    You’re right. We are making progress.

    I think it’s giving us so much hassle because of my eclipse/MyEclipse cluelessness. With all of these tools (JBuilder, Netbeans, Eclipse) there is a philosophy about how things get done. If you understand the philosophy things go much smoother. I still haven’t fully wrapped my head around how things are done in eclipse.

    The errors that I see are reference to my objects. In the following errors Partner, NoCachingTab, and SecureFormTag are all objects that are defined in the other two projects. Partner is in the src-common project, while NoCachingTag and SecureFormTag are part of the src-website project.

    There are 6 errors that are repeated for various JSPs. They are:

    – com.wsc cannot be resolved or is not a type
    – The import com.wsc cannot be resolved
    – Partner cannot be resolved or is not a type
    – Partner cannot be resolved or is not a type
    – cannot load class: com.wsc.taglib.NoCachingTag
    – cannot load class: org.apache.struts.taglib.html.SecureFormTag

    #209617 Reply

    Riyad Kalla
    Member

    Hrrm… can you open up one of the projects that hosts the class that can’t be found, and then using the navigator view (or Windows explorer) go into the bin dir, and into the com/wsc dir and see if there are classes in there? Has the project been built? Maybe try forcing a rebuild (this is done by “Cleaning” a project if “Automatically build” is selected)

    #209708 Reply

    richsn
    Member

    The classes are in both bin directories. Cleaning the workspace didn’t help. Both java projects build clean. The website still has the same 58 errors.

    #209709 Reply

    richsn
    Member

    Ok. Here is something. The classes are not being copied to WEB-INF/classes. I looked at .mymetadata and it seems correct (it’s the one listed a few posts back). The output directory in the website’s class path looks correct.

    Does the following errors help:

    Errors during build.
    Errors running builder “BJE JSP builder” on project webapp.
    Resource /webapp/eclipse-wsc/wscWebApps/webapps/website does not exist.

    Why does the resource line say ‘/webapp/eclipse-wsc/wscWebApps/webapps/website’? The webrootdir in .mymetatdata is ‘f:/eclipse-wsc/wscWebApps/webapps/website’.

    The default output path for the website is ‘webapp/website/WEB-INF/classes’.

    Would the ‘xdoclet-build.xml’ be helpful?

Viewing 15 posts - 1 through 15 (of 16 total)
Reply To: Help with classpath configuration

You must be logged in to post in the forum log in