Reputation: 144
I am trying to run a very simple java server with jetty embedded. I am using gradle to compile it but for simplicity I'll just describe the way I am trying to start my process
start.bat
com
test
worktest
Starter.class
WebServer.class
./lib:
asm-3.2.jar
cglib-nodep-2.2.jar
ecj-3.12.3.jar
gentyref-1.2.0.jar
gson-2.8.2.jar
javax.servlet-api-3.1.0.jar
jetty-http-9.4.8.v20171121.jar
jetty-io-9.4.8.v20171121.jar
jetty-jsp-2.1-7.5.4.v20111024.jar
jetty-security-9.4.8.v20171121.jar
jetty-server-9.4.8.v20171121.jar
jetty-servlet-9.4.8.v20171121.jar
jetty-util-9.4.8.v20171121.jar
jetty-webapp-9.4.8.v20171121.jar
jetty-xml-9.4.8.v20171121.jar
mockachino-0.6.2.jar
objenesis-1.2.jar
slf4j-api-1.7.25.jar
slf4j-simple-1.6.2.jar
tomcat-api-9.0.5.jar
tomcat-el-api-9.0.5.jar
tomcat-jasper-9.0.5.jar
tomcat-jasper-el-9.0.5.jar
tomcat-jsp-api-9.0.5.jar
tomcat-juli-9.0.5.jar
tomcat-servlet-api-9.0.5.jar
tomcat-util-9.0.5.jar
tomcat-util-scan-9.0.5.jar
./web:
index.jsp
./web/js:
jquery-1.7.1.min.js
start.bat looks like this
cat start.bat
set JAVA_STARTER="com.test.worktest.Starter"
set CLASSPATH=".\lib\*;."
java -cp %CLASSPATH% %JAVA_STARTER%
The server starts just fine but when i try to access localhost:port I am getting
Problem accessing /index.jsp. Reason:
JSP support not configured
I am on jdk 9.0.1.
PART 2
Following up on the answer below, I have made a few changes to my gradle script. Got rid of not compatible deps.
I also figured out that asm3.0 was a dep for mockachino. It's now gone. At the moment I am looking like:
dependencies {
compile 'com.google.code.gson:gson:2.8.2'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
runtime group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
compile group: 'org.eclipse.jetty', name: 'jetty-http', version: '9.4.8.v20171121'
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.4.8.v20171121'
compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '9.4.8.v20171121'
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.8.v20171121'
compile group: 'org.eclipse.jetty', name: 'apache-jsp', version: '9.4.8.v20171121'
compile group: 'org.eclipse.jetty', name: 'jetty-annotations', version: '9.4.8.v20171121'
compile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile group: 'se.mockachino', name: 'mockachino', version: '0.6.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
and my lib folder:
apache-el-8.5.23.jar
apache-jsp-8.5.23.jar
apache-jsp-9.4.8.v20171121.jar
asm-6.0.jar
asm-commons-6.0.jar
asm-tree-6.0.jar
ecj-3.12.3.jar
gson-2.8.2.jar
javax.annotation-api-1.2.jar
javax.servlet-api-3.1.0.jar
jetty-annotations-9.4.8.v20171121.jar
jetty-http-9.4.8.v20171121.jar
jetty-io-9.4.8.v20171121.jar
jetty-jndi-9.4.8.v20171121.jar
jetty-plus-9.4.8.v20171121.jar
jetty-schemas-3.1.jar
jetty-security-9.4.8.v20171121.jar
jetty-server-9.4.8.v20171121.jar
jetty-servlet-9.4.8.v20171121.jar
jetty-util-9.4.8.v20171121.jar
jetty-webapp-9.4.8.v20171121.jar
jetty-xml-9.4.8.v20171121.jar
slf4j-api-1.7.25.jar
slf4j-simple-1.7.25.jar
When accessing the jsp I am still getting:
Code is here
I'll keep posting updates as I find things out.
Upvotes: 1
Views: 2256
Reputation: 328
Wanted to post this here as I was facing a similar issue after migrating a legacy app from tomcat to jetty. I got the java.lang.IllegalStateException: No org.apache.tomcat.InstanceManager set in ServletContext
exception but not the other exception you mention. I feel this is the most appropriate place to post this considering this is the first post that shows when searching for that error.
After doing extensive research I came across this thread. As the thread shows, that error can be thrown when jetty is missing some modules. In this particular case the missing modules were plus
and annotations
.
Jetty modules can be enabled in a couple of different ways. For instance, you can add the --add-to-start=<module-name1>,<module-name2>,…etc.
parameter to your start command:
[mybase]$ java -jar $JETTY_HOME/start.jar --add-to-start=server,deploy,http,jmx,stats,servlets,webapp,logging-log4j,apache-jsp,apache-jstl,plus,annotations
You can also do it programmatically by using the addAfter
and addBefore
functions. One thing to note here as that the order in which you add modules programmatically matters so be careful where you add them. Here is a sample snippet:
//Create the server
Server server = new Server(8080);
//Enable parsing of jndi-related parts of web.xml and jetty-env.xml
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
Another way to add them would be through XML files. Here's the contents of the jetty-provided jetty-plus.xml
and jetty-annotations.xml
files.
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add plus Configuring classes to all webapps for this Server -->
<!-- =========================================================== -->
<Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault">
<Arg><Ref refid="Server" /></Arg>
<Call name="addAfter">
<Arg name="afterClass">org.eclipse.jetty.webapp.FragmentConfiguration</Arg>
<Arg>
<Array type="String">
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
</Array>
</Arg>
</Call>
</Call>
</Configure>
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add annotation Configuring classes to all webapps for this Server -->
<!-- =========================================================== -->
<Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault">
<Arg><Ref refid="Server" /></Arg>
<Call name="addBefore">
<Arg name="beforeClass">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Arg>
<Arg>
<Array type="String">
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
</Array>
</Arg>
</Call>
</Call>
</Configure>
These XML files are used when you add them with the parameter option or you can also use them by enabling the respective modules through a start.ini
file by adding modules with --module=<module-name>
.
Hope this helps someone.
Upvotes: 0
Reputation: 49462
You have to setup JSP for Jetty, the mere existence of the JARs is insufficient.
The following JARs should be removed from your project.
jetty-jsp-2.1-7.5.4.v20111024.jar
tomcat-api-9.0.5.jar
tomcat-el-api-9.0.5.jar
tomcat-jasper-9.0.5.jar
tomcat-jasper-el-9.0.5.jar
tomcat-jsp-api-9.0.5.jar
tomcat-juli-9.0.5.jar
tomcat-servlet-api-9.0.5.jar
tomcat-util-9.0.5.jar
tomcat-util-scan-9.0.5.jar
jetty-jsp
is not valid for Jetty 9.4.8.
The straight/normal/default Tomcat libraries are 100% incompatible within Jetty.
Important: For success with JSP, Use a proper build system (choose one of the following: maven, ant+ivy, buildr, grails, grape, sbt, or leiningen). Don't skip this, don't work around this, don't try to do it manually.
Use a proper servlet-api
jar.
http://search.maven.org/#artifactdetails%7Cjavax.servlet%7Cjavax.servlet-api%7C3.1.0%7Cjar
Remove ecj-3.12.3.jar
if you are deploying to a JDK, or intend to use Java 1.7 (or newer) features within your JSPs. By default, the JDK compiler will be used if present. Don't forget to configure your desired source/target levels on the JettyJspServlet
configuration.
Make sure you use a valid ASM jar for Jetty 9.4.8.
Remove this as it's incompatible:
asm-3.2.jar
Make sure you use the jetty-annotations
artifact (and transient dependencies) from the org.eclipse.jetty
group id, aligned with the same version as the rest of your jetty artifacts.
This will pull in the correct asm jars and appropriate dependencies needed for your JSP webapp.
You'll need the apache-jsp
artifact (and transient dependencies) from the org.eclipse.jetty
group id, aligned with the same version as the rest of your jetty artifacts.
http://search.maven.org/#artifactdetails%7Corg.eclipse.jetty%7Capache-jsp%7C9.4.8.v20171121%7Cjar
This will pull in the correct JSP support libraries (and JSTL/EL) that you need.
Then you'll need to configure for JSP.
See the sample project at https://github.com/jetty-project/embedded-jetty-jsp
Finally, some things you need to consider with JSP/JSTL/EL support:
Upvotes: 2