Eclipse E4 application does not build correctly - eclipse-rcp

I have an E4 application that contains two different plugins.
The second plugin holds all my shared models and those models are used in my first plugin.
When building and starting the application using Eclipse run functionality everything works fine. All the classes in the second plugin are found and use by the first plugin.
Now when I export the full application into an executable. The export itself doesn't give any errors but when starting my application it throws errors that the classes in the second plugin cannot be found. When I check the exported jar of the second plugin I can only find the source code in the jar, not the builded class files itself.
Are there some steps to also include the class files to the second plugin jar?
My build.properties of my second plugin looks like:
source.. = src/
bin.includes = META-INF/,\
libs/hibernate-c3p0-5.1.1.Final.jar,\
libs/hibernate-commons-annotations-5.0.1.Final.jar,\
libs/hibernate-core-5.1.1.Final.jar,\
libs/hibernate-java8-5.1.1.Final.jar,\
libs/hibernate-jpa-2.1-api-1.0.0.Final.jar,\
libs/lombok.jar,\
libs/logback-core-1.1.7.jar,\
libs/slf4j-api-1.7.21.jar,\
libs/jboss-logging-3.3.0.Final.jar,\
libs/jta-1.1.jar,\
libs/javassist-3.21.0-GA.jar

Assuming you have code in a source directory you need to have a . in the bin.includes to include that code in the build:
source.. = src/
bin.includes = META-INF/,\
.,\
libs/hibernate-c3p0-5.1.1.Final.jar,\
..... other libs ....
The build.properties is only used when doing the RCP build so you don't get an error for this when you run your RCP from within Eclipse.

Related

Trouble running jar file created by Eclipse

I exported my Eclipse project as a runnable Jar file, added a manifest, as well as the appropriate class files with the command:
jar cfm JarFile.jar manifest.txt *.class
However, when I try to run the jar file with
java -jar JarFile.jar
I get the error that it "Could not find or load main class" etc. etc.
The structure of my manifest.txt file looks like this:
Main-Class: EclipseProjectName.src.packagename.mainclassname
(With a carriage return at the end)
Is something wrong with my manifest file? If not, what may be the reason that the main class cannot be found?
Thank you!
The manifest file extension should be .mf i.e manifest.mf. See here for jar file specification
Suggest to use fat jar eclipse plugin for exporting java projects as runnable jars.
Edit
Correct the content of manifest.txt as shown below
Main-Class: EclipseProjectName.src.packagename.mainclassname
project name and src are not required. Refer this
The entry in the META-INF/MANIFEST.MF entry in the finished jar file should be
Main-Class: packagename.mainclassname
and should correspond exactly to
/packagename/mainclassname.class
in your jar file (or jar file_s_ if you use Class-Path too).

preference extension package to jar

http://www.eclipse.org/articles/article.php?file=Article-Preferences/article.html did somebody see this paper? and I executed the example, it is run as eclipse application successfully, however when I packaged it to jar and pushed the jar package to eclipse's plugin directory , there was no effect in eclipse, thanks for your anwser
You don't seem to have the plugin.xml (and possibly other things) in your build.properties. A more or less standard build.properties for a plug-in would be:
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
plugin.xml
OSGI-INF can be left out if you don't have that folder.

OSGi NoClassDefFoundError when running outside of Eclipse with my Bundle

I have an application made up of multiple bundles. Inside eclipse it is working perfectly. When I export it as a product it was working perfect but something has changed and I can't work out what.
Now when I export my bundles, at runtime I get NoClassDefFoundError. The Error is in one of my bundle's activator and the class it is unable to find is in another bundle. A common bundle.
When I try to start the bundle I get the exception
Caused by: java.lang.NoClassDefFoundError: com/ardor/common/util/Systems
This class is in another one of my bundles com.ardor.common.
At the console when I inspect this bundle with the "bundle" command I get
Exported packages
com.ardor.common.util; version="0.0.0"[exported]
I'm stuck for ideas :(
When trying to remove compiler warnings I removed from the build.properties
output.. = bin/
with out this the bundle contains no class files
build.properties
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

NoClassDefFoundError in Eclipse when adding project in build path

I am receiving an NoClassDefFoundError in Eclipse when I try to run my project.
My Project looks like this:
JavaProject: BulkAdmin
- src
- com.mycompany.bulkadmin.SDK.util
- Login.java
Dynamic Web Project: JSPTesting
- src
- com.mycompany.bulkadmin.jspController
- Controller.java
- WebContent
- index.html
- execute.jsp
This is the control flow:
index.html loads
index.html has a form that redirects to execute.jsp
execute.jsp takes the info returned in the form and makes a static call to Login.java
execute.jsp prints the results of the call
Controller.java uses Login.java. I was receiving compilation errors. To resolve them I did this:
Right click on JSPTesting -> properties
Choose java build path on the left bar
Choose projects tab
Click add
Choose BulkAdmin (Project)
I am not sure why but now when I am getting a NoClassDefFoundError. I have done some googling. I think that this means that I have messed up my classpath somehow but I am not sure how to resolve this.
java.lang.NoClassDefFoundError: com/myCompany/bulkadmin/SDK/util/Login
at com.myCompany.bulkadmin.jspController.Controller.process(Controller.java:44)
at org.apache.jsp.execute_jsp._jspService(execute_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)
Other information:
I am using tomcat (in Eclipse) as my server
The exception shows up in the browser and the eclipse console
execute.jsp is a JSP
It seems like there are many similar questions to this on SO. I have read about 15 of them and tried various things however I think that my question has a different solution. I can provide more information.
Rightclick your dynamic web project, go to Properties > Deployment Assembly and add the dependent projects there. This way they will end up as JAR in /WEB-INF/lib, exactly there where you want it to be.
In Eclipse versions older than 3.5 you need to go to Properties > Java EE Module Dependencies.
See also:
ClassNotFoundException when using User Libraries in Eclipse build path
Difference between Deployment Assembly and J2EE Module Dependencies in Eclipse
The NoClassDefFoundError indicates that a class that was available during compilation is no longer available at runtime. Your problem is that the com/myCompany/bulkadmin/cSDK/util/Login class is available in the compilation classpath (in Eclipse via the Project reference you added to the build path) but not in the runtime classpath (Tomcat, which has no idea how to find this class).
You need to add the BulkAdmin project to the web-app class path when deployed on Tomcat as well.
One way to do this would be to export the BulkAdmin project as a JAR and put it into the WEB-INF/lib directory of your JSPTesting project.

How do you ensure a Utility Projects library dependency gets packaged in the final EAR in Eclipse Galileo?

I have a 'Utilty Project', and an 'EAR Project' that includes that 'Utility Project'. All the classes from the 'Utility Project' end up being packaged as a JAR and placed within the 'lib' directory of the exported EAR, for example:
EAR.ear
META-INF
MANIFEST.MF
lib
utility.jar (which expands to):
META-INF
MANIFEST.MF
com
acme
Foo.class
Bar.class
However, the 'Utility Project' relies on a library (freemarker.jar) that has been added to the build path using 'Properties > Java Build Path > Libraries'. All I want to do is to get freemarker.jar added to the EAR as follows:
EAR.ear
META-INF
MANIFEST.MF
lib
**freemarker.jar**
utility.jar (which expands to):
META-INF
MANIFEST.MF
com
acme
Foo.class
Bar.class
By searching around within Eclipse I've found 4 potential avenues for achieving this, none of which have worked. If someone can just cut to the chase and tell me what I should actually do, that would be great. But just in case, I'll iterate them here:
From the 'Utility Project' Properties:
If I click 'Java Build Path > Order and Export' and select 'freemarker.jar' for export, the jar does not end up in the EAR file at all.
If I click 'Java EE Module Dependencies' and select the 'freemarker.jar' library as a dependency, it says:
This JAR is a bundled library of an
EAR project and is supposed to be
packed in the EAR's library directory.
It conflicts with the manifest class
path dependency you are trying to
create. If you create this dependency,
the JAR will be packed in the root
(not library) directory of the EAR.
Are you sure you want to proceed?
From the 'EAR Project' Properties:
If I click 'Java EE Module Dependencies > Add JARs...' and navigate to the 'freemarker.jar', and make it a dependency, it gets added to the root of the EAR:
/freemarker.jar
If I do the same as above, but check the 'In Lib Dir' checkbox, it gets added into the lib folder, but contained within another lib folder:
/lib/lib/freemarker.jar
Thanks.
I've managed to solve this problem. In the Problems window I was getting the following warning:
Classpath entry /utility-project/lib/freemarker.jar will not be exported or published.
Runtime ClassNotFoundExceptions may result.
What I tried, at a whim, was to use the Ctrl-1 key combination I've been using to get quick fix solutions for my source code. It turns out this also provides quick-fix solutions for for the given errors and warnings. I chose the first of the two options:
Mark the associated raw classpath entry as a publish/export dependency.
and my problem disappeared!
Bizarrely, all this seems to have done is to cause the 'freemarker.jar' lib to be selected in the 'Java EE Module Dependencies' properties dialog, which I was doing myself anyway. This may be an Eclispe bug!
#MonoThreaded: After using the quick fix > Mark the associated raw classpath entry as published/export dependency, if you right-click on the project > properties > depolyment assembly you will notice that eclipse has added a new entry, something like source: /freemaker.jar, deploy path: ../lib. You can do that too, by selecting Add > Java Build Path Entry.