Can launch Spring Boot from Eclipse (STS) but not from CLI - java

I have a problem that I can't seem to resolve. I have no issues starting a Spring Boot application from Eclipse (Oxygen) with STS 3.9.2, from the Boot Dashboard:
However, when I try to run it from command line, I get an error that files are missing:
Exception in thread "main" java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:62)
at java.lang.Thread.run(Thread.java:748) Caused by:
java.lang.reflect.InvocationTargetException at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54)
... 1 more Caused by: java.lang.ArrayStoreException:
sun.reflect.annotation.TypeNotPresentExceptionProxy at
sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
at
sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
at
sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
at
sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at
sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at
sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.createAnnotationData(Class.java:3521) at
java.lang.Class.annotationData(Class.java:3510) at
java.lang.Class.getAnnotations(Class.java:3446) at
org.springframework.core.type.StandardAnnotationMetadata.(StandardAnnotationMetadata.java:68)
at
org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition.(AnnotatedGenericBeanDefinition.java:56)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:139)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:127)
at
org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:122)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:158)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:134)
at
org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:126)
at
org.springframework.boot.SpringApplication.load(SpringApplication.java:708)
at
org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:357)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
at se.itab.bos.admin.AdminServer.main(AdminServer.java:37) ... 6
more
I tried commenting out the following from my startup class:
#SpringBootApplication
#Import({
// AppConfig.class
// , ActiveMqServerConfig.class
// , MetricConfig.class
// , AdminConfig.class
// , SystemConfig.class
// , SystemMessageRouterConfig.class
// , CommandConfig.class
// , AdminMessageRouterConfig.class
})
public class AdminServer {
This solves the issue so that I can launch from command line, but I don't understand why. In my pom.xml I have every other module defined, in which these files are contained.
I am using Spring Boot Starter 1.3.5.RELEASE and Java 8.
Any help would be greatly appreciated.
UPDATED
This is my full pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>se.bos</groupId>
<artifactId>bos-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../bos-parent</relativePath>
</parent>
<artifactId>bos-admin</artifactId>
<packaging>jar</packaging>
<name>BOS Admin</name>
<properties>
<java.version>1.7</java.version>
<start-class>se.bos.admin.AdminServer</start-class>
</properties>
<dependencies>
<!-- operations: spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency>
<!-- operations: spring boot admin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<!-- application: bos -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-site</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-server</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-core</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-client</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-model</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bos-system</artifactId>
</dependency>
<!-- application: spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- test -->
<!-- -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
To start the project from command line, I run:
mvn clean install
java -jar target/admin.jar
After commenting out each import one by one, I also found that the problem stems from imported modules, but have not yet found why.
Running java -version from command line:
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
This is the same as what is used in Eclipse and what is in JAVA_HOME

Using mvn clean install will not produce the executable jar file for you, as this will not package the executable spring boot libraries and pom dependencies. It will only produce a jar file containing only your code.
Using the spring-boot-maven-plugin you need to execute the spring-boot:repackage goal and phase in order for the executable jar file to be appropriately packaged with the spring boot/pom dependencies and ready to be executed on the command line. i.e. run mvn package spring-boot:repackage and then run your application on the command line.
Full details on this can be found in the Spring Boot Maven Plugin Documentation and the spring-boot:repackage goal.
Note: It works in Eclipse because Eclispe has setup your classpath appropriately to reference the dependencies in your pom at compile and runtime, whereas your compiled jar file does not.

Related

Maven from command line: dependencies don't work

I used the following basic Maven command to generate a project:
mvn archetype:generate -DgroupId=it.maven.project -DartifactId=MavenExample -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
The project was correctly created and I could test the automatically generated App class without any problem with this instruction:
java -cp target/MavenExample-1.0-SNAPSHOT.jar:lib/* it.maven.project.App
Later on, I added some dependencies to the POM, obtaining the following file:
<?xml version="1.0" encoding="UTF-8"?>
<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>it.maven.project</groupId>
<artifactId>MavenExample</artifactId>
<version>1.0-SNAPSHOT</version>
<name>MavenExample</name>
<!-- FIXME change it to the project's website -->
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Finally, for testing sake, I modified the App class previously generated by Maven itself:
package it.maven.project;
import org.apache.commons.lang3.RandomStringUtils;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
System.out.println("Stringa generata casualmente: " + RandomStringUtils.random(16, true, true).toUpperCase());
}
}
A series of strange things happen:
even though more recent versions of dependencies are specified in POM, in .m2 folder the downloaded versions seem to be older (for instance I get 2.1 and 2.5 for commons-lang3)
the project is correctly compiled by instruction
mvn clean install -U
when I run again command to execute App, I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/RandomStringUtils
at it.maven.project.App.main(App.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.RandomStringUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Questions:
how is it possible that project compiles but then errors are returned at compiling time? Why the import in App is accepted but instruction:
System.out.println("Stringa generata casualmente: " + RandomStringUtils.random(16, true, true).toUpperCase());
generates an exception?
what should I correct/execute to allow my program to work and use correctly dependencies?
when you create a simple java project you define a set of dependencies in the pom but if you don't create a java archive file (ejb-jar or war) all the dependencies are not available at runtime if you run the jar compiled in the target directory.
There are two solutions:
Create a uber jar that include all your depenencies in your jar: use stackoverflow solution
when you run the jar from command line you have to add the dependencies to the classpath:
java -cp "/path/dependencies/dep1.jar;/path/dependencies/dep2.jar" -jar myApp.jar

Self-contained JavaFX 12 build with JDK 12 & Maven?

There are a lot of threads about JavaFX not being included with JDK 12/11, and that you need to have your own installation of JavaFX, but I found only this example of a modular installation without external download requirements :
https://github.com/openjfx/samples/tree/master/IDE/IntelliJ/Modular/Maven
Here is my pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<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>scheduler</groupId>
<artifactId>shop-solver</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>scheduler.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>com.jfoenix</groupId>
<artifactId>jfoenix</artifactId>
<version>9.0.8</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.21</version>
</dependency>
</dependencies>
I'm still getting this error when I try to run through the javafx:run plugin :
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --module-path
When I try to run from IntelliJ I get another error :
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0xd5599b7) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0xd5599b7
The project worked fine under JDK1.8 and JavaFX 2, here is a video of the error happening on the upgrade : https://puu.sh/E25JW/7ecdca26d7.webm
Again, the issue is that I'm trying to build all of this modularly, I want to be able to publish a repository with maven dependencies and maybe plugin or build directives, but do not want to have people who clone my repo need to install JavaFX externally outside of Maven. Thanks.

How to install the library Deeplearning4j with IntelliJ and Maven?

I'm trying to install the Deeplearning4j library ( https://deeplearning4j.org/index.html) but I don't understand how to use install the lib correctly with IntelliJ and Maven so that I can build a .jar file from it.
As long as I'm running the program from IntelliJ everything seems to work.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>DeepLearning</groupId>
<artifactId>deeplearning</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-core -->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-api -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native-platform -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.datavec/datavec-api -->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>MLPClassifierLinear</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I am not sure if everything is set up correctly because it's the first time I use maven.
When I run the maven install command and start the .jar file I get an error that says that a JNI error has occurred and a NoClassDefFoundError.
This is the exact error message:
Error: A JNI error has occurred, please check your installation and
try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/deeplearning4j/nn/conf/layers/Layer at java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at
java.lang.Class.privateGetMethodRecursive(Class.java:3048) at
java.lang.Class.getMethod0(Class.java:3018) at
java.lang.Class.getMethod(Class.java:1784) at
sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException:
org.deeplearning4j.nn.conf.layers.Layer at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 more
Can somebody explain me how to use maven correctly so I can build .jar files without getting errors?
Thank you :)
Simple recipe for getting most things done:
deeplearning4j-core, nd4j-native-platform, maven shade plugin
deeplearning4j-core gives you most dependencies people use on simple desktop.
nd4j-native-platform bundles all operating system native dependencies so you don't have to worry about multi OS deployments/binaries. This also makes sbt and gradle actually..usable since they can't handle classifiers.
maven shade plugin handles building the jar properly.
https://github.com/deeplearning4j/dl4j-examples/blob/94568e78e86c56807c03fe17d6a2f89f0b0df377/dl4j-spark-examples/dl4j-spark/pom.xml#L98
Also, please don't use the term "install". You aren't installing anything. You're setting up a set of libraries using a dependency manager. It's not installing in the sense of the OS like ruby and python tend to do.
Beyond that: Specific critiques about your pom. nd4j-native here is redundant. You don't need that. You only use nd4j-native if you are using snapshots or building from source.
Datavec-api isn't needed because it's already brought in by deeplearning4j-core. Please read up on maven transitive dependencies to understand how this works.
If you aren't sure on how any of these things get resolved, look at using
mvn dependency:tree

no native library found for maven plugin project

I want to integrate a leap motion app into Weasis Dicom Viewer.
Projects:
Weasis-maven-plugin -> where my leap implementation is
Weasis-framework -> dicom viewer
Weasis-launcher -> This is where I launch the Dicom viewer.
What I've done already:
have m2e with eclipse and added the LeapJava.jar to plugin project and set the location of the native library
installed LeapJava.jar into the .m2/repository folder so that mvn install on my maven plugin build succeeds
added into the pom.xml of maven-plugin
updated maven project
what doesn't work:
when i launch the application, I get no LeapJava in java.library.path
I've seen some other threads that says I need to manually add -Djava.library.path to the VM arguments. However, when I add that to the launcher run config in eclipse the library not found still exists. Should I be adding this somewhere? Any help is greatly appreciated.
This is my pom.xml for the weasis-plugin:
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>weasis-parent</artifactId>
<groupId>org.weasis</groupId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../../weasis-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>LeapPlugin</groupId>
<artifactId>UBC</artifactId>
<packaging>bundle</packaging>
<name>Tool panel sample [${project.artifactId}]</name>
<properties>
<bundle.symbolicName>${project.artifactId}</bundle.symbolicName>
</properties>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Service-Component>OSGI-INF/*.xml</Service-Component>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-ui</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.dicom</groupId>
<artifactId>weasis-dicom-viewer2d</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/sdk/LeapJava.jar</systemPath>
</dependency>
</dependencies>
When I add the "systemPath" I can still mvn install properly but when i run the launcher project now I get org.osgi.framework.BundleException: "Unresolved constraint in bundle"
UPDATE 1:
So right now this is what my pom.xml looks like
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no leapMotion-1.0.0 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at weasisTool.SampleTool$1.run(SampleTool.java:98)
Not sure if this is the actual solution.
But I added:
nativedependency-plugin in my pom.xml
made sure to do mvn package on the plugin project folder (this generated some files under target/ folder
added -Djava.library.path to the VM argument and it compiles and runs!

Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?

Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?
I'm not sure if I have to do this in 1 or 2 steps, but I want to compile my spring mvc (3) application and deploy to my local tomcat.
Right now I just mapped the RunAs -> Maven build to a 'compile' goal type.
I'm very new to do this so not sure how to setup build and deploy.
My pom.xml is:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>springmvc2</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springmvc2 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mod4j.org.apache.commons</groupId>
<artifactId>logging</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<build>
<finalName>springmvc2</finalName>
<filters>
</filters>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Inside Eclipse
Assuming you have the WTP (Web Tools Project) installed (which is part of the Eclipse IDE for Java EE developers distro) and you have the "Maven Integration for WTP" installed (which is an optional module of m2eclipse, you have to intall it explicitly), then your spring project should be recognized as a dynamic web project and runnable on a Server. In that case, just right-click on your project, go to Run As > Run on Server, select Manually define a new server and use the wizard to add your local Tomcat.
Outside Eclipse
You can simply execute:
mvn tomcat:run
This will run the current project as a dynamic web application using an embedded Tomcat server.
If what you want is really to deploy to your local Tomcat, then have a look at the tomcat:deploy goal.
Of course, you can always run these goals from Eclipse but I'd recommend to use the IDE support here (i.e. the WTP). This will be easier if you want to run your Tomcat in debug mode, etc.

Categories