servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache ServiceMix > Importing ServiceMix into Eclipse
Date Sun, 21 Feb 2010 14:43:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=SM&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/SM/Importing+ServiceMix+into+Eclipse">Importing
ServiceMix into Eclipse</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~nanthrax">Jean-Baptiste
Onofré</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h1><a name="ImportingServiceMixintoEclipse-Introduction"></a>Introduction</h1>

<p>This document will guide you through importing ServiceMix 3 into the <a href="http://eclipse.org/downloads/"
rel="nofollow">Eclipse IDE</a>. </p>

<p>The Maven website offers some additional information concerning <a href="http://maven.apache.org/guides/mini/guide-ide-eclipse.html"
rel="nofollow">Maven and Eclipse</a>, for example how Maven goals can be executed
from within Eclipse or alternative ways of importing projects into Eclipse.</p>

<h2><a name="ImportingServiceMixintoEclipse-PreInstallationRequirements"></a>Pre-Installation
Requirements</h2>

<p><b>Operating Systems:</b></p>
<ul>
	<li>Just about any Windows or Linux/Unix platform that supports Java</li>
</ul>


<p><b>Environment:</b></p>
<ul>
	<li>JDK 1.5</li>
	<li>Maven 2.0.6 or greater</li>
	<li>Eclipse 3.3 or greater</li>
</ul>


<h1><a name="ImportingServiceMixintoEclipse-ImportingServiceMix"></a>Importing
ServiceMix</h1>

<p>Below are the steps to import ServiceMix as a project in Eclipse: </p>

<h2><a name="ImportingServiceMixintoEclipse-PreparingtheSourceforEclipse"></a>Preparing
the Source for Eclipse</h2>

<p>1) Grab the sources from the <a href="/confluence/display/SM/Source" title="Source">Subversion
repository</a> or <a href="http://servicemix.apache.org/download.html" rel="nofollow">download</a>
the ServiceMix source distribution <br/>
2) Build the source with the following command on the command line: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn install
</pre>
</div></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><p>If you encounter
some failures due to unit tests errors do the following:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn install -Dmaven.test.skip=<span class="code-keyword">true</span>
</pre>
</div></div></td></tr></table></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><p>If you try
to build ServiceMix 3.2.x version, you need to do the following:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn -Dmaven.test.skip=<span class="code-keyword">true</span> -P=step1
mvn -Dmaven.test.skip=<span class="code-keyword">true</span> -P=step2
</pre>
</div></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td></td></tr></table></div>
<p>If maven build dies with some checkstyle or pmd errors then do the following:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn -Dmaven.test.skip=<span class="code-keyword">true</span> -Pstep1,nochecks
install
mvn -Dmaven.test.skip=<span class="code-keyword">true</span> -Pstep2,nochecks
install
</pre>
</div></div></td></tr></table></div>
<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td></td></tr></table></div>

<p>3) Now create the necessary Eclipse project files using the following command on
the command line: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn eclipse:eclipse
</pre>
</div></div>

<h2><a name="ImportingServiceMixintoEclipse-ImportingtheSourceIntoEclipse%3A"></a>Importing
the Source Into Eclipse:</h2>

