Deploying spring project in tomcat - java

I created a sample Maven MVC project using my Spring tool suite but unable to deploy to tomcat.
The problem is when I right click the project and click "Run as" I don't see the "Run on server" option..
I tried changing the project to Dynamic web module after selecting the properties-project facets
but get the error, "Dyanmic web module 3.0 requires Java 1.6 or more"
How do I enable my project to run in Tomcat?

Have your Maven project compile for Java 1.6. Add this to your pom.xml:
<build>
<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>

Related

Migrate maven project in offline environment

I have created a web application in spring mvc and now i have to migrate the project to an offline machine but when i imported the project in my eclipse(offline) then it got stuck on "Importing Maven Projects" and also it is showing an error in my pom.xml file at tag :-
<plugins>
<plugin> // shows error over here
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
I also read something about mvn dependency:go-offline so I tried it but couldn't exactly understand that where it saves the dependencies?
So, is there a way through which i could import the project in the offline environment?
As pointed out by #Thomas, the only way to build a project which needs external dependencies with Maven is to copy the repository in the target environment. Build your project on an online environment, then copy your .m2 folder in the offline one. The build will then find all required libraries locally.
With mvn dependency:go-offline you tell maven to download all the needed plugin dependencies in your local repository.

Converting Eclipse dynamic web project to maven project with modules

so I just started a new project at work where I've gotten some code, really strange code...
So the project structure was as follows:
simple-java-project-1 ---> eclipse java project which holds some database-connectors
simple-java-project-2 ---> holds the logic of converting, formatting etc of the data, uses the connectors from project-1
dynamic-web-project --> just gets the jars from project1 and project2 and offer's a websocket api to send this data etc.
I would like to convert this mess to a well structured maven project. So I created a master maven project with this pom:
......bla bla bla....
<modules>
<module>the-connectors</module>
<module>the-logic</module>
<module>the-dynamic-web-module</module>
</modules>
<dependencies>.....</dependencies/>
And the modules as well. I added the dependencies needed to them.
So now the hard part I didn't get : How can I achive that the whole project is deployed to the local tomcat and runs?
The web.xml and /WEB-INF/ stuff is in the "the-dynamic-web-module" module for now,...
Any ideas or hints?Thanks in advance.
You should add the tomcat7-maven-plugin to your the-dynamic-web-module:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<uriEncoding>UTF-8</uriEncoding>
<systemProperties>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
After building and installing the 2 other modules (mvn install), go to the-dynamic-web-module and launch mvn tomcat7:run. Then with your browser, go to localhost:8080/ and you should get your app.

Maven War Plugin Websphere

I am trying to get a Rational Application Developer project to run on a websphere server. I am trying to get the maven-war-plugin to work. However, when trying to start the server, websphere can not find the UI Files. I have my plugin here:
<build>
<outputDirectory>${project.basedir}\WebContent\WEB-INF\classes</outputDirectory>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webXml>/WebContent/WEB-INF/web.xml</webXml>
<webappDirectory>WebContent</webappDirectory>
<source>/codeCoverageUI2/src/</source>
<encoding>utf-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
I feel the issue is with my webappDirectory but I do not know what else to put it to, besides the location of all my UI files.
Anyone have some insight?
I am assuming you are using WebSphere Classic V8 or earlier?
What we recommend because when developing a project in RAD/WDT, WAS Classic requires building the project in a "Single Root" structure. Add the following to your pom:
<build>
<outputDirectory>${project.basedir}\WebContent\WEB-INF\classes</outputDirectory>
<finalName>${project.name}</finalName>
...
This will build your source within the Web content folder. (Make sure you do a Project -> "Maven" -> "Update Project...") then rebuild...

Issus with building the java project using maven2

I am using maven2 to build the java project, when i issue the command mvn clean install i am getting the error could not parse error message: (use -source 5 or higher to enable generics).
In my eclipse environment i am using jdk 1.7 and the project is working fine. when i want to build the project i am unable to do that, think maven is taking java version 1.3 as default.
Any one please help me how to set the jdk versio to 1.7 in maven, to build the project successfully..
Apart from the jars mentioned in pom.xml i want to add add my own jar, how can i specify that in pom xml?
Thanks in advance..
In your pom.xml configure the maven-compiler-plugin to use 1.6:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

create eclipse groovy-java project with maven

I have a Java-Groovy Eclipse project that I build with Maven. I have added the Maven Groovy plugin to the pom.xml such that I can build/test the Java and Groovy sources on the command-line using Maven.
I would like to have some way to automatically generate the Eclipse .project and .classpath files from my pom.xml. If I run mvn eclipse:eclipse it seems to assume that it's a Java project, so there's no way to (for example) run the tests in src/main/groovy from within Eclipse.
I'm using the STS Eclipse distribution, which includes support for Groovy/Grails. All I'm missing is a way to automatically create the appropriate .classpath and .project files.
Thanks!
P.S. I know IntelliJ is better, but I don't have a license
Here is configuration I found that works when Java calls Groovy code
and when Groovy calls Java code fitting good within groovy eclipse IDE plugin (nature).
There is no need for additional source folders for groovy. It just works!
Using:
mvn clean install eclipse:clean eclipse:eclipse
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<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>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<extensions>true</extensions>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
</build>
You should try the Groovy-Eclipse m2eclipse integration. It is available here:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
With this installed, your maven projects will be automatically configured as groovy-eclipse projects when you import them into your workspace.
If you would like to create a Groovy project just by calling mvn eclipse:eclipse you have to configure your project. As follows a snippet how you configure your maven eclipse plugin so that your project becomes a Groovy project in Eclipse. That snippet must go into your projects pom.xml by the way.
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<sourceIncludes>
<sourceIncludes>**/*.groovy</sourceIncludes>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
</build>
...
When you now call mvn eclipse:eclipse maven creates the .project and .classpath files. .project contains the new project nature what makes it a Groovy project and .classpath contains the */*.groovy* what makes Eclipse treating any file that ends on .groovy as a source file.
Please see also http://maven.apache.org/plugins/maven-eclipse-plugin/examples/provide-project-natures-and-build-commands.html
There is another best way to create maven groovy project. Please follow below steps:
Navigate to https://start.spring.io/ from your browser.
Select project as maven and language as groovy as shown below.
Select other options as per your build requirement like packaging, java version and project name.
Now click on Generate radio button at the bottom and a maven groovy project will be downloaded.
Open Eclipse and import the downloaded maven project and it's ready to use for your groovy scripting with maven integration.

Categories