How to configure MuleSoft with Maven? - java

I am trying to create my first MuleSoft application using Maven. I have used CMD to confirm that both Java and Maven are installed. I've also configured my environment variables.
I then open the MuleSoft Anypoint Studio, and create my first named "mulesoft-sample" I select to use Maven, and leave all default settings as they are.
Once I click finish, the Console begins to download a number of files
These continue to be downloaded until after it would seem the near end of the files, it throws an error:
There was an error running the studio:studio goal on project mulesoft-sample
In Console, I see the errors listed below.
I was originally trying to use the latest version of Maven (3.5.0). However, I found a video tutorial that said 3.3.9 was a verified version for MuleSoft. So I thought perhaps the newest version wasn't supported and instead used 3.3.9. However, it is still failing. I've also tried changing the environment variable to other options, such as going straight to \bin, rather than the complete directory (taking shots in the dark here). Unfortunately, nothing has worked and I'm running out of option.
Can anyone tell me why I'm getting these errors, and my build will not succeed? How to correct the error?

In anypoint studio go on windows>prefernces.then click on java>installed JREs. and add your Java JDK folder and note that only JDK, not JRE. then you can test your maven

This error occurs when the right java is not pointing with Anypoint Studio . In the studio navigate to windows > preferences the search java. Make sure jdk is selected and not jre . If still problem continues try updating your java and reinstalling maven .

Download the latest maven on your local machine, then goto anypoint
studio windows->preferences->anypoint studio->maven
provide the maven path and click Test Maven configuration(green
check mark obtained if the URL is properly provided)

Mule Maven Plugin configuration.
1.1. Use mule mule-app-maven-plugin to build the application.
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-app-maven-plugin</artifactId>
<version>${mule.tools.version}</version>
<extensions>true</extensions>
<configuration>
<copyToAppsDirectory>false</copyToAppsDirectory>
</configuration>
</plugin>
No need for additional Mule Maven plugins.
This is the default mule plugin set when creating your Mule project on AnyPoint (AP) Studio.
1.2. Make sure you set flag copyToAppsDirectory to false.
This flag is set to true by default so you must change it manually.
Maven Dependency Plugin Configuration.
2.1. Now we need to add a plugin to copy the generated artifact to the MULE_HOME/apps directory, i.e. to deploy the application to the standalone local mule server.
We will use the maven-dependency-plugin.
Just add these plugin after the mule maven plugin section in your application pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>deploy</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.mule.support.ba</groupId>
<artifactId>bonmarche-case-00145615</artifactId>
<version>1.0.0</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>C:/mule-home/apps</outputDirectory>
<destFileName>bonmarche-case.zip</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
2.2. Update the attributes within the tag (in grey) with the corresponding values on your environment.
2.3. As you see in 2.1, we are configuring the deployment to apps folder on Maven 'deploy' phase. You may choose a different phase to copy the artifact, but it must be bound to any phase after the package phase, so that the artifact exists in the repository.
Disable the default execution of Maven Deploy Plugin to prevent deploying the generated artifact to an external repository. This may be changed depending on your project needs.
Add this plugin after maven-dependency-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
Build your application and verify the generated ZIP file is copied to MULE_HOME/apps directory.
$> mvn clean deploy

I have faced same issue and got resolved by changing the JRE to JDK in preferences==>java==>Installed JRE's there change to JDK and restarted the any point studio. This resolved the issue to me.

Related

Plugin 'org.apache.maven.plugins:maven-gpg-plugin:3.0.1' not found

I've come across a project with a pom.xml file that contains the following
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
So, this pom.xml file contains what is suggested in the documentation.
But my IntelliJ IDE is telling me
Plugin 'org.apache.maven.plugins:maven-gpg-plugin:3.0.1' not found
I tried to update the Maven indices, but this did not fix the issue.
I can still do mvn clean install (provided I comment a section related to the documentation, but this is another, I think unrelated, issue).
Of course, I never used this plugin and I don't know what maven-gpg-plugin actually does (well, I think it's used for signing software). I just wanted to run this project that I found, but, at the same time, I would not like to run it with these errors.
The documentation of this plugin explains that gpg should be on the path.
Signs all of a project's attached artifacts with GnuPG.
You need to have previously configured the default key.
gpg also needs to be on the search path.
So, I realised that I had not installed manually GnuGP, and so that I didn't probably have gpg on the path. So, I thought I had to install it first, and that's what I did.
Here are the instructions on how to install it.
I am on a mac, so I tried to find a brew formula to install it - here it is. So, I did brew install --cask gpg-suite (and I have now gpg on the path), but this did not solve the problem.
Why am I having this problem, and how can I solve it?
try "Invalidate caches & Restart"!!

How to link StepDefination classes from Classpath (jar) in Cucumber IntelliJ Plugin

I would like to use existing step definition classes coming from maven jar dependency.
My cucumber tests works if ran from Runner Class (with glue to packages) & mvn CLI. But the
problem is with IntelliJ Cucumber plugin for the steps which are coming from jar. In feature file steps that I am using from the jar are shown as "Undefined step reference:...". I am not even able to run directly from feature file.
Is there a way I can configure cucumber plugin to use stepdefinations from classloader/jar?
Posting the solution worked for Me:
Use IntelliJ 2020.1 +
In cucumber run configuration : select jar manifest for classpath
Deploy the Jar with source jar as well to Nexus as below
You can simple do this by adding maven-source-plugin plugin to your build
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
In other project add dependency and confirm source is downloaded from repo
File -> Project Structure -> Libraries -> Select the Artifact -> Sources , Make sure it's not in red.
Update IntelliJ to use latest version, for me IntelliJ version 2019 did not work but 2020.1 was able to find the step definitions.
PS: I use Java8 with Lambda exp and I can confirm it works.
Updating Intellij from version 2019.3 to 2022.2 solved the issue without changing anything else.
My project is in Java 8

IntelliJ IDE 2017.3.2 Maven Project packagingexcludes

I have a maven project that is going out to tomcat using a exploded war build in development. I have the following entry in my pom to exclude certain files for any non development environments:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>web</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
<webXml>web/WEB-INF/web.xml</webXml>
<packagingExcludes>
WEB-INF/classes/application.properties,
WEB-INF/classes/proxool.xml,
WEB-INF/classes/log4j.properties,
WEB-INF/classes/wetemplates/**
</packagingExcludes>
</configuration>
</plugin>
The packaging excludes are being used by intellij and excluded from my local development build and breaking it. I have been having to comment this block out in development for the environment to function correctly. How can I resolve this so that these are not excluded in my development environment?
You can use maven profiles to configure the build in such way that the Intellij build will use one given profile and the Maven/external build will use another profile.
Take a look at here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Does the POM file configuration overwrite the default settings of Spring Tool Suite configuration?

After checking this link No Compiler is provided in this environment
I observed that POM file configuration is overwriting STS default settings. This might be the reason whenever project is run on server, it is generating the error as mentioned in above link. This might be the code which is overwriting the STS default configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
This is a feature of the Maven support in Eclipse (which is also included in STS). It automatically maps your JDK version setting in your pom file to the compiler settings in Eclipse/STS. Otherwise you would end up having the IDE compile for a different JDK version than your Maven build - which would be a bit strange.

Maven won't run my Project : Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec

I can't run the Maven Netbeans JavaFX example :
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) onproject mavenproject3:
Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e
switch. Re-run Maven using the -X switch to enable full debug logging.
My POM looks like this :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.huw.almexoffice.client</groupId>
<artifactId>almex-office-client</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Almex Office Client</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.huw.almexoffice.client.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Does anyone know why this is happening?
And if not, does anyone know how to get Maven running with the -e or the -X switch via Netbeans? I assume it is via a right click on the POM and then run goal then entering something in the textfield there.
This error would spring up arbitrarily and caused quite a bit of trouble though the code on my end was solid.
I did the following :
I closed it on netbeans.
Then open the project by clicking "Open Project", selecting my project and
Simply hit the run button in netbeans.
I would not build or clean build it. Hope that helps you out.
I noticed another reason why this happens. If you moved your main class to another package, the same error springs up. In that case you :
Right Click Project > Properties > Run
Set the "Main Class" correctly by clicking "Browse" and selecting.
I faced the same issue. When I tried to run the project from IDE, it was giving me same error. But when I tried running from the command prompt, the project was running fine. So it came to me that there should be some issue with the settings that makes the program to Run from IDE.
I solved the problem by changing some Project settings. I traced the error and came to the following part in my pom.xml file.
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
</execution>
I went to my Project Properties > Actions Categories > Action: Run Project:
then I Set Properties for Run Project Action as follows:
runfx.args=-jar "${project.build.directory}/${project.build.finalName}.jar"
Then, I rebuild the project and I was able to Run the Project. As you can see, the IDE(Netbeans in my case), was not able to find 'runfx.args' which is set in Project Properties.
what's happening? you haven' shown much of the output to be able to decide. if you are using netbeans 7.4, try disabling Compile on Save.
to enable debug output, either run Custom > Goals... action from project popup or after running a regular build, click the Rerun with options action from the output's toolbar
I am a beginner in Maven - don't know much about it.
Carefully check on your input i.e. file path in my case.
After I have carefully check, my file path is wrong so it leads to this error.
After I fixed it, it works magically lol.
A solution which worked in my case is:
1. Go to the module having Main class.
2. Right click on pom.xml under this module.
3. Select "Run Maven" -> "UpdateSnapshots"
Had the same problem, I worked around it by changing
${java.home}/../bin/javafxpackager
to
${java.home}/bin/javafxpackager
Had the same problem after installing oracle jdk on Ubuntu 13.10 x64.
I've done the following steps, not sure which one helped. I think that at least 2 and 3 are necessary.
Deleted Netbeans 7.4 and reinstalled it from oracle's site.
Installed plugins for maven, ant and java that may be related to the project.
Deleted .nbproject folder - after that the project was considered a maven project.
Also, after that, I've found that the project runs, but exits with exit code 1 because I didn't supply the command line parameters for it. And the builder considers it is an error. So, look carefully for the output and see if the program actually starts.
Maven needs to be able to access various Maven repositories in order to download artifacts to the local repository. If your local system is accessing the Internet through a proxy host, you might need to explicitly specify the proxy settings for Maven by editing the Maven settings.xml file. Maven builds ignore the IDE proxy settings that are set in the Options window.
For many common cases, just passing -Djava.net.useSystemProxies=true to Maven should suffice to download artifacts through the system's configured proxy. NetBeans 7.1 will offer to configure this flag for you if it detects a possible proxy problem. https://netbeans.org/bugzilla/show_bug.cgi?id=194916 has discussion.
I solved this issue with right click on project -> Set as Main Project.
Netbeans needs to be able to index the maven repository. Allow it to do that and try again. It was giving me the same error and after it indexed the repository it ran like a charm
Try to run Maven from the command line or type "-X" in the text field - you can't break anything this way, at the worst, you'll get an error (I don't have Netbeans; in Eclipse, there is a checkbox "Debug" for this).
When running with debug output enabled, you should see the paths which the exec-maven-plugin plugin uses.
The next step would then be to copy the command into a command prompt or terminal and execute it manually to see if you get a useful error message there.
Restart Netbeans & it solved my problem.
Im new to java hibernate but i could solve this problem, this is how i did it :
I was working with hibernate and maven project.
First you have to put persistence.xml under project directory, then add jdbc manually.
Maven couldn't download my dependency so i added it manually.
In the persistence.xml in design jdbc connection add it manually ps: i work with netbeans good luck
For me, the clue was the "org.codehaus.mojo:exec-maven-plugin:1.2.1:exec".
The only place this was referenced was in the "Run project" action under Project Properties=>Actions.
When I changed this action to match the HelloFXMLWithMaven sample project (available in Netbeans 11.1):
"clean javafx:run"
then executing the Run goal was able to proceed.
Note, I also had to update the pom file's javafx-maven-plugin to also match the sample project but with the mainClass changed for my project.
Rohith H.Y Solved this problem
I noticed another reason why this happens. If you moved your main class to another package, the same error springs up.
In that case you :
Right Click Project > Properties > Run
Set the "Main Class" correctly by clicking "Browse" and selecting.

Categories