<ol>
	<li>From the "File" menu select "Import"
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/FileImport.JPG"
align="absmiddle" border="0" /><br clear="all" /></li>
	<li>Select "Existing Projects into Workspace" and click "Next"
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/Import.png"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>Browse for the root directory (into which you downloaded ServiceMix).&nbsp;
"Select All" the projects in the "Import" pop-up window&nbsp;&#45; they are probably
already pre-selected for you (check boxes are checked).&nbsp; Un-checking the option "Copy
projects into workspace" allows you to automatically always edit the current version of the
SVN checkout folder, thus avoiding an import after each SVN update. Click "Finish" in the
"Import" window; the import takes around three minutes.
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/Import_SelectAll.png"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>In the menu bar, open "Windows" and click "Preferences"<br/>
The "Preferences" window will pop-up.<br/>
Click on the "Java" plus sign and change to "Compiler". Compiler compliance level must be
5.0; select this option in the pull down menu.<br/>
Check the "Use default compliance settings" box.&nbsp;
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/JDK_Compliance.JPG"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>Then check under "Installed JREs" that you have JDK 5, e.g., jre_1.5.x&nbsp;
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/Installed_JREs.JPG"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>Click on "Build Path" and then select "Classpath Variables".&nbsp;
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath_Variables.JPG"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>Click on "New" button to right
<br clear="all" />
A pop-up appears.<br/>
Enter the Name: M2_REPO<br/>
Enter the Path of your local maven repository, usually located in &lt;your home directory&gt;\.m2,
for example: <em>C:\Documents and Settings\exjobb\.m2\repository</em>
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/eclipse-m2-repo-variable.PNG"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>Click "OK" button. The necessary build takes around three minutes.</li>
</ol>


<h1><a name="ImportingServiceMixintoEclipse-RunninganExample"></a>Running
an Example</h1>

<p>Now you can run an example:</p>
<ol>
	<li>In the Package Explorer find the Main class, which should be located in <em>org.apache.servicemix/Main.java</em>
under <em>servicemix-core/src/main/java/</em> and double click on the main() method.&nbsp;
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/PackageMainJava.png"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>From the Run menu select "Run..."&nbsp;
<br clear="all" />
<br clear="all" />  <img src="/confluence/download/attachments/39121/RunRun.JPG"
align="absmiddle" border="0" /><br clear="all" />
&nbsp;</li>
	<li>You will get a "Run" window pop-up, from there select "Java Application".
	<ol>
		<li>Click on New button in botton left (Eclipse &lt;v3.2) or the icon in the top
left (Eclipse v3.2)</li>
		<li>Name the Project: any name you like, for example if you want to run the FilePoller
/ FileBinding application call it "filepoller", so it's easy for you to remember what this
run configuration does.</li>
		<li>Click on "<b>Arguments</b>" tab:
		<ol>
			<li>In the "Program Arguments" box enter <tt>servicemix.xml</tt></li>
			<li>In the Working Directory enter the path of your example. Such as <em>S:\apache-servicemix\src\main\release\examples\file-binding</em>
where S:\ is assumed to be your servicemix root directory.
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><p>For ServiceMix 3.1 S:\
is assumed to be <tt>&lt;servicemix_root&gt;\distributions</tt></p></td></tr></table></div>
<p>You can use the "File System..." button to browse for your directory.
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Run - filepoller
- Arguments.png" align="absmiddle" border="0" /><br clear="all" />
&nbsp;
<br clear="all" /></p></li>
		</ol>
		</li>
		<li>Click on the tab "<b>Classpath</b>" to give Eclipse needed information
on where to search for executable files.<br/>
This description sticks to the file-binding example, but a similar procedure will be needed
for most examples and your own code as well.<br/>
There are three main ways to add classes to the classpath:
		<ol>
			<li>You can <b>add other projects of the workbench</b>. Doing this will
make the file-binding example run.
			<ol>
				<li>Click "User Entries"</li>
				<li>Click "Add Projects" and click the checkbox(es) in front of the project(s) that
are required. For convenience reasons you may click "Select All".
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath -
Add projects.png" align="absmiddle" border="0" /><br clear="all" />
&nbsp;
<br clear="all" /></li>
				<li>Click "OK". Now your Run-dialog shall look similar to this screenshot:
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath result
all projects.png" align="absmiddle" border="0" /><br clear="all" />
 &nbsp;</li>
			</ol>
			</li>
			<li>You can <b>add JARs and classes</b> that are stored within a path
