problems deploying a maven application with mvn command - java

I have a maven application under eclipse . The jsp pages and WEB-INF folder are located under the path NomeMiaApplicazione\src\main\webapp. I run these commands : mvn clean ,
mvn eclipse: eclipse and mvn compile under the root folder of the application, and in all three cases, the build is successful. However when I access the folder ( into the workspace )
. metadata.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\NomeMiaApplicazione
, there are no jsp pages . what would be the solution for this problem ? thks !

It is necessary to clarify the role of the commands you used and their impact on Eclipse.
The mvn eclipse:eclipse command creates the Eclipse project files, in order to save you the hassle of configuring a new project and identifying all the sources for it. This command is also equivalent to creating a new Eclipse project from an existing Maven project using the m2e Eclipse plugin. See also this page regarding the eclipse:eclipse command. That being said, you only need to run such command once, and then import the resulting project into Eclipse.
Secondarily, mvn compile builds your source files into the target directory of your NomeMiaApplicazione root folder. This command does not involve Eclipse in any way. Also, web resources are still not packaged. To package them, you need to issue mvn package: you will then find the <artifact>-<version>.war file again under target, and the pre-packaged content under target\<artifact>-<version>. Beware that, in order to account for the webapp content, your Maven packaging must be of type war. Check the pom.xml for the <packaging> tag.
Finally, deployment is still another issue. If you actually need to move your .war file from the target directory to somewhere else (namely, an autodeploy folder of a servlet container), you can configure the Maven Deploy Plugin and issue mvn deploy. I'd rather suggest you to search SO for deploy war eclipse and/or deploy war maven, since there's plenty of related stuff. In the first case, you will find how to use Eclipse as a facility for deployment, while the second case leverages the command line to provide a more portable/flexible deployment procedure.

That's because mvn compile ends on compile phase of Maven's default lifecycle. Do mvn package and check then. And by the way, default Maven output directory is target so rather check it instead of kind of WTP temporary dirs.

Related

Exporting Spring Boot application as JAR file in eclipse

I'm using the Spring STS in Eclipse to create a simple web-based spring boot project. I can run it fine in Eclipse, but when I try to export it as a JAR file I get:
rg.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
My public static void mainis located in Application.java, with the #SpringBootApplication annotation.
I've double checked all the Maven dependencies a hundred times.
What am I doing wrong?
Most likely, you're using the built-in Eclipse exporter to generate your jar, which only includes the target files actually produced in that project. In order to have a "fat" (standalone executable) jar, you need to use the Spring Boot Maven or Gradle plugin to "repackage" the jar.
First, make sure that you have the repackage goal included in your build setup, then use the Maven package target. The simplest way to do this is to run mvn package from the command line (you may need to install the Maven CLI package for your OS); you can also right-click the POM in Eclipse and "Run As" to execute specific Maven operations from within Eclipse.
It is a single line command, on window 7/10 machine, with command prompt to your project folder (Inside your project workspace). I do not do with Eclipse IDE POM maven goals, but you can do with maven goal there also. ON window machine I prefer cmd.exe for exporting and running.
mvnw clean package
on unix kernel based
./mvnw clean package
You have to go inside workspace and than to the project root folder. You will see a maven wrapper mvnw, with that you don't need to have maven installed and .mvn folder at the same level provides necessary jar for that.
For a project
D:\workspace\Zuteller Workspace\zusteller>mvnw clean package
it will create zusteller-0.0.1-SNAPSHOT.jar in the target folder at the same level.
D:\workspace\Zuteller Workspace\zusteller>java -jar target\zusteller-0.0.1-SNAPSHOT.jar
You can run self-contained application(embedded Tomcat) and access at localhost:8080/your project

Eclipse Build does not generate WAR

I have a Maven WEB Project that I am having problems configuring. I am trying to get the project to build a WAR and place it in the target directory when I build through Eclipse, but when I do a build, nothing appears to be happening. Is there anything special that I have to do to setup what happens when I do a build through Eclipse?
Right now, when I build, the target directory gets created and a m2e-wtp folder gets generated, not sure what that is.
Executing mvn clean install command from the directory where pom.xml is present will generate the WAR file. Sometimes IDE fails to reload the application target folder after external build. Try to refresh the workspace in Eclipse after building the application.
You can also try mvn clean install -X to run the build process in debug mode. This way you can figure out the exact problem.
Shishir

Maven to Eclipse build issue while creating web application

I'm trying to build web Service using maven and eclipse. Here is steps I followed.
Generated mvn folder struture using comman prompt
mvn archetype:generate - DarchetypeArtifactId=maven-archetype-webapp
Converted the mvn project into eclipse.
mvn eclipse:eclipse -Dwtpversion=2.0
Imported the project into my workspace.
Changed the project facets such as java version, servlet version, added cxf and jaxb feature and server runtime.
Copied the WSDL to Resources folder.
Since I do not want to add dependencies(as somebody else would be doing this job for me). I added spring and CXF lib into build path. and also to deployment assembly.
Generated the jaxb classes and operations from wsdl. Here all the java classes created instead of going to src/main/java to went to src/main/resources.
I run the app on tomcat. web.xml is invoked from that cxf framework got invoked and also spring bean creation got invoked. but while creating the bean for the webservice class it threw Class not found error.
When I opened up the war I could notice that while packaging instead of placeing the class files, the eclipse placed java file as it is in the war file.
Could some one help me in fixing this problem. Not sure how to configure eclipse to compile and place .class files in the war instead of .java filee.
Figured out the problem, while importing the file eclipse is adding command, exclude all the java files from src/main/resources in srource tab of java build path On removing it worked fine

Why might eclipse not export maven libraries that are included in classpath?

I have a fine running project that uses Maven for dependency management. The project itself is run by eclipse (Run As...).
In the project menu > Deployment Assembly, I have included the MAVEN_REPO.
Problem: when I run the project, everything gets copied correctly to war/WEB-INF/lib.
BUT I'm constantly getting an error that PersistenceProvider cannot be found.
IF I copy manually all libraries from deployed war dir to src/main/webapp/WEB-INF/lib, and then restart the application, everthing works fine!
So I can conclude that my jpa/hibernate config in general is fine.
But how can I come over the need to add all libraries manually to the src lib folder?
So, when you do 'Run As - Web Applicaiton' eclipse/google plugin uses the War directory path you specify. To change this, you right click on your project, and select properties. Then under the google drop down, select 'Web Applicaiton'. There, you can edit the 'WAR directory' path. this is probably set to src/main/webapp, which is NOT what you want.
When maven builds your war, it takes all built class files and libraries, and packages them into the target directory. This is the directory you want to use as the 'War directory'. This will be something like '/target/myappname-1.0.0'
Sidenote: If you are using gwt/maven, you'll probably want to use the command 'mvn gwt:run' versus running using the google/eclipse plugin. This allows maven to do some work (like resolve dependencies) before the dev server is run.

How to build project from maven pom file

I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir. Cd into that dir and ran mvn command without any arguments but I got bunch of errors. I am absolutely new to maven so I think I am missing something. I tried also from Eclipse ( Import project -- exisitng maven project) but that also does not work except eclipse creates a project that has just that file pom.xml. I expect something that first it will download the jar for the project and then download all dependent jars and config files but nothing there.
So given a pom file how do I build the project from it?
mvn install should get you going
I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir ...
It sounds like you only have the project's POM file. This is not sufficient. You need to checkout the complete source tree for the project. Having done that, change directory to the directory containing the POM file and run mvn install.
Also, don't copy the POM to a different directory. Maven expects to find all of the source files relative to the POM file location.
FOLLOW UP
Thanks for advice. I was not able to use the command mvn install as it gave errors.
Probably because you hadn't checked out the source.
I don't know how to check the source tree of the project ...
Use a subversion client (the svn command for example), or one of the Eclipse subversion plugins.
If this was a properly documented project, there would be clear instructions on what version control and build tools you needed, how to checkout the source code and how to build it.
... as I thought POM itself should have this information to automatically checkout if the source is not check out.
It doesn't necessarily, though in this particular case it does.
Anyway I was able use Eclipse to build the project without errors.
(Other readers can read #icyrock.com's answer for links to the m2eclipse plugin and documentation.)
The only problem is the dependent jars were downloaded but hidden deep paths in .m2 repository folder on my linux box.
But I would like these dependent jars to be relative to dir where POM file is.
Sorry, but that is not the way Maven works.
The ~/.m2/repository directory is a fundamental part of Maven. It is not a problem. It is a feature. (Don't fight it!)
If you want to open this within Eclipse, you need to install m2eclipse:
http://www.eclipse.org/m2e/
and then import the project as a Maven project as described here:
http://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html
Try out their getting started guide. It has a lot of good examples:
http://maven.apache.org/guides/getting-started/

Categories

Resources