facebook

EAP and normal Java projects [Closed/Solved]

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #210004 Reply

    Marcus Beyer
    Member

    For my application I created a Java project containing all the more or less generic stuff, an EJB project and a web project. The EJB project and the web project access the classes of the normal Java project.

    Then I created an Enterprise Application Project. I added the EJB project and the web project but am not able to add the Java project directly to the application. Is there some way to include that Java project in the ear file? Or must I deploy them always seperately?

    thanx!
    Marcus

    #210009 Reply

    Scott Anderson
    Participant

    Marcus,

    If both your web and EJB project depend on the contents of the Java project, the easiest approach is to export the java project as a jar into the root directory of your enterprise project. Then, update the Class-Path entries in the MANIFEST.MF files in the EJB and Web projects to reference it. That will take care of the dependencies properly at runtime.

    Another approach is to combine your Java project contents into your EJB project since Web projects can automatically use all classes within EJB projects within the same EAR.

    #210129 Reply

    Marcus Beyer
    Member

    As I found out, the solution is quite easy: I added the following line to “natures” in the “.project” file of my Java project:

    <nature>com.genuitec.eclipse.j2eedt.core.ejbnature</nature>

    And then added the project as an EJB project to the Enterprise Application.

    If it’s so easy, why don’t allow any project to be part of an Enterprise Application?

    Marcus

    #210147 Reply

    Scott Anderson
    Participant

    Marcus,

    So I assume you used this workaround so that your Java project would be jar’ed and placed in the EAR root? Am I then correct in assuming that you modified the MANIFEST.MF entries in your web and EJB projects to reference it as a common library at runtime?

    #210150 Reply

    Marcus Beyer
    Member

    @support-scott wrote:

    So I assume you used this workaround so that your Java project would be jar’ed and placed in the EAR root?

    yes.

    @support-scott wrote:

    Am I then correct in assuming that you modified the MANIFEST.MF entries in your web and EJB projects to reference it as a common library at runtime?

    no. I did not change any MANIFEST.MF.

    My EJB project has got no MANIFEST.MF. The content of the MANIFEST.MF of the web and ea project are both the same:

    
    Manifest-Version: 1.0
    Class-Path: 
    

    Something wrong with it? Please explain.

    #210151 Reply

    Marcus Beyer
    Member

    Most strangely the .jar is in the .ear when I deploy it, but not if my colleague does—although we have the same Eclipse + MyEclipse versions and he checked out all changes to the project.

    🙁

    any idea?

    #210218 Reply

    Scott Anderson
    Participant

    As I found out, the solution is quite easy: I added the following line to “natures” in the “.project” file of my Java project:
    <nature>com.genuitec.eclipse.j2eedt.core.ejbnature</nature>
    And then added the project as an EJB project to the Enterprise Application.

    Sorry, but we’re not allowed to provide suppport once you customize the product as none of this functionality could’ve possibly been tested by our dev team.

    #210231 Reply

    Marcus Beyer
    Member

    Because of the problems I described above I had to undo my changes to the projects.

    My current solution is a build.xml in the EAP that creates a myproject.jar in the EAP rootdir.

    For the application server then I had to insert a line into its application.xml:

    <module><java>myproject.jar</java></module>

    Because this entry is deleted if e.g. some web project is added to the EAP, I generate it in the build.xml like this:

    <java classname="JavaModuleToApplicationXML"
      classpath="../ProjectOfJavaModuleToApplicationXML/bin/"
      fork="true"
      failonerror="true">
      <!-- fork="true" is important to be on the right dir!! -->
      <arg value="myproject.jar" />
    </java>
    

    Here comes my utility class that does the job:

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    
    /**
     * Inserts a module/java line to application.xml. 
     * May be used with ant. 
     * Important: fork must be set to true!
     * Not using any special libs, so classpath is simple :) 
     * 
     * @author Marcus Beyer
     */
    public final class JavaModuleToApplicationXML
    {
      private static final String TAB = "    ";
      private static final String NEW_LINE = System.getProperty ("line.separator");
      private static String       CN;
      static
      {
        CN = JavaModuleToApplicationXML.class.getName ( );
        CN = CN.substring (CN.lastIndexOf ('.') + 1);
      }
    
      public static void main (String [ ] args) throws Exception
      {
        if (args.length == 0)
        {
          exit ("jar not specified!");
        }
        String jarName = args [0];
        if (!new File(jarName).exists())
        {
          exit ("jar file not found: " + new File(jarName).getAbsolutePath ( ));      
        }
        File configFile = new File ("META-INF" + File.separator + "application.xml");
        if (!configFile.exists ( ))
        {
          exit ("config file not found: " + configFile.getAbsolutePath ( ));
        }
        BufferedReader br = new BufferedReader (new FileReader (configFile));
        StringBuffer sb = new StringBuffer ( );
        String line = null;
        int lastLine = 0;
        while ( (line = br.readLine ( )) != null)
        {
          if (line.indexOf (jarName) != -1)
          {
            /*
             * found
             */
            info (jarName + " already in application.xml");
            return;
          }
          if (line.indexOf ("</application>") != -1)
          {
            /*
             * insert
             */
            sb.append (TAB);
            sb.append ("<!-- generated by " + CN + ": -->");
            sb.append (NEW_LINE);
            sb.append (TAB);
            sb.append ("<module>");
            sb.append ("<java>");
            sb.append (jarName);
            sb.append ("</java>");
            sb.append ("</module>");
            sb.append (NEW_LINE);
          }
          sb.append (line);
          sb.append (NEW_LINE);
        }
        br.close();
        FileWriter fw = new FileWriter (configFile);
        fw.write (sb.toString ( ));
        fw.close();
        info (jarName + " added to application.xml");
      }
      public static void info (String s)
      {
        System.out.println (CN + ": " + s);
      }
      public static void exit (String s)
      {
        System.err.println (CN + ": " + s);
        System.exit (1);
      }
    

    This one works on all our machines 😉

    #210234 Reply

    Riyad Kalla
    Member

    Hey very slick! Thanks for provinding a nice solution, I’ll mark this thread as such so others can learn from it.

    #210247 Reply

    Marcus Beyer
    Member

    8)

Viewing 10 posts - 1 through 10 (of 10 total)
Reply To: EAP and normal Java projects [Closed/Solved]

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