contained in the classpath environment variable. This is not required for the file-binding
example, but possible, e.g. if you want to run a specific ServiceMix version from a JAR for
bug reproduction - this case is used for the following description. Often, this way is used
to reference dependencies Maven downloads automatically for you.
			<ol>
				<li>Click "User Entries"</li>
				<li>Click "Advanced", "Add Classpath Variables" and "OK"
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath -
Advanced Options var.png" align="absmiddle" border="0" /><br clear="all" />
&nbsp;
<br clear="all" /></li>
				<li>Check M2_REPO and click "Extend"
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath -
Advanced Options - Variable.png" align="absmiddle" border="0" /><br clear="all" />
&nbsp;
<br clear="all" /></li>
				<li>Choose the JAR containing the bytecode for the missing classes. If you want
to run SOME_VERSION of ServiceMix, choose /org/apache/servicemix/servicemix-core/SOME_VERSION/servicemix-core-SOME_VERSION.jar
<br clear="all" />
&nbsp;
<br clear="all" />
In case you want to reference a dependency, proceed in the same way. In case you do not know
which package you shall select, see below at <a href="#ImportingServiceMixintoEclipse-Troubleshooting">Troubleshooting</a>.
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath -
Advanced Options - Variable - Extend.png" align="absmiddle" border="0" /><br clear="all"
/>
&nbsp;
<br clear="all" /></li>
				<li>Click "OK"</li>
			</ol>
			</li>
			<li>You can <b>add arbitrary folders</b> to the classpath. This is usually
only needed for your own code. To explain the workflow, let's assume you did not add any projects,
thus your file-binding example does not run but thows errors and the console window contains
this message:
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>Error 'Bean class [org.apache.servicemix.components.file.FileWriter] not found'
</pre>
</div></div>
			<ol>
				<li>Click "User Entries"</li>
				<li>Click "Advanced", "Add External Folder" and "OK"
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath -
Advanced Options ext folder.png" align="absmiddle" border="0" /><br clear="all" />
&nbsp;
<br clear="all" /></li>
				<li>When S:\ is your servicemix root directory, select/enter <em>S:\servicemix-components\target\classes</em>
<br clear="all" />
&nbsp;
<br clear="all" />
Why this directory? Well, have a closer look at the error message presented above. The package
<em>org.apache.servicemix.components</em> indicates the location of the missing
bean <em>FileWriter</em> is <em>servicemix-components</em>, and as
we need an executable file, the <em>target\classes</em> subdirectory is where
to look. Of course we shall proof that <em>FileWriter</em> really is located here,
so execute <em>dir /s FileWriter.class</em> in the given directory and watch the
output. For further hints, see below at <a href="#ImportingServiceMixintoEclipse-Troubleshooting">Troubleshooting</a>.
<br clear="all" />
&nbsp;
<br clear="all" />  <img src="/confluence/download/attachments/39121/Classpath -
Advanced Options - external folder.png" align="absmiddle" border="0" /><br clear="all"
/>
 &nbsp;</li>
				<li>Click "OK".</li>
			</ol>
			</li>
		</ol>
		</li>
	</ol>
	</li>
	<li>Click Apply.</li>
	<li>Click Run.</li>
</ol>


<p>Now, ServiceMix shall start with the static configuration file (<em>servicemix.xml</em>)
you pointed at and in the Console tab all log output will be displayed.</p>

<h3><a name="ImportingServiceMixintoEclipse-DebuggingServiceMix"></a>Debugging
ServiceMix</h3>

<p>This is extremely easy when ServiceMix was already running - it just requires to
set a breakpoint in the Main.java (or anywhere else) and a press of F11 (debug last launched).</p>

<h2><a name="ImportingServiceMixintoEclipse-Troubleshooting"></a>Troubleshooting</h2>


<h3><a name="ImportingServiceMixintoEclipse-Oneortwolinesoferrormessages"></a>One
or two lines of error messages</h3>

