You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Rader <p....@gmx.net> on 2020/03/15 10:47:07 UTC

/META-INF/resources/ and Chrome's DevTools

I have my default.js in a frontend.jar's /META-INF/resources/js/ according to the specs (last paragraph of point 10.10 in https://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-eval-oth-JSpec/servlet-3_0-final-spec.pdf ) it is served successfully. This works great!

Chrome load this default.js during surfing on localhost. Using DevTools I can map this in-browser-default.js to a local directory. This allowes chrome to synchronize the local source-version of the default.js with the in-browser loaded default.js.

This way I have a source-cascade.
1. The default.js is Packed into the frontend.jar.
2. The frontend.jar is Packed into the application.war.
3. The application.war is served via Tomcat.

The Problem:

If I reload the website Chrome DevTools drops all changes I made to the Tomcat served version. 
So if I change a single byte in the default.js I have to:
1. Pack the jar
2. Pack the war
3. Redeploy the war.

This process takes a length of about 5 minutes. It is reloading the application and package the jars/wars for the sake of 1 byte change.

The Question:

Can I map a single resource to a file dynamically without reloading the application.


Kind regards

Peter Rader
--
Fachinformatiker AE / IT Software Developer
Peter Rader
Wilsnacker Strasse 17
10559 Berlin - GERMANY
Tel: 0049 (0)30 / 20 9930560
Fax: 0049 (0)30 / 20 9930561
Handy: 0049 (0)176 / 8 7521576

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Aw: /META-INF/resources/ and Chrome's DevTools

Posted by Peter Rader <p....@gmx.net>.
I wrote a little WebFilter for this task.

https://github.com/enexusde/devtools-tomcat-bypass

Kind regards

Peter Rader
--
Fachinformatiker AE / IT Software Developer
Peter Rader
Wilsnacker Strasse 17
10559 Berlin - GERMANY
Tel: 0049 (0)30 / 20 9930560
Fax: 0049 (0)30 / 20 9930561
Handy: 0049 (0)176 / 8 7521576

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Aw: Re: Re: /META-INF/resources/ and Chrome's DevTools

Posted by Peter Rader <p....@gmx.net>.

Ah ok, 
 
I use maven, only tomcat 7 and 6 is available. PreResources are only available in tomcat8 so I decide against tomcat in higher versions than 7.
 
Kind regards

>  Gesendet: Montag, 06. April 2020 um 16:34 Uhr
>  Von: "Mark Thomas" <ma...@apache.org>
>  An: users@tomcat.apache.org
>  Betreff: Re: Aw: Re: /META-INF/resources/ and Chrome's DevTools
>  On 06/04/2020 09:16, Peter Rader wrote:
>  > Hello Konstantin Kolinko,
>  >
>  > I tried to use the PreResource but it does not work.
>  >
>  > 2020-04-06 10:13:05 WARNUNG org.apache.tomcat.util.digester.Digester endElement No rules found matching 'Context/Resources/PreResources'.
>  >
>  > This is my context.xml
>  >
>  > <Context addWebinfClassesResources="true" cookies="true">
>  > <Resource name="jdbc/database" auth="Container"
>  > type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
>  > url="xxxx"
>  > username="xxx" password="xxx" maxTotal="50"
>  > maxIdle="50" maxWait="10"></Resource>
>  > <Resources>
>  > <PreResources
>  > className="org.apache.catalina.webresources.FileResourceSet"
>  > base="C:\Users\Guest\git\xxxxx\src\main\resources\META-INF\resources"
>  > internalPath="index.html" />
> 
>  That doesn't look quite right. I'd expect it to look something like:
> 
>  <PreResources
>  className="org.apache.catalina.webresources.FileResourceSet"
>  base="C:\Users\Guest\git\xxxxx\src\main\resources\META-INF\resources"
>  />
>
>  To map the contents of the "...\META-INF\resources" directory into the
>  root of the web application.
> 
>  Mark
> 
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: users-help@tomcat.apache.org
>   
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Aw: Re: /META-INF/resources/ and Chrome's DevTools

Posted by Mark Thomas <ma...@apache.org>.
On 06/04/2020 09:16, Peter Rader wrote:
> Hello Konstantin Kolinko,
> 
> I tried to use the PreResource but it does not work. 
> 
> 2020-04-06 10:13:05 WARNUNG org.apache.tomcat.util.digester.Digester endElement   No rules found matching 'Context/Resources/PreResources'.
> 
> This is my context.xml
> 
> <Context addWebinfClassesResources="true" cookies="true">
> 	<Resource name="jdbc/database" auth="Container"
> 		type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
> 		url="xxxx"
> 		username="xxx" password="xxx" maxTotal="50"
> 		maxIdle="50" maxWait="10"></Resource>
> 	<Resources>
> 		<PreResources
> 			className="org.apache.catalina.webresources.FileResourceSet"
> 			base="C:\Users\Guest\git\xxxxx\src\main\resources\META-INF\resources"
> 			internalPath="index.html" />

That doesn't look quite right. I'd expect it to look something like:

<PreResources
  className="org.apache.catalina.webresources.FileResourceSet"
  base="C:\Users\Guest\git\xxxxx\src\main\resources\META-INF\resources"
  />

To map the contents of the "...\META-INF\resources" directory into the
root of the web application.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Aw: Re: /META-INF/resources/ and Chrome's DevTools

Posted by Peter Rader <p....@gmx.net>.
Hello Konstantin Kolinko,

I tried to use the PreResource but it does not work. 

2020-04-06 10:13:05 WARNUNG org.apache.tomcat.util.digester.Digester endElement   No rules found matching 'Context/Resources/PreResources'.

This is my context.xml

<Context addWebinfClassesResources="true" cookies="true">
	<Resource name="jdbc/database" auth="Container"
		type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
		url="xxxx"
		username="xxx" password="xxx" maxTotal="50"
		maxIdle="50" maxWait="10"></Resource>
	<Resources>
		<PreResources
			className="org.apache.catalina.webresources.FileResourceSet"
			base="C:\Users\Guest\git\xxxxx\src\main\resources\META-INF\resources"
			internalPath="index.html" />
	</Resources>
</Context>


Any idea?



>
> Gesendet: Montag, 16. März 2020 um 01:01 Uhr
> Von: "Konstantin Kolinko" <kn...@gmail.com>
> An: "Tomcat Users List" <us...@tomcat.apache.org>
> Betreff: Re: /META-INF/resources/ and Chrome's DevTools
> ??, 15 ???. 2020 ?. ? 13:47, Peter Rader <p....@gmx.net>:
> >
> > I have my default.js in a frontend.jar's /META-INF/resources/js/ according to the specs (last paragraph of point 10.10 in https://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-eval-oth-JSpec/servlet-3_0-final-spec.pdf ) it is served successfully. This works great!
>
> 1. If you unpack the file into a directory in your web application
> (into its /js/ directory),
> it will take precedence over the version packed in the framework jar.
>
>
> 2. It is possible to map files from elsewhere on your hard drive into
> your web application.
> It can be done with "<PreResources>" element in the
> META-INF/context.xml file of your web application.
>
> For reference:
> http://tomcat.apache.org/tomcat-9.0-doc/config/resources.html[http://tomcat.apache.org/tomcat-9.0-doc/config/resources.html]
>
>
> 3. If your Tomcat runs on the same computer. you can run the web
> application from an expanded directory, without packing it as a war
> file.
>
> 1) Copy your META-INF/context.xml file as
> $CATALINA_BASE/conf/Catalina/localhost/yourwebappname.xml
>
> 2) Add docBase attribute to the <Context> element in it.
>
> See
> http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Defining_a_context[http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Defining_a_context]
>
>
> Best regards,
> Konstantin Kolinko




Kind regards

Peter Rader
--
Fachinformatiker AE / IT Software Developer
Peter Rader
Wilsnacker Strasse 17
10559 Berlin - GERMANY
Tel: 0049 (0)30 / 20 9930560
Fax: 0049 (0)30 / 20 9930561
Handy: 0049 (0)176 / 8 7521576

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Aw: Re: /META-INF/resources/ and Chrome's DevTools

Posted by Peter Rader <p....@gmx.net>.
> >
> > I have my default.js in a frontend.jar's /META-INF/resources/js/ according to the specs (last paragraph of point 10.10 in https://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-eval-oth-JSpec/servlet-3_0-final-spec.pdf ) it is served successfully. This works great!
>
> 1. If you unpack the file into a directory in your web application
> (into its /js/ directory),
> it will take precedence over the version packed in the framework jar.

Ok this will work but I run the app using

  mvn tomcat:run

Any behavioural modification to this process will order modifications to the pom.xml. Since this leads to be more project-specific code under version-control to support I like to avoid this.

>
>
> 2. It is possible to map files from elsewhere on your hard drive into
> your web application.
> It can be done with "<PreResources>" element in the
> META-INF/context.xml file of your web application.
>
> For reference:
> http://tomcat.apache.org/tomcat-9.0-doc/config/resources.html[http://tomcat.apache.org/tomcat-9.0-doc/config/resources.html]
>

This might do the trick! Ill try that out. If that is confirmed to be working I can get rid of https://github.com./enexusde/devtools-tomcat-bypass .

>
> 3. If your Tomcat runs on the same computer. you can run the web
> application from an expanded directory, without packing it as a war
> file.
>
> 1) Copy your META-INF/context.xml file as
> $CATALINA_BASE/conf/Catalina/localhost/yourwebappname.xml
>
> 2) Add docBase attribute to the <Context> element in it.
>
> See
> http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Defining_a_context[http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Defining_a_context]
>

Since beside the frontend.jar I have other jars who serve static resources. This means I must have multiple docBases what is not possible AFAIK.

>
> Best regards,
> Konstantin Kolinko

Kind regards

Peter Rader

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: /META-INF/resources/ and Chrome's DevTools

Posted by Konstantin Kolinko <kn...@gmail.com>.
вс, 15 мар. 2020 г. в 13:47, Peter Rader <p....@gmx.net>:
>
> I have my default.js in a frontend.jar's /META-INF/resources/js/ according to the specs (last paragraph of point 10.10 in https://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-eval-oth-JSpec/servlet-3_0-final-spec.pdf ) it is served successfully. This works great!

1. If you unpack the file into a directory in your web application
(into its /js/ directory),
it will take precedence over the version packed in the framework jar.


2. It is possible to map files from elsewhere on your hard drive into
your web application.
It can be done with "<PreResources>" element in the
META-INF/context.xml file of your web application.

For reference:
http://tomcat.apache.org/tomcat-9.0-doc/config/resources.html


3. If your Tomcat runs on the same computer. you can run the web
application from an expanded directory, without packing it as a war
file.

1) Copy your META-INF/context.xml file as
$CATALINA_BASE/conf/Catalina/localhost/yourwebappname.xml

2) Add docBase attribute to the <Context> element in it.

See
http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Defining_a_context


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org