How to create a tomcat snap?


#1

Hi guys, I have a web application, that uses the tomcat server. It’s working fine. Now I want to create a snap for my application. I don’t know how to create a tomcat snap. Please guide me to solve this problem…


#2

take a look at @mhall119’s tomcat part on

https://wiki.ubuntu.com/snapcraft/parts

it even has an example how your snapcraft.yaml needs to look and where to put your .war file to make it work …


#3

@ogra

I tried this examples, but in the build part it shows error,"Redirection detected from https to http. Protocol switch unsafe, not allowed ", in the build.xml file.


#4

hmm, that sounds like the tomcat part is actually broken (i assume the build.xml file comes from the tomcat part)


#5

@ogra I don’t know about that,

My snapcraft.yaml File is

 apps:
  my-app:
    command: tomcat-launch
    daemon: simple
    plugs: [network-bind]
parts:
  my-webapp:
    source: .
    plugin: dump
    organize:
        my.war: webapps/my.war
    after: [tomcat]

as per the example, i created this? is it correct?


#6

yes, thats correct, i think the issue lies in the tomcat remote part itself, not much you can do about that and i’m not sure if @mhall119 still reads this forum to actually receive pings or if he is willing to fix it … i see that @bsutton created the tomcat-with-ssl parts next in the list on the parts wikipage, perhaps he has a hint for you


#7

I do indeed get pings when you tag me :slight_smile:

my.war: webapps/my.war

This is using an example webapp file called my.war. You should replace this (both sides) with the name of your actual .war file in that local directory.


#8

Well, the tomcat build itself fails with

Redirection detected from https to http. Protocol switch unsafe, not allowed

and points you to the build.xml file, this is before the dump part (that puts the .war in place) is actually run at all …


#9

Ah, must be something new in Snapcraft. I’ve changed the URL for the tomcat source to use https, I’m not sure if this is immediately reflected in the Snapcraft remote parts or not, but see if a clean build will work now.


#10

@Siva mind re-trying your build to see if it succeeds now ?


#11

If this doesn’t fix it, it might be something in the Ant build plugin, in which case I’m not sure if I can fix it and we might need to drag @sergiusens into it


#12

It seems more likely, given where the failure occurs due to,

  • the fact that the tomcat source points to an unpinned subversion repo.
  • java or ant got updated on xenial to not support redirects.

Here’s the error in context:

Building tomcat 
ant
Buildfile: /home/ubuntu/t/parts/tomcat/build/build.xml

download-compile:

testexist:
     [echo] Testing  for /home/ubuntu/tomcat-build-libs/commons-daemon-1.1.0/commons-daemon-1.1.0.jar

downloadgz-2:

setproxy:

trydownload.check:

trydownload:
      [get] Getting: https://www.apache.org/dyn/closer.lua?action=download&filename=/commons/daemon/binaries/commons-daemon-1.1.0-bin.tar.gz
      [get] To: /home/ubuntu/tomcat-build-libs/download-1776729610.tar.gz
      [get] https://www.apache.org/dyn/closer.lua?action=download&filename=/commons/daemon/binaries/commons-daemon-1.1.0-bin.tar.gz moved to http://apache.dattatec.com//commons/daemon/binaries/commons-daemon-1.1.0-bin.tar.gz

BUILD FAILED
/home/ubuntu/t/parts/tomcat/build/build.xml:2618: The following error occurred while executing this line:
/home/ubuntu/t/parts/tomcat/build/build.xml:2924: The following error occurred while executing this line:
/home/ubuntu/t/parts/tomcat/build/build.xml:3040: Redirection detected from https to http. Protocol switch unsafe, not allowed.

Total time: 2 seconds
Failed to run 'ant' for 'tomcat': Exited with code 1.
Verify that the part is using the correct parameters and try again.

I am not really familiar with how ant really works out to be able to help further without ding a deep dive here.


#13

Hi guys, Sorry for the late reply… And thanks for all your responds… I will try to re-build my snap, and see if it succeeds or not?.. And let you guys know about it?


#14

@sergiusens I got the same error as you got. I have no idea how to solve this… Hope this conversation will help to solve this…


#15

Hi @sergiusens

  • the fact that the tomcat source points to an unpinned subversion repo.
  • java or ant got updated on xenial to not support redirects.

In that case how we snap the tomcat? Is there any other way to snap it?
If not what we can do for snap a web application.
Please guide me?


#16

According to the log, the Apache site is redirecting its download from HTTPS to HTTP, and therefore Snapcraft complains with ‘Redirection detected from https to http. Protocol switch unsafe, not allowed.’

See line:

[get] https://www.apache.org/dyn/closer.lua?action=download&filename=/commons/daemon/binaries/commons-daemon-1.1.0-bin.tar.gz moved to http://apache.dattatec.com//commons/daemon/binaries/commons-daemon-1.1.0-bin.tar.gz

Not a plugin issue as much as Snapcraft not allowing protocol switches.


#17

@pvanloo
In my snap I didn’t use a source from URL, I dump the source from my local system. It also gives error.
And the above error also caused by the after[tomcat] remote part.


#18

no, this is ant not allowing protocol switches when building tomcat, not a snapcraft issue at all …
my guess is that the build.xml simply needs to point to the http url by default, but that would be something to be fixed on the tomcat side.

digging a little deeper:

https://svn.apache.org/repos/asf/tomcat/tc8.5.x/trunk/build.properties.default

points to base-apache.loc.1=https://www.apache.org … while

https://svn.apache.org/repos/asf/tomcat/tc8.5.x/tags/TOMCAT_8_5_32/build.properties.default

uses base-apache.loc.1=http://www.apache.org

so if the code at

would be updated to not use trunk but one of the tags instead it would work …


#19

@ogra
Using this build.properties file, snap build successfully. https://svn.apache.org/repos/asf/tomcat/tc8.5.x/tags/TOMCAT_8_5_32/build.properties.default

But I don’t know how to call the web application in Ubuntu core. Can you please help me on this…


#20

you should be able to include the tomcat part directly in your snapcraft.yaml like:

(indeed with the fixed url) … that should install tomcat-launch and create a webapps dir in $SNAPCRAFT_PART_INSTALL … you should be able to use the same apps: section as above to have tomcat start.