Announcement Announcement Module
Collapse
No announcement yet.
using a roo generated entity in a project reference Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • using a roo generated entity in a project reference

    I'm using eclipse and have created a project (lets call it ProjectA) with some entities (lets say Person for this example) in Roo

    now have another project "ProjectB" in the workspace which has a project reference to ProejctA.

    when I try to use Person in some code located in ProjectB, I do not get access to the getters & setters created in the AspectJ by roo. Am I missing somethere here or is there a better way to reference ProjectA from within ProjectB?

    many thanks in advance.

    Ben

  • #2
    When you say you cannot access the getters/setters, does this mean ProjectB does not compile at all or simply files you open in ProjectB with an Eclipse editor fail to show the introduced getters/setters during code assist?

    Does ProjectB compile successfully if you attempt to compile it outside of Eclipse? If so, this indicates it's more likely an issue in AJDT.

    I'll mention this tread to the AspectJ/AJDT team and see if they can offer any further suggestions.

    Comment


    • #3
      Hi Ben,

      I have't tried compiling out of the ide, but yes, it does not give me the code completion when inside the ide, which is something i would very much like to have.

      FWIW when I export ProjectA to a jar then import it in ProjectB it works fine, this problem only seems to come up when I am using a project reference...

      thanks
      Ben
      Last edited by benmonro; Jan 14th, 2010, 06:58 PM.

      Comment


      • #4
        Hi benmonro,

        I'm guessing that your project B is a Java project, not an AJ project. When I try your situation with 2 AJ projects with standard project references, I do not see the problem you describe, but when project B is a plain Java project, I do see the errors in the editor (but not in the problems view).

        This is mostly by design. What is happening here is that both Projects A and B are being compiled correctly, but only the editor is showing problems.

        A way around this is to make Project B an AJ project.

        If you are interested, what is happening is that the magic that we have in AJDT to enable ITDs to appear where they should is only enabled when inside of an AspectJ project. The reason is that there is a bit of a performance hit for this extra functionality that may not be appropriate in pure Java projects.

        Now, that being said, I did find a bit of a bug. When Project A is added to Project B's aspect path, I do see some real compile problems. I'll have to look deeper into this.

        Is it possible for you to add the AJ nature to Project B and if so, does it help?

        Comment


        • #5
          Hi Andrew,

          I'll give it a whirl, but the project is an android project so I'm not sure if I'll be able to do that without messing up how android sees the project. I'll try it out and post my findings here.

          many thanks for your help

          Cheers
          Ben

          Comment


          • #6
            Well, if the need becomes big enough, we can consider relaxing the requirement that ITD-awareness is disabled in all Java projects. It could be possible to walk the project dependency graph to see if any project upstream is an AJ project and if so we could enable ITD-awareness in the Java project. But, I'm still a little concerned about the performance impacts in the Java projects.

            Comment


            • #7
              yeah understood.

              i'm wondering if there's a way to have a project reference exported as a jar to ProjectB each time its compiled (this is basically the way .NET does things). When I use the jar reference everybody's happy, its only when I use the direct project ref that things go wrong.

              Comment


              • #8
                Originally posted by benmonro View Post
                i'm wondering if there's a way to have a project reference exported as a jar to ProjectB each time its compiled (this is basically the way .NET does things). When I use the jar reference everybody's happy, its only when I use the direct project ref that things go wrong.
                Hi,

                You can achieve something like that if you change from a Project dependency to a class folder dependency. In Project Properties for your Java project, select Java Build Path. Click 'Libraries' on the right and 'Add Class Folder'. Then add the output folder of the AJ project as a class folder dependency for your java project. This is similar to what you described above but avoids the need to use a packaged jar.

                Let me know how that works out for you,

                cheers,
                Andy
                ---
                Andy Clement
                AspectJ Project Lead

                Comment


                • #9
                  Well guys I tried a bunch of differnt ways to do this, but just couldnt get it working. Instead of running this in an android project, I went to a simple Java project. When I run a main method w/ a reference to the jar (i used the export feature of eclipse to export the roo gen'd library), I do the following code:

                  Code:
                  		Person p = new Person();
                  		p.setName("ben");
                  		
                  		System.out.println(p.getName());
                  I then get the following exception:

                  Code:
                  Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/aspectj/ConfigurableObject
                  	at java.lang.ClassLoader.defineClass1(Native Method)
                  	at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
                  	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
                  	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
                  	at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
                  	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
                  	at java.security.AccessController.doPrivileged(Native Method)
                  	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                  	at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
                  	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
                  	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
                  	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
                  	at com.ProjectB.MainClass.main(MainClass.java:11)
                  Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.aspectj.ConfigurableObject
                  	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                  	at java.security.AccessController.doPrivileged(Native Method)
                  	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                  	at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
                  	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
                  	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
                  	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
                  	... 13 more

                  Comment


                  • #10
                    I'm assuming that you are getting this when you are running, but not when compiling.

                    Unfortunately, because of all of ROO's dependencies, this is not as easy as it should be. What is happening is that the jar from the roo project has lots of other dependencies that must be included on the classpath of the launch.

                    So, to fix this, in your launch configuration tab, you must include all the jars that are on the ROO classpath for the roo project.

                    Comment


                    • #11
                      Yeah this happens when I run.

                      I presume by Launch tab, you mean Build Path => Libraries?

                      There are a pretty large number of dependencies in the Roo project (under maven dependencies) what do you recommend as the easiest way to package all of these up for my console project to see them?

                      Comment


                      • #12
                        Click on the little arrow next to the Run icon ->
                        Run Configurations... ->
                        Choose the launch you are working on ->
                        Select the Classpath page ->
                        Select User Entries ->
                        Click on project ->
                        Add Project A ->
                        Launch

                        This should be enough. Let me know if it works for you.

                        Comment


                        • #13
                          that didn't work (i got the same error)

                          I next tried putting a main class in the same level as Person inside of ProjectA and when I run that I get the following exception

                          Code:
                          java.lang.NoClassDefFoundError: com/helloroo2/domain/Runner
                          Caused by: java.lang.ClassNotFoundException: com.helloroo2.domain.Runner
                          	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                          	at java.security.AccessController.doPrivileged(Native Method)
                          	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                          	at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
                          	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
                          	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
                          	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
                          Exception in thread "main"

                          Comment


                          • #14
                            Oh... and make sure that all classpath entries in the ROO project are marked as Exported. You can do this from the Java Build Path properties page. It may be that the ROO jars were not being added to the classpath because they were not exported.

                            Comment


                            • #15
                              hmm found something interesting, maybe it gives you a hint. When I run "perform package" from the roo shell, I'm then able to run it inside of ProjectA. it still doesn't work when i run from projectB though...

                              Comment

                              Working...
                              X