<p>In case you see an error message like</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>java.lang.NoClassDefFoundError: org/apache/servicemix/Main
</pre>
</div></div>
<p>in the console window, the ServiceMix class (or xbean or whatever is stated) file
is not found. Did you add the class files to the classpath like stated above (see "Add Projects")?
In case you did, there may not exist any class files as they were not yet built. You can do
that by executing</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>mvn install
</pre>
</div></div>
<p>in the source's root directory. This will take roughly 10 to 15 minutes. Maybe you
prefer to reference a binary distribution (see "Add Classpath Variables" above).</p>

<h3><a name="ImportingServiceMixintoEclipse-Lengthyerrormessages%28stacktrace%29"></a>Lengthy
error messages (stack trace)</h3>

<p>Scan the messages in the console window from top to bottom until you find one stating
a missing component, indicated by a package name&nbsp;&#45; in case it's a "<em>java.lang.NoClassDefFoundError</em>"
or "<em>java.lang.ClassNotFoundException</em>", the missing class is printed directly
after that error string, whereas for instance "<em>Error creating bean with name</em>"
is demanding slightly more search in order to find out the missing component.</p>

<p>Messages may look like one of the following</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>Error 'Bean class [org.apache.servicemix.components.file.FileWriter] not found'
</pre>
</div></div>
<p>or&nbsp;</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>java.lang.ClassNotFoundException: org.quartz.SimpleTrigger
</pre>
</div></div>
<p>First extract the package name from the error message, so <em>org.apache.servicemix.components</em>
respectively <em>org.quartz</em> for the above examples.</p>

<p>Now, you have to choose the appropriate procedure:</p>
<ul>
	<li>Build the class / project. "One or two lines of error messages" above gives some
hints.</li>
	<li>Add the required library to the classpath like stated above for "Add Classpath
Variables". Look in the Maven repository for a folder matching the missing package. Sometimes
the top level domain (org, com, de and the like) is omitted, so package <em>org.quartz</em>
may be placed in folder <em>quartz</em>. Then choose a JAR containing executable
bytecode classes, so not the <em>quartz-1.5.1-sources.jar</em> but <em>quartz-1.5.1.jar</em></li>
	<li>Add the required library to the classpath like stated above for "Add External Folder".
The package indicates the location of the missing bean <em>FileWriter</em> is
<em>servicemix-components</em>, and as we need an executable file, the <em>target\classes</em>
subdirectory is where to look. Of course we shall proof that <em>FileWriter</em>
really is located here, so execute <em>dir /s FileWriter.class</em> in the given
directory and watch the output.</li>
</ul>


<p>Redo this until no class/JAR is missing any more.</p>

<p>See also <a href="/confluence/display/SM/3.+Installation#3.Installation-Missinglibraries">User's
Guide: 3. Installation, Troubleshooting</a>.</p>

<h3><a name="ImportingServiceMixintoEclipse-ProjectswithfailingbuildinEclipseworkspace"></a>Projects
with failing build in Eclipse workspace</h3>

<p>The first line of java classes in projects with failing build will look like this:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>package ${packageName};
</pre>
</div></div>
<p>Reason for the problem is Eclipse which considers the .java files as classes to compile.&nbsp;
In the case of archetypes, they are just resources to be bundled, and there is no real code
to compile.&nbsp; To tell Eclipse to not compile these archetype files, one may add an
exclusion pattern to the source folder in Eclipse's build path configuration (see screenshot).
This has to be done manually every time one imports the projects as the maven eclipse plug-in
cannot generate this information in the .classpath files automatically. For ServiceMix 3.0,
the change has to be applied in three Eclipse projects: servicemix-binding-component, servicemix-jsr181-annotated-service-unit
and servicemix-service-engine.</p>

<p><img src="/confluence/download/attachments/39121/archetype-build-path.png" align="absmiddle"
border="0" /></p>
     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/SM/Importing+ServiceMix+into+Eclipse">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=39121&revisedVersion=28&originalVersion=27">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/SM/Importing+ServiceMix+into+Eclipse?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message