mvn jetty:run giving error 404 - java

I have a Spring MVC web application and tried running it using Jetty. But whenever I type
mvn jetty: run
I get the proper sequence of events ending in "Jetty Server Started"
But however when I try to open the browser and type in
http:localhost:8080/app
I get Error 404 page Not found
here is my pom.xml jetty part
<plugin>
<!-- This plugin is needed for the servlet example -->
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.0.v20101020</version>
<configuration>
<webApp>
<contextPath>/app</contextPath>
</webApp>
</configuration>
</plugin>
my controller is mapped to #RequestMapping("/") and my servlet is also mapped to /. The pom.xml build name is app thus the URL is http://localhost:8080/app
Any help with this would be great.
I have also tried with Jetty v9 and that doesn't work either

Try this it works fine
Edit
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.8</version>
<configuration>
<contextPath>/app</contextPath>
</configuration>
</plugin>
First thing http:localhost:8080/app is wrong it should be http://localhost:8080/app if you give this url then you must have a landing page that you can specify in web.xml
Like this
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
So simply try to access the url http://localhost:8080/app/index.jsp where there must be some index.jsp under the web-content folder

Related

How to use #pact maven plugin to verify a provider without port

Per https://docs.pact.io/implementation_guides/jvm/provider/maven/#2-define-the-pacts-between-your-consumers-and-providers
: Protocol, Host, and Port are required.
My spring boot rest app is on kubernetes, I have endpoint URL like https://fruitbasket.net/abc
If I don't specify the port tag, and run mvn pact:verify; test fail and it seems like :8080 get appended during run time
https://fruitbasket.net/:8080/abc
Essentially, messing up the request endpoint.
Please note: I having fixed IP address and port isn't realistic.
How can I specify the provider host URL without port?
plugin config:
<plugin>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>maven</artifactId>
<version>4.1.0</version>
<configuration>
<serviceProviders>
<name>marketplace</name>
<protocol>https</protocol>
<host>fruitbasket.net</host>
</serviceProvider>
</serviceProviders>
</configuration>
</plugin>
in my current project we use this config
<plugin>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>maven</artifactId>
<version>4.2.0</version>
<configuration>
<pactBrokerUrl>https://mypactbroker</pactBrokerUrl>
<trimSnapshot>true</trimSnapshot>
</configuration>
</plugin>
with the annotation #PactBroker(scheme = "https")on the test class.
The pom.xml is not correct. You are missing to open serviceProvider tag

How to access tomcat page when using tomcat maven plugin

I have created a SOAP service and using tomcat maven plugin for deploying in tomcat server.
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- <contextFile>${basedir}/src/main/webapp/META-INF/context.xml</contextFile> -->
</configuration>
</plugin>
</plugins>
</build>
I am able to start application and able to get wsdl also when using this end point - http://localhost:8080/soapapptest
everything is working, but when I used this endpoint http://localhost:8080 for getting tomcat home page then I got below page.
how I will get the tomcat home page where I can see my deployed war?
After starting application I am getting following logs
The home page is an application that gets deployed to the "ROOT" context. You'll find it in the downloadable Tomcat .tar.gz and .zip files. Unless your pom.xml deploys an application as ROOT, you are supposed to get a 404 response for /.

Connection reset error - when running mvn clean install to run features

We have generated a karate test project using the Maven archetype, to test several different API services.
We have a feature file that conducts a test with an endpoint, which works fine when this endpoint is locally running on our machine. However, we would like to run these karate tests in a CI environment where we use a url to our (deployed) service on a dev environment. When we run mvn clean install on our CI pipeline, we get an error when running the feature:
com.intuit.karate.exception.KarateException:
MyFeatureTest.feature:8 -
java.net.SocketException: Connection reset
Our configuration
pom.xml:
<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.mycompany.app</groupId>
<artifactId>our-karate-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.version>3.6.0</maven.compiler.version>
<karate.version>0.9.5</karate.version>
</properties>
<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-Werror</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
MyFeatureTest.java
import com.intuit.karate.KarateOptions;
import com.intuit.karate.junit4.Karate;
import com.junit.runner.RunWith;
#RunWith(Karate.class)
#KarateOptions(features="classpath:MyFeatureTest.feature")
public class MyFeatureTest {
}
MyFeatureTest.feature
Feature: test an endpoint
Background:
* url 'https://dev.myapplication.com/api/signin'
* configure ssl = true
Scenario: test request
Given request {"username":"john", "password":"doe"}
When method post
Then status 200
And match response == {resp:"success"}
What we have tried:
We are able to call the service through Postman without any problem (both locally and the deployed service). We have also tried executing different methods, for example get. The strange part out of all this is that the connection reset error occurs in our CI environment, but when we run the feature locally, we get a org.apache.http.conn.ConnectTimeoutException: connect to https://dev.myapplication.com:443 failed: connection timeout.
We have a feeling it is related to the karate-apache client, but we have also tried to use apache-jersey. Unfortunately, we get the same problem when we use the jersey client as well. We also thought it might be related to SSL. However, even when using a non ssl service (and remove the ssl configuration from the feature), the same problem occurs. We have tried to test responses from non-https websites like web.archive.org as well as https ones like google.com, in a futile attempt as well where we simply test a GET request. Still, the same issue occurs.
Sounds very much like you have an HTTP proxy to deal with.
Refer to the docs if that is the case: https://github.com/intuit/karate#configure
* configure proxy = 'http://my.proxy.host:8080'

WELD-000119: Not generating any bean definitions from because of underlying class loading error

I'm new in using MyEclipse and Java EE
I'm trying to deploy my web application on wildfly 8.0.0. in MyEclipse.
Unfortunately, I'm getting this error after I took some code changes from SVN (I'm not sure this is the reason), before that it was working fine:
[org.jboss.weld.Bootstrap] (weld-worker-2) WELD-000119: Not generating any bean definitions from (.....) because of underlying class loading error: Type WebArchive from [Module "deployment.Test.war:main" from Service Module Loader] not found. If this is unexpected, enable DEBUG logging to see the full error.
When I (Run) the server, the deployment succeeded although the console produces some lines of the same error, but when i (Debug) the server, it keeps generating the same error.
Can someone help me please
Thanks.
It may be that the class loader can't find "WebArchive" because it needs to be added as a module to the WildFly configuration. You do that like this:
module add --name=org.apache.commons.lang3.commons-lang3 --resources=C:\Users\b\.m2\repository\org\apache\commons\commons-lang3\3.4\commons-lang3-3.4.jar
In addition, you'll probably need to add WebArchive as a dependency in the <build> section of your pom.xml.
Here's the relevant section of my pom.xml:
<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated WAR, and hence the context root) -->
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifestEntries>
<Dependencies>com.fasterxml.jackson.datatype.jackson-datatype-jsr310,org.hibernate,org.apache.commons.lang3.commons-lang3</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- The WildFly plug-in deploys the WAR to a local WildFly container -->
<!-- To use, run: mvn package wildfly:deploy -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
</plugins>
</build>
If you can't figure it out, try posting your pom.xml and jboss-deployment-structure.xml (if you have one).
This error message does not hint to start your server in debug mode, but to set the log level of org.jboss.weld.Bootstrap or the root logger to debug.
See WildFly 8 Logging Levels for how to do that
The problem was because I'm starting my server in debug mode and the breakpoints were activated

gwt-maven-plugin: webapp structure

I am using gwt-maven-plugin and eclipse to create GWT+Spring webapp. In the end I want to get .war file to be deployed to some application server(tomcat etc). The problem is that the generated .war file has strange structure.
And then I run in on Tomcat the application doesn't work - SimpleGWT.html page has a link to javascript file which does all the job
<script type="text/javascript" language="javascript" src="SimpleGWT/SimpleGWT.nocache.js"></script>
My guess is that since the SimpleGWT.nocache.js in located inside SimpleGWT folder which is not inside WEB-INF - it is not accessible
Is there any way to alter options of gwt-maven-plugin in order to get normal webapp structure? Here is part of my pom.xml
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.6.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see
gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<inplace>true</inplace>
<runTarget>SimpleGWT.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>com.javacodegeeks.gwtspring.client.Messages</i18nMessagesBundle>
</configuration>
</plugin>
Its the issue that is mostly related to access static resources in an HTML page.
You are using relative path that does not have a "/" prefix. That is an absolute path
pointing to the root of the web-server.
In Spring MVC application org.springframework.web.servlet.DispatcherServlet is responsible fore serving all the contents for web apps.
What have you defined as url-pattern for above servlet mapping? Please try with *.html or /* as url-pattern.
For more information read about Unable to load java script files in Jetty webapplication.

Categories