Mule ClassNotFoundException for class existing in a library in the class path - mule

I have a class in a Mule application which resides in a jar of a third party library. The library gets included in the lib folder after the project builds so it is definitely in the classpath. The class is then used in a Mule component. The applications deploys successfully in AnyPoint Studio'sembedded server. However, when the Mule component is processing data, Mule complains that it can't find the class.
As soon as the line with the following code snippet is encountered it throws the NoClassDefFoundError.
populator.put(ScanType.MRI,container);
Here is a portion of the stacktrace:
Root Exception stack trace:
java.lang.ClassNotFoundException: com.tcfg.utils.defn.Populator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at org.mule.module.launcher.FineGrainedControlClassLoader.findClass(FineGrainedControlClassLoader.java:175)
at org.mule.module.launcher.MuleApplicationClassLoader.findClass(MuleApplicationClassLoader.java:134)
at org.mule.module.launcher.FineGrainedControlClassLoader.loadClass(FineGrainedControlClassLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
I also know that this is the only instance of the class in the whole project when I use a tool to search the entire lib folder for instances of the class. This is definitely not a situation of multiple versions of the class or of other classes existing in one of the jars with a similar name. What could be the cause of this and how can I resolve it?

Even though if you add the jar in lib folder you need to manually add that jar to your class path.So, that it will be available.

They are 2 possibilities here one is there might be a need of OS specific library to be downloaded and configured in Anypoint Stduio in Run configurations like for SAP we need to point it to the DLL which windows will refer to. Giving below an example.
-Djava.library.path=C:\Users\adm-snandu\AnypointStudio\workspace\
For most of the Class Notfound errors you need to make sure the maven dependency is given in the pom.xml which takes care of downloading all the relevant libraries and referring to them during run time.

Related

calling java component with multiple java classes from Mule

I am using Anypont Studio 5.3.0 and server runtime 3.7.0. I want to invoke a main() method from my component. Application is developed using Maven, SpringBoot and JPA. It sits in the jar file and have the following structure.
com
package
Application.class (with main method)
another package
Other classes
lib
other jars
META-INF
persistance.xml
MANIFEST.MF
Org
springframework boot loader and other spring classes.
when file arrives with file pattern that I detect with mule polling component I would like to invoke Java component in mule flow that has main class and all the supporting classes.
Thanks,
David
did you mavenize your Application? If yes, you can add that as a dependency in your mule project pom, which is also mavenize. But you need to make sure that the jars are added in your maven repository i.e. execute first "mvn clean install" to your java application. Otherwise, add the jars in you build path. When you are able to do those, you can create a spring bean or create a java component in mule where they could call your class with main() method.
I never came across this kind of production scenario where there is a need to call main method of java class in enterprise application. Are you sure you have only main method to access other classes, it should have initialize, spring way of injection etc. Simple answer to you question, create a mule java component and override onCall method to call Application(class).main. I will never do this kind of stuff [for sure it will give more problems based on what is being written in main method]. In general we will use main method invocation in desktop application. if possible work on (or let the application team to work on) jar file to have better initializing options

Can't get a Mule flow-reference to recognize imported resource (external flow) from an external jar

I cannot get a flow or a sub-flow that is in an external Mule application to display in the Flow name: drop-down of the Flow-Reference component of another project (my main project).
I have closely followed the example here from the MuleSoft documentation regarding the sharing of fragments.
It all works as per the tutorial, except I cannot get the external flow/sub-flow's name to appear in the drop-down of the main project's Flow-Reference component.
All of the maven stuff is fine.
The dependency is properly coded in the main Project's POM.
The jar displays in the Referenced Libraries.
The jar contains the application file I need (common-mule.xml).
If I force an error, by temporarily changing the name of import
resource, it correctly throws a not-found message. So, I know the
classpath is finding this external resource just fine.
BUT... when I double-click my Flow-Reference in the main project, I am not able to see the external flow in the flow names drop down.
Am I wrong about how this should work?
I tried doing the same thing and it is possible using the XML editor. My findings were -
If you are using maven the referenced project must be packaged as a jar and must be available on the referencing project's classpath.
You can refer to these for linking details:
https://docs.mulesoft.com/mule-user-guide/v/3.7/sharing-custom-code
https://docs.mulesoft.com/mule-user-guide/v/3.5/sharing-custom-configuration-fragments
After importing the xml as resource, you can simply type in the flow name in flow-ref and use it. It will give an error in the studio UI but the project is successfully built and the referenced flow is used as expected at runtime.
Its the bug with Studio UI only.
Make sure to use import of the flows in jar in your main project.
<spring:beans>
<spring:import resource="classpath:source_flow.xml"/>
<spring:import resource="classpath:global-config.xml"/>
</spring:beans>
Studio doesn't load elements from configuration files in JARs located on the build-path, so what you're trying to do is impossible (at least, currently).

mule anypoint studio class not found exception

If I run the application in server, which is working fine, but If i run application in anypoint studio doesn't run. Here is the error message for loading oracle driver.
error message:
2015-02-04 11:18:34 WARN DriverManagerDataSource:107 - Could not load driverClass oracle.jdbc.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
I have placed all jdbc and other jars under studio->project->properties->libraries.
This is caused by the Studio's classloading policies. The workaround is to copy the JDBC Driver .jar to ${studio.home}/plugins/org.mule.tooling.server.${mule.version}.ee_${mule.version}.${release.date}/mule/lib/user
Hi there actually that's kind of a hack :P though it works.
The more proper way to deal with this is, when coding your application (that's why one should use Mule Studio), to place the jars like drivers in a particular folder, like a /lib in the root of you project.
Then add these jars to the classpath.
I know what you did is the way it should be done when running on Mule stand alone in order to share such jars but try this one if you can ;)
I was also facing the same problem. As the application runtime fails to locate the jdbc driver jar in classpath So It is unable to load the same.
the simple and easiest way to handle this error is just put your lib folder containing the ojdbc jar file inside the app resource (src/main/app) of the project. During the building of project it will automatically be place in classpath.
I have tried the same approach and It works for me.
Hope this helps.
The way I fixed the problem was removing the .classpath / .project files from my project root folder. I re-imported the project and then I saw a bin folder created. I removed this bin folder then right-click on the project -> Refresh and then Run As -> Mule Application.

Invalid ejb jar: it contains zero ejb.

I have 2 modules: ejb and war, and ear module, that contains them. Modules build successfully, but when I try to deploy ear to glassfish, I recieve this error:
glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=17;_ThreadName=Thread-2;|Exception while deploying the app [EarModule] : Invalid ejb jar [BackEnd-1.0-SNAPSHOT.jar]: it contains zero ejb.
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean.
2. EJB3+ entity beans (#Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (#Stateless, #Stateful, #MessageDriven, #Singleton), please check server.log to see whether the annotations were processed properly.|#]
I really don't know what to do, I've found a lot of questions like mine, but there was no solution.
I understood, what was wrong. The problem was in run configurations, I'm using Intellij Idea and in run configurations there was build and make before run of my ear module. I removed this and after maven install it deployed successfully.
You have to add an EJB into your WAR or EAR file. Just Create a new Class and annotate it with #Stateless
I know this is very build specific and it uses Netbeans instead of the OP's IDE but because I was lead here and this will likely be useful to some users:
I had the following build:
Netbeans Enterprise Application with Maven
Glassfish 4.1
Java EE 7
I had tried migrating from a previous non-maven enterprise application and the clone didn't quite work the way I expected, there was some old ejb jars lying around that I deleted.
I had done quite a few things to fix it:
Ensure theres no ejb jars lying around that shouldn't be there. Ensure that you don't have accidently have the ejb module jar included more than once as this can result in the same error too (Manually deploying the ear and deployment through netbeans sometimes gave me different errors).
I used the #Remote interface on my EJB applications. Now you should not be importing your EJB into your War, you should use the annotations correctly as described https://docs.oracle.com/javaee/7/tutorial/ejb-intro004.htm
(This is more of a note) When you update any of your war or ejb, clean and build them before cleaning and building your ear (sounds funny right?).
If you are using interfaces for your session beans then you should put them in a separate jar, make a new project maven > java application. Do the same thing with your persistence entities. Add these as dependencies to both your ejb and war project.
This doesn't relate to me in particular but you should have at least 1 #stateless (or I think #stateful) annotation in a java class inside your ejb module for it to run (for the module to be considered an ejb).
I likely had to do a few more things that I forgot but if you still run into issues comment below and I'll try to update.
Just try to build & install your project using Maven , and then , deploy it in glassfish ( do not run your project directly from your IDE )
I encountered this problem as well. It occurred when I had imported a new EJB project into my Eclipse workspace. The project didn't have a reference to the Glassfish libraries then, since it was not yet included in the EAR deployment assembly.
Upon saving the Bean file, the IDE automatically imported javax.inject.Singleton instead of javax.ejb.Singleton. This made the code compile without warnings, but throw the same error as in the original post.

Why can't I override a javax.validation.ValidationFactory when deploying mule app to CloudHub?

I'm trying to load javax.validation.ValidationFactory from a library containing the javax.validation package (retrieved from jboss.org). I see that the library is included when I export the Mule Studio Project to a zip file, so I'm assuming it is also exported when I deploy the application to CloudHub (all of my other 3rd party jars have deployed with minimal trouble).
Unfortunately, I get a ClassNotFound error. I've tried overriding the class definition using loader.override=javax.validation.ValidatorFactory in the mule-deploy.properties, but I get an error in CloudHub saying that I can't override a system package. I thought the above override would only override the given class, asking CloudHub to look within the deployed application for a class definition rather than from the CloudHub supplied libraries.
As a side note, searching through a copy of the Mule Standalone server, I don't see javax.validation.ValidationFactory anywhere. Can anyone tell me why I can't force the load of this one class using loader.override?