- This topic has 9 replies, 3 voices, and was last updated 20 years, 5 months ago by Marcus Beyer.
-
AuthorPosts
-
Marcus BeyerMemberFor 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
Scott AndersonParticipantMarcus,
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.
Marcus BeyerMemberAs 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
Scott AndersonParticipantMarcus,
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?
Marcus BeyerMember@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.
Marcus BeyerMemberMost 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?
Scott AndersonParticipantAs 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.
Marcus BeyerMemberBecause 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 😉
Riyad KallaMemberHey very slick! Thanks for provinding a nice solution, I’ll mark this thread as such so others can learn from it.
Marcus BeyerMember8)
-
AuthorPosts