Not able to start Tomcat for maven project in Eclipse I am getting:
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
while starting tomcat.
the same is working outside eclipse(making the war and deploying in Tomcat)
Can any one suggest what to do?
My answer will be slightly off-topic but If I dare, I really recommend using jetty and using hot deployment in a separate process, not to launch it from within maven, but as a real server in /etc/init.d. Then you could deploy your app easily with an external script, activable from within eclipse, that will do a hot deploy of context in jetty.
It takes time to get this config but it's the fastest I have found and uses much less memory than using jetty within eclipse, and much much less than using tomcat. Hot deploy is also quite interesting in jetty.
You build cycle will look like
edit / save from eclipse
build / package through maven from eclipse (eclipse indigo is a charm for that)
deploy your app in jetty through a external tool script from eclipse.
Regards,
Stéphane
It has to do with tomcat looking for those classes in src/main/webapp/WEB-INF/lib, You can add the dependency plugin to your pom.xml like this.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory>
</configuration>
</plugin>
This plugin will copy all the pom dependencies to WEB-INF/lib and tomcat can find all the jars when you it out of workspace
Related
I have a Java/Maven project (POM-based) which builds and launches fine when using java -jar on the uber JAR produced by my Maven build on the command line, using the spring-boot-maven-plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.3.RELEASE</version>
<configuration>
<mainClass>com.company.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
The JAR is created (~100MB), and launches as expected.
However, I'm unable to launch this same application in Eclipse using the right-click -> Run As -> Java Application configuration on the main class I've defined in my POM. It's a Maven project, and M2E is up-to-date/refreshed, etc.
The error is:
java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.LoggerFactory
So clearly some dependency issues with the logging frameworks. However: My first head-scratcher was, why does this work in Maven using the CLI, and fail in Eclipse using M2E?
So I went and looked at the classpaths, and they seem identical. (Looking at the Maven Dependencies list in Eclipse, and the BOOT-INF directory contained in my uber JAR.) The interesting bits are:
slf4j-api 1.7.25
log4j-over-slf4j 1.7.25
logback-core 1.2.3
logback-classic 1.2.3
commons-logging 1.1.3
So, I debugged. I placed a breakpoint on NoClassDefFoundError, and captured this. Note that the debugger is paused on the thrown exception, and the watch expression in the upper-right is getClass().getClassLoader().classes, which is a Vector.
How is it possible that we're throwing on LoggerFactory, even though this very class is present in the current ClassLoader? Where should I look next?
Edit: Since it's causing some confusion, the class in which Eclipse has caught this error (Category.java) is not one of my classes. It's inside a dependency (see Eclipse titlebar) and as a result cannot be modified.
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
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.
If it possible to build java desktop application with embedded JVM? I do not need to depend on the end user having the right JRE installed.
I build my application for Windows with l4j maven plugin.
Googling does not give needed results. Maybe you someone know how to do it with maven o gradle, not by some another utility like Avian, ProGuard and etc. (Embed a JRE in a Windows executable?)
The Maven plugin for Launch4j lets you generate the Launch4j
executable as part of the Maven build process. It supports Maven 2.0.4
and Launch4j 3.x.
See here
This is a sample of the configuration that you can try to use:
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
...
<configuration>
...
<jre>
<!-- Specify path or minVersion or both. -->
<path>bundled JRE path (%VAR%)</path>
<bundledJre64Bit>true|false</bundledJre64Bit>
<bundledJreAsFallback>true|false</bundledJreAsFallback>
<minVersion>x.x.x[_xx]</minVersion>
<maxVersion>x.x.x[_xx]</maxVersion>
<jdkPreference>jreOnly|preferJre|preferJdk|jdkOnly</jdkPreference>
<runtimeBits>64|64/32|32/64|32</runtimeBits>
<!-- Heap sizes in MB and % of available memory. -->
<initialHeapSize>MB</initialHeapSize>
<initialHeapPercent>%</initialHeapPercent>
<maxHeapSize>MB</maxHeapSize>
<maxHeapPercent>%</maxHeapPercent>
<opt>text (%VAR%)</opt>
</jre>
...
</configuration>
</execution>
</executions>
</plugin>
I have a REST web service which I created previously and deployed in Tomcat7. I wanted to deploy it on Jetty, as advised in a previous question, I made a Maven project and copied my files there and configured the dependencies and I can run Maven install from eclipse successfully.
This is my build part in POM.xml:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<dependentWarExcludes></dependentWarExcludes>
<webappDirectory>
WebContent
</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
I followed instructions here to use maven jetty plug-in (I am not sure if this is required). The question here is how can I deploy my maven project in jetty from eclipse so that i can go to http:localhost:8080/myproject for example and see my project working?
EDIT:
The way I used to run the service on Tomcat was by right click on the project and click on Run As -> Run on server (which is configured in eclipse servers)
I am using eclipse Indigo, Maven 3 and jetty 8. Also I used jersey for the web service.
Here, you are mixing two different things:
Run your Web application using a Eclipse server plugin as Tomcat plugin for Eclipse.
Run your Web application using a Maven plugin as Jetty Maven plugin. There are also Maven plugins for Tomcat.
Having said that, take a look to this answer where it is described how to configure Eclipse to run Maven plugins (it could change depending on Eclipse version but idea would be similar)
Edited:
If you just want to run jetty from Maven, just use the following command line:
mvn jetty:run
But, in any case, I recommend that you indicate the Maven jetty plugin version in the pom file (Maven will warn you if you don't).
Edited 2
First, update your jetty maven plugin version:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.0.M2</version>
</plugin>
Second. You are working with two plugins, one for building the war file (maven-war-plugin) and another one for running your application on jetty (jetty-maven-plugin). Take in mind that jetty thinks your project has a standard maven project structure, it means, it will look for your web app content in /src/main/webapp but it looks like is not here. In your war plugin configuration, you specify that your web content is in WebContent, so tell jetty plugin that directory is there, as well as you are telling it to war plugin:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.0.M2</version>
<configuration>
<webAppSourceDirectory>/WebContent</webAppSourceDirectory>
<webXml>/over/here/web.xml</webXml>
<jettyEnvXml>/src/over/here/jetty-env.xml</jettyEnvXml>
<classesDirectory>/somewhere/else</classesDirectory>
<configuration>
</plugin>
See documentation. Of course, it is better to work with a standard maven project structure so you do not need to tell jetty where things are.