tony1223 / run-jetty-run

Automatically exported from code.google.com/p/run-jetty-run
0 stars 0 forks source link

Jetty8 servlet3 annotation support #85

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please allow create run/debug configuration for jetty 8.x when web.xml id 
missed (it is not error for api version 3.0).

Original issue reported on code.google.com by asuk...@gmail.com on 25 Jul 2011 at 12:24

GoogleCodeExporter commented 9 years ago
Sorry , I didn't get your question from you description, 
could you explain more on this one?

At least how to reproduce it and what's the error message?

Original comment by tonylovejava on 25 Jul 2011 at 4:10

GoogleCodeExporter commented 9 years ago
Regarding to servlet api 3.0 web.xml can be ommited. It means I can create 
run/debug configuration for jetty 8.x without web.xml in WEB-INF folder. With 
current version of plugin it is impossible.

Original comment by asuk...@gmail.com on 25 Jul 2011 at 4:13

GoogleCodeExporter commented 9 years ago
ok , got you.

I will try to remove it and test with servlet-api 3.0 project.

Original comment by tonylovejava on 25 Jul 2011 at 4:23

GoogleCodeExporter commented 9 years ago
I added a comment to issue#55, but that is closed. I'll repeat it here (and 
yes, I also notice the problem with the requirement of a web.xml file):

The Jetty8 configuration that RJR makes apparently doesn't include 
annotation-processing (@WebServlet - drop web.xml entirely), which probably is 
one of the most defining features of Servlet 3.

To enable a default jetty 8 install to run annotations, you apparently need to 
start it as such:

java -jar start.jar OPTIONS=annotations,plus etc/jetty-plus.xml

This seems to sticks in a couple of jars (these aren't missing), and includes 
the annotation processing config for Jetty 8 (which seemingly is missing).

Original comment by en...@stolsvik.com on 28 Jul 2011 at 11:38

GoogleCodeExporter commented 9 years ago
Here's Servlet that, if put on the webapp's classpath, should just "magically 
appear" on path /test

package test;

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
@WebServlet(name = "TestServletName", urlPatterns = { "/test" })
public class TestServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
            throws IOException {
        res.getOutputStream().println("test output!");
    }
}

Original comment by en...@stolsvik.com on 28 Jul 2011 at 11:45

GoogleCodeExporter commented 9 years ago
ok , I will take them all before we release 1.3 this weekend. ;)

Thanks for reporting issues. 

Original comment by tonylovejava on 29 Jul 2011 at 4:16

GoogleCodeExporter commented 9 years ago
Awesome, quick response! ;-)

Original comment by en...@stolsvik.com on 29 Jul 2011 at 6:53

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Btw: An option to consider, is to enable the user to define additional jetty 
config files, as the 'etc/jetty-plus.xml' does above. That would a) have 
enabled me to "fix" this particular problem myself, and b) tailor the jetty 
server that is started to fit my needs.

Actually, I do feel that you should consider to /not/ programmatically define 
the jetty-server that is started by RJR, /but instead/ use a default jetty xml 
file to do this - which, under advanced options, could be exchanged with a user 
defined one. THEN, in addition, one should be able to include overrides.

This would be just like the 'jetty.jar' starter itself does.

This particular suggestion is not Jetty 8 specific, and is similar to  issue#9 
. Reading it again, I actually think it is identical! Note how   issue#9 
-comment#10 requests the same "Jetty Plus" config that I do here in comment#4 
(but that for jetty 6.)

Original comment by en...@stolsvik.com on 29 Jul 2011 at 7:14

GoogleCodeExporter commented 9 years ago
About using a jetty.xml, I will take it into consider , but there's still some 
complicated part in the jetty server , since we do some resource mapping for 
linked resource, I am not sure if that's a easy one for converting to jetty.xml.

And in most case we meet so far, it's good enough to use the run configuration 
way,
we should have some use-case that really need a setup jetty.xml first.

I will think more/review the code for the jetty.xml after we release 1.3 , 
currently I don't have a good solution to handle it.:P

But surely we will handle the servlet3 and web.xml issue in 1.3 first.

Original comment by tonylovejava on 29 Jul 2011 at 10:03

GoogleCodeExporter commented 9 years ago
For some reason I can't get the Jetty work even I setup a config in the code,
would you mind to provide a workable jetty.xml to help me test it ?

Anyway I think we will delay the annotation support to 1.3.1 , 
since it's more a complicated one then my image.  :P

It's easy to remove the web.xml detection ,add those jars in the classpath , 
and setup config classes in the code, but it's not working for some reason ,
so we need to test it more carefully and to be sure it's stable enough.

Original comment by tonylovejava on 30 Jul 2011 at 11:48

GoogleCodeExporter commented 9 years ago
*Please* don't delay this. I really need this for the project I am embarking 
on, literally monday morning! :-)

You don not need to remove any jars at all - all jars can be included, as you 
do.

Have you got it working on the command line? I do not need to provide you with 
a jetty.xml, as I have never made one - I use the one provided in the jetty 
distribution.

Using the command-line I provided in comment#4, the Servlet I provided in 
comment#5 runs just fine, with no web.xml in the webapp, only the class 
residing in the webapp/WEB-INF/classes. (To test whether the webapp works at 
all, add a web.xml that defines another Servlet using another servletname, the 
same class, but on a different path.)

As I envisioned this, it should just be a matter of (in this first round) 
programmatically adding the same config processors that is added in the 
distribution-provided jetty-plus.xml. Just check that file up, it is a very 
tiny.

In a later stage, you definitely should look into using an user-overridable 
approach, possibly like I suggested in issue#9.

Original comment by en...@stolsvik.com on 31 Jul 2011 at 7:47

GoogleCodeExporter commented 9 years ago
Ok , let me try if I could get it working in nightly version. :)

Original comment by tonylovejava on 31 Jul 2011 at 11:50

GoogleCodeExporter commented 9 years ago
Ah ha! Finally got it working after I turn on the debugging mode and traced 
some details.

There's still something need to be mentioned.

1.I miss two dependency jars for the annotation , 
javax.annotation_1.1.0.v201105051105.jar
org.objectweb.asm_3.3.1.v201101071600.jar

That's the first reason for it's not working for me yesterday , 
I only find the asm , but not the javax.annotation since it's a hidden error 
message.

2.The AnnotationConfiguration 

It required to place your classes in WEB-INF/classes or the jars in WEB-INF/lib 
, actually that make sense for general web application ,but not the one we use 
for RunJettyRun , our classes files is actually depending on the JDT target 
output folder.

I try to copy the classes to WEB-INF/classes , then it working.

More reference 
http://download.eclipse.org/jetty/8.0.0.M3/xref/org/eclipse/jetty/osgi/annotatio
ns/AnnotationConfiguration.html

It's now the critical point for AnnotationConfiguration now , still looking for 
if there's any document could allow us to set a attribute to scan those classes.

Or I will try to create a my own implementation for RJR application , hope that 
could be done gracefully. :P

Original comment by tonylovejava on 1 Aug 2011 at 12:43

GoogleCodeExporter commented 9 years ago
The one is the correct reference.
http://download.eclipse.org/jetty/8.0.0.M3/xref/org/eclipse/jetty/annotations/An
notationConfiguration.html

Original comment by tonylovejava on 1 Aug 2011 at 6:37

GoogleCodeExporter commented 9 years ago
Yes, I had a hunch this might become a problem. But it is actually fixable, or 
at least hackable, by specifically stating in the project settings that the 
eclipse-build output folder shall be WEB-INF/classes.

However, any servlets in the project's referenced jars won't then be loaded.

Amending the AnnotationConfiguration to read through all of the 
run-configuration's Classpath (including jars) seems to be doable, as all 
methods are overridable. But it might be a bit difficult to do this in a 
Servlet 3.0 correct way, as there really are no such correct way..!

Original comment by en...@stolsvik.com on 1 Aug 2011 at 8:08

GoogleCodeExporter commented 9 years ago
I know , it only takes time to survey it and work with it, lol.

Actually I have done this with my own AnnotationConfiguration.

You could try it on our nightly update-site ,here's the reference to nightly.
http://code.google.com/p/run-jetty-run/wiki/Nightly?ts=1312189791&updated=Nightl
y

For more details for how to debug if need.

Setup the two vm arguments to enable Jetty debugging log:
-Dorg.eclipse.jetty.start.DEBUG=true  
-Dorg.eclipse.jetty.util.log.stderr.DEBUG=true

And the log will show up  like this sample
---
2011-08-01 17:06:21.394:DBUG::parsing annotations
......
2011-08-01 17:06:21.461:DBUG::Scanning all classses for annotations: 
webxmlVersion=3 configurationDiscovered=true
2011-08-01 17:06:21.461:DBUG::Scanning container jars
2011-08-01 17:06:21.462:DBUG::Scanning classes in WEB-INF/classes
2011-08-01 17:06:21.464:DBUG::scanning RJR classes for 
annotation:C:\runtime-EclipseApplication\test1\build\classes
2011-08-01 17:06:21.520:DBUG::Search of 
file:/C:/runtime-EclipseApplication/test1/WebContent/WEB-INF/lib/wire-0.8.0.jar
2011-08-01 17:06:21.535:DBUG::skip scanning RJR jar which is already in 
WEB-INF/lib:C:\runtime-EclipseApplication\test1\WebContent\WEB-INF\lib\wire-0.8.
0.jar
2011-08-01 17:06:21.536:DBUG::scanning RJR jar for 
annotation:C:\wseclipse\run-jetty-run-jetty8\lib\servlet-api-3.0.jar
2011-08-01 17:06:21.536:DBUG::Search of 
file:/C:/wseclipse/run-jetty-run-jetty8/lib/servlet-api-3.0.jar

Original comment by tonylovejava on 1 Aug 2011 at 9:13

GoogleCodeExporter commented 9 years ago
The commit is in r233 , I use some bad design this time, 
but at least it work for now , have to find a time to do a code review later. 
haha

You know, sometimes it's not very important for me to write some wonderful 
code, 
it's all about time and requirement. :P

For the additional Jetty.xml , hmm , I will try to schedule a time for it,
but I won't consider to build a default jetty.xml template , since it's 
actually required a lot of code change, and we don't have many user complain 
this so far.

If you have any user-case need any feature, 
just post a new feature and I will think about it. :P

But always , we are not concerning FREEDOM , we consider the REQUIREMENT/USE 
CASE.

Original comment by tonylovejava on 1 Aug 2011 at 9:20

GoogleCodeExporter commented 9 years ago
btw , I will publish official 1.3.1 in two weeks if there's no any critical 
issue for the annotation .

The additional jetty.xml will be in 1.3.1 , if I could find a way to handle it 
gracefully.:)

Original comment by tonylovejava on 1 Aug 2011 at 9:23

GoogleCodeExporter commented 9 years ago
And still a btw , we will scan all the jars which the project referenced ,
usually we assume the jars in the classpath of project is actually the jars in 
WEB-INF/lib . :)

Original comment by tonylovejava on 1 Aug 2011 at 9:25

GoogleCodeExporter commented 9 years ago
And if the jars is already WEB-INF/lib , we will only scan it once, not twice.

Maybe there's still some bugs , please feel free to test it and let me know. 

Original comment by tonylovejava on 1 Aug 2011 at 9:26

GoogleCodeExporter commented 9 years ago

Original comment by tonylovejava on 1 Aug 2011 at 9:35

GoogleCodeExporter commented 9 years ago
Hi tony, thanks for this plugin.We have a use case for a jetty.xml file.
First, all our apps uses contexts different than root, but also uses flash to 
make xhr requests, and we need to have a /crossdomain.xml file, to solve this, 
we can use jetty.xml to define two contexts. The other possible sollution is to 
use a rewrite rule handler, to map a request to /crossdomain.xml to load a file 
from elsewhere. Have you any possible sollution to this without using a 
jetty.xml, or an Apache in front of Jetty? I think direct aliases may help, but 
there's no way to configure them now (also we use rewrite handler for some 
other important tasks, so it's needed too...)

Thanks!

Original comment by juan.t...@gmail.com on 23 Nov 2011 at 3:48

GoogleCodeExporter commented 9 years ago
Hi Juan ,

For issue tracking reason , 
I moved and replied the feature request/discussion to a new issue . 

Please reference to Issue 94 and thanks for your suggestion. :) 

Original comment by tonylovejava on 23 Nov 2011 at 8:41

GoogleCodeExporter commented 9 years ago
Thanks!
It would be very nice to have that feature!

Original comment by juan.t...@gmail.com on 24 Nov 2011 at 3:42