How to deploy angular2 on tomcat? - eclipse

First I'd like to describe my set up:
I have a web service, let's call it "Cars", written in Java, that I've tested in eclipse with tomcat v6, working local (it was a requirement, so that once it works locally I can switch to do it with a "real" tomcat server so others can access). It works, it access the database, it offers an answer for certain URIs and so on.
I have coded in Plunker an angular 2 application, "WebCar", and I now want to run that on my computer, with a Tomcat server (unless there is a better way of doing it, I've been told to do it with Tomcat. Since I do not know any better option, that's why I talk about tomcat all of the time). With eclipse, I have already managed to get the app running, using palantir plugin for typescript https://marketplace.eclipse.org/content/typescript , and then running the project with a server-launch.js which contains require('lite-server'); , this allows me to see the same I saw on plunker, so, it works, but before I upload anything to the business servers I wanted to check everything works (hence the set up, which may not be necessary but it's what I come up with).
I now want to go one step further and use, if possible, tomcat v6 to run my angular 2 app, instead of simply using that lite server, so that I can test that it works, and then uploading it to a "real", remote server.
I would like to know what options are there, what would be a better option, and anything that is required to make an angular 2 deployment properly. So far I've found this
https://stackoverflow.com/a/34408495/6028947 " You only have to deploy
.js files, since anyway browser won;t" which I don't fully get,
http://jspm.io/ which is for SystemJS (I have an older version of
Angular 2 and use config.js)
https://stackoverflow.com/a/37568235/6028947 which talks about
angular-cli or webpack, which makes a bundle but if I got that
running, I still don't know what to do with it to upload to Tomcat
and then connect it to my web service.
So maybe the question should be (I don't know for sure): Once you get your angular 2 code bundled, what's next?
Btw there are a few other questions on stackOverflow, similar to this, but as far as I've seen, without any answer at all or with answers only obliquely related to this (and of course, nothing resembling a guide or step by step required)

Thanks to #nuzz for this ..
I'm running a little script to build the project and then copy it to tomcat. I'm telling angular what the base directory is that it will run under in tomcat.
#!/bin/sh
ng build --base-href /angular/ --prod
mkdir -p /home/xxx/apache-tomcat-8.0.37/webapps/angular
cp -R /home/xxx/angular-clitest/dist/* /home/xxx/apache-tomcat-8.0.37/webapps/angular/
Once thats run, start tomcat and you can access it at: http://localhost:8080/angular

Related

Getting requests only in one computer in UmbracoApi

I have a Umbraco API project that using the UmbracoCms library V 7.15.3. The project work properly, but from some reason after that i copy the project to another computer. The API stop to work there and requests did not comes to the controller.
Is there a reason for something like this to happen?
Umbraco gives you a web application which you need to install and setup somewhere before it will work.
You probably used their installer initially which created an IIS website and a database for you. You don't need to re-run the installer, but you do need to copy the database and all the files and re-create the website in IIS on the other computer.
Simply moving files around is not enough.

Run Protractor without node

I am building an AngularJS web application with Java as backend.When I look for an end to end testing framework, Protractor found to be a better option.But it is highly dependent on node.js(since it's built on top ofnode). Is that correct?
what I need is , I want to run Protractor with maven and tomcat. Can we run it without the dependency of node.js?
No, Protractor is dependent on Node.js So you have to use it.
There are two separate questions:
Can you run protractor without node? The answer is no. Protractor is a node project and requires node dependencies.
Can you use Protractor in a maven project? The answer is yes. I have not tried it but I've seen community members comment on this. A quick search to maven and protractor, I came across this stackoverflow for maven + protractor with the corresponding maven plugin project on github.
I hit this question since I'm wrestling with the same problem. This is what I've figured out.
Protractor (and Karma for the jsunit testing of Angular) requires node, but this isn't a large obstacle since you can pull in and install node using Maven, and use it to pull in yarn to get angular setup and built at deploy and test time. It is also possible to set up a proxy server from the node server to the Spring Boot App so that the REST endpoints will work.
What I want (and what I'm guessing the original poster wants) is to figure out a way to start up protractor without starting the node server. I don't want that server started because as part of the end to end testing I want to verify the spring app is serving the necessary static files correctly, not just the REST endpoints.
If I find an answer I'll update this.

Speeding up code changes in Eclipse Web Browser?

I'm developing an application using the Vaadin framework in Eclipse. I'm using the Tomcat v6.0 servlet and run the application in the Eclipse Web Browser. A problem I've been having though is to have recent changes show in the browser when I test the application.
No matter how many times I restart Tomcat, clean all published resources and restart the Eclipse Web Browser the changes still won't take effect. The changes seem to take effect randomly where time is the biggest factor, which is of great frustration when developing...
So my question is if anyone else has noticed this problem and have any ideas of how to solve it, if there is a configuration I can do or if I'm missing a step in the restart which blocks the changes from taking effect..?
Any help would be greatly appreciated!
In Vaadin most of the code runs in the server and is contained in normal Java files. There are three levels of resource/class changes:
The runtime "hot code replacement". If running Tomcat in debug mode some Java class changes can be published without redeploying the web application. However, if the Tomcat is configured to "auto publish" (check your server settings in Eclipse), the redeployment is automatically done whenever classes change and this causes full context reload and sessions serialization (see #2) . Hot code replacement can be enhanced using tools like JRebel.
Web application deployment. This is essentially deploying a new war file to the server. Causes the previous version to be undeployed and deploys the new version of all classes and resources. Sometimes there are some resources left in the servers work directory or classes are not reloaded, in which case the server restart (#3) is needed.
Server restart. This makes the whole JVM to reload and all the classes and web applications are also reloaded. Still cleaning the work directory separately is needed to make sure everything is reloaded.
In addition to this there is the client-side part of Vaadin (essentially a JavaScript compiled with GWT), which is treated as a static resource by Tomcat. If you modify the client-side Java code the GWT is used to recompile the JavaScript. Deployment should be simply file copying. The browsers cache the generated HTML/JS files, but GWT includes mechanism to avoid this.
You should first try to change the server settings for automatic publishing and see if that helps. Also, I've noticed that different Tomcat version behave differently. This is unfortunate, but the only thing you can do is to try to find the versions/set-up that works for you.
Just to make sure: you have been adding ?restartApplication in the URL to force application to restart on page reload, haven't you?

Remotely deploying in Tomcat 7 using HTTP PUT

I want to remotely deploy my web app in Tomcat 7. I have added manager-gui, manager-text roles and added a user in conf/tomcat-users.xml. I checked this link out.
Deploy A New Application Remotely
Here they have mentioned that we must upload the war file as HTTP PUT request. How do I achieve this ? I know there are ways to remotely deploy using ANT and Maven. But they look slightly complex to me. Using <form> with method="put" did not work.
The HTML FORM will only support GET and POST. If you want to do this via a Web Interface I think JQuery is the simplest route. Taking the time to build it into your build and deploy process is probably the best solution though.

eclipse howto start a application client on java ee glassfish appl srv

i have installed the glassfish eclipse tools bundle...
i can start a project like dynamic web & a ear project and deploy them on the glassfish... it works perfect & under the localhost url i will get an hello world
but how i do this if i want to make an application client. please help...
at the moment i simply created an "app client project in eclipse" & added it to the same ear,
but i have no idea how to start this...
help - any tutorial how to start?!!
Not the only only answer to this question but the appclient approach mentioned in Jeff's answer is a viable approach, but I was able to execute a client using this mechanism in eclipse and I wanted to share that approach.
This approach will let you execute a java application with a main method acting as a client.
What you want to do is setup an External Tools Configuration.
Create a new Program type of external tool configuration.
Set location to point to the path of the appclient, for me
(using embedded glassfish eclipse plugin) it was [PATH TO ECLIPSE]\plugins\oracle.eclipse.runtime.glassfish_3.1.1.0\glassfish3\glassfish\bin\appclient.bat
Set working directory to your output/build directory e.g.
${project_loc}/target/classes
Set arguments to ${java_type_name}
Select the class in your project with a main method that you wish to run as the client app and then select your external tool from the run external tools menu.
There are two ways to do it. I'm afraid I can't be very specific, but I can point you in the right direction. (I'm just learning myself)
You can enable Web Start for the application client EAR in GlassFish. You can do this either in the deployment descriptor (so it's enabled every time you deploy) or you can go into the GlassFish admin console, navigate to the Application, and check the checkbox to enable it. I have made a little progress on this approach.
You can run it manually from the command line using, I believe, the "appclient" command. I have not been able to get this working yet.
Good luck, and if you learn more, I'd appreciate it if you let me know since I'm in the same boat as you.
Jeff