While we continue the investigation into why I can't get Tomcat to run
within NetBeans, I thought that I would create a mockup of the
functionality that I would look to implement to protect the reloading
of the webapp until the files have been rebuilt. I have mimicked the
expected Tomcat listener for changes to a folder structure but of
course that will already exist within Tomcat and so will only be
looking to react to the existing events that are being triggered. If
anyone has a moment, can you have a quick look and see if what I am
proposing seems acceptable. The source is pretty short. To run this,
once compiled, you just need to create a blank folder (or reference an
existing one) and then amend the three constants, specifically to
reference your folder!

  static final String folderToWatch = "C:\\Community\\MonitorFolder";
  static final int timeToWatchSeconds = 30;
  // How long to listen for changes to files in the folder
  static final int timeForQuietMilliseconds = 5000;
  // How long to wait with no activity before triggering reload (list
directory files in my example)

The only minor observation is that if the period to listen for changes
expires prior to the period of no activity then the 'reload' task
(print the files in the directory) won't be triggered but as that
would (guessing now) only be when Tomcat was shut down then it would
be irrelevant anyway.



On Fri, 18 Feb 2022 at 17:03, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> John,
> On 2/18/22 10:50, John Barrow wrote:
> >>> Would you be interested in looking at the existing algorithm to see if
> >>> it would be updated in this way?
> >
> >> WebappLoader.backgroundProcess() would be a good place to start.
> >
> > I am sort of interested in looking at this.
> Awesome!
> > I have only been playing
> > with Java for about 6 months, having been a Pascal developer most of
> > my life (40 odd years). Therefore, I think that I could at least ‘give
> > it a look’, if I can get Tomcat installed locally.
> >
> > However, I appreciate that I could be well out of my depth and there
> > are too many unknowns / barriers in order to be of any use.
> >
> > It is the installation process that I am having issues with. I think
> > it is down to lack of experience / knowledge / familiarity with
> > commercial strength application.
> >
> > I use Netbeans 12.6 (Apache loyalty!) on Windows 10 for all my Java
> > development using JDK 17.
> >
> > Unfortunately, I am only ‘sort-of’ familiar with Maven and have never
> > touched Ant so I am flying a bit blind here, but that shouldn’t matter
> > if it all works as I don't need to touch the build process.
> >
> > I downloaded the ‘main’ branch from GitHub
> > (https://github.com/apache/tomcat) and unzipped it into its own
> > folder, again with Ant (apache-ant-1.9.16).
> >
> > I have managed to get Ant to build it using instructions in
> > BUILDING.txt. While it says that Tomcat built successfully, scrolling
> > up, I got lots of warnings saying ‘can’t find a module etc so not sure
> > if doing something wrong. I can send the results as an attachment if
> > that would be useful.
> >
> > I can also get it to build in Netbeans (I first had to set  Project >
> > Properties > Java Sources to Source Level 17 which may be a bit of a
> > guess as Netbeans complained about default value of 1.7). The java
> > files in Netbeans don’t highlight any exceptions, just warnings.
> >
> > I appear to have issues with the other two folders
> > ‘C:\Community\Tomcat\tomcat-main\webapps\docs\appdev\sample\src\mypackage’
> > and ‘C:\Community\Tomcat\tomcat-main\test’ as they don’t seem to be
> > able to locate the dependencies (HelloWorld is -e.g. import
> > jakarta.servlet.http.HttpServlet & tests is -e.g. import
> > org.junit.Assert). In Maven, I would add a dependency to the pom.xml
> > file, but not sure what to do in Ant as I would expect the
> > configuration to already be set up.
> Try this:
> 1. Close the project in NetBeans
> 2. On the command-line, go to the directory where your Tomcat git
> checkout is
> 3. Run "ant ide-netbeans"
> 4. Open the project again in Netbeans
> See if that improves anything. That ant target configures Netbeans in a
> way that should be "helpful". I don't use Netbeans myself, but the
> equivalent for Eclipse (ide-eclipse) sets up the build-path and lots of
> other goodies.
> > I also ran the ‘ant test’, took about 90 minutes and failed a number
> > of tests (which I thought was surprising as I would expect sources in
> > the repository to pass all the tests. I can provide examples if useful
> > as it may indicate that I have done something wrong.
> You can speed-up the unit tests by throwing more CPU cores at it; by
> default it uses just one. You can do that by adding this to
> build.properties in the same directory as the build.xml file:
> test.threads=n
> That n should be something ... reasonable. I have a 6-core hyperthreaded
> CPU (=12 logic CPUs) and setting the number of threads to 4
> significantly reduces the time to run the whole test-suite. I wouldn't
> set this to anything higher than the number of physical cores you
> actually have unless you don't want to use your computer for anything
> else during that test.
> As for test failures, some of them are known to fail in certain
> environments. Do you have a list of the tests which fail? Do you know
> how to get that list?
> I have an automated build-test-etc script[1] that performs this little
> gem after the unit tests have run:
> grep "\(Failures\|Errors\): [^0]"
> "${BASE_SOURCE_DIR}/output/build/logs/"TEST*.txt
> That should tell you which tests have failed. Feel free to post them
> here and we'll let you know if any of them are concerning.
> > I read through the ‘RUNNING.txt’ file, but that assumes a binary to
> > start, rather than following on from BUILDING Tomcat and so I couldn’t
> > relate that to what I was trying to achieve.
> If you can run the unit tests, then they are compiling and you should be
> able to build a binary release (ant deploy) without a problem.
> > However, if I launch Tomcat from within Netbeans (F6), I get a dialog
> > which I don’t understand - probably due to my lack of familiarity with
> > Ant. Again, I can include a screenshot if that would help.
> >
> > [Run – Tomcat 8.0]
> > No build target is associated with Run action.
> > The free-form project requires a target
> > Representing the Run action to invoke in
> > Your Ant script. Select the target to invoke.
> > [Dropdown with lots of tasks v]
> This might be solved by running "ant ide-netbeans". Or maybe not. You
> may have to pick a target. The "deploy" target is probably the one you
> want, or maybe "compile". Running ant from within an IDE only makes
> sense if you know what you are trying to accomplish, just like when
> running Maven. Maybe you just want a compile (mvn compile / ant
> compile), but maybe you want a JAR file to come out  (ant jar/mvn package).
> > Is there an alternative document I should be reviewing to get me to
> > actually run Tomcat from within Netbeans?
> >
> > I need to be able to run the locally built version of Tomcat so that,
> > as a starting point, I can add some System.out.print() messages around
> > the relevant routines (which I have located – thanks Mark). Of course
> > I am assuming that it is possible to develop Tomcat from within
> > Netbeans.
> >
> > While I would enjoy the challenge of reviewing the existing sources
> > and attempting to incorporate a delay, I may waste more peoples time
> > trying to get off the starting blocks. If that is the case, then I can
> > raise a bug for future inclusion although it will be a
> > pain-in-the-neck having to keep shutting down Tomcat after each
> > compile!
> Honestly, this community is all about getting people involved. We are
> happy to help you get up and running. How else do you think new
> committers are added to the project?
> -chris
> [1]
> https://github.com/ChristopherSchultz/apache-tomcat-stuff/blob/master/bin/test-tomcat-release.sh
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org

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

Reply via email to