How to create war file of angular project? - angularjs

I am working on project where I used angular as frontend and spring boot as backend. I want to deploy my project on Sentora control panel. It requires only war files to deploy on server. I created war file of spring project but I dont know how to create war file of angular project. I used vs code for angular. I tried to find the way of creating war file for angular on internet but didn't find any solution. Should I need to import angular project in eclipse? Please someone tell me step by step solution to create war file of angular project.
Update: Error while deploying wabit.war file
I deployed simple spring boot project demo-0.0.1-SNAPSHOT and it started.
wabit.war file is deployed but it doesn't start. It gives error
FAIL - Application at context path [/wabit] could not be started
Why is this happening?

You can use maven for doing that.
Just add a pom.xml in you project with the following information.
With this configuration you will have to build your angular application in a file directory named dist.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- The Basics -->
<groupId>your.group</groupId>
<artifactId>projectName</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<!-- Build Settings -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>dist</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
After creating this file you will have to use the following command
mvn clean install
and the file will be created in the target/ directory
You can find more information on maven-war-plugins in the apache maven official documentation

Another solution is instead of creating a war file for your angular project just embed it in the spring boot war.
To do that
Just create your angular dist by ng build command.
Copy the contents of everything in that folder.
Go to your Spring Boot project and paste them inside a static package in the resources
directory. The path should be src/main/resources/static
Create and deploy the Spring boot war file and your angular will run as well.
This is how you directory of spring boot should look like

Related

deploying spring app with react frontend to heroku

I have a react app with Spring backend. I have successfully deployed the Spring web app to Heroku, I can send http requests via postman to the endpoints and they work fine.
But I am unsure how I should allow the app on heroku to utilise the react frontend.
So far my structure is as below,
syftgolf
-.idea
-.mvn
-src
-target
-uploads-dev
-uploads-prod
-uploads-test
-.gitignore
-HELP.md
-mvnw
-mvnw.cmd
-pom.xml
-syftgolf.iml
-system.properties
Then in src I have
src
-main
--frontend //Front end react code
--java //Java code for Spring web app
--resources
-test
I am using the heroku CLI command git push heroku master on my route directory to deploy the app to heroku, this appears to then auto detact its a java app and then builds the app from there.
I am stuck though on how is the correct way to also build the react app? I read a post about building it first and adding it into the target/classes/static folder on my Spring app, but this folder doesn't appear to exist.
Which is the correct way to go about doing this please so when deployed, my app on heroku will also show the frontend stuff.
You need to tell maven where the react app resources are and where to add them in the output artifact. Use the maven resource plugin as follows:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/resources</outputDirectory>
<resources>
<resource>
<directory>/path/to/react/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Just change the resource directory path to your react app build directory. The plugin will copy all the files in the directory to your artifact resources folder so spring will find them.

Correct way to add thirdy-party dependencies on a wildfly-swarm ejb-jar deployment

I'm trying to create a wildfly swarm jar for a ejb-jar deployment that contains only a MDB.
The bean onMessage method is using a thirdy party library that's included in the project dependencies.
The generated uber jar contains the library but for some reason I get a ClassNotFound exception when I try to use the library.
If we change the packaging type from simple "jar" to "war" everything works as expected.
What is the correct way to add thirdy-party dependency to a simple ejb-jar deployment for wildfly swarm ?
I'm not sure what the "correct" solution is. It always seemed a bit odd to me that a thorntail package (formerlly wildfly swarm) always needed to be a WAR, and always needed to include undertow and/or jaxrs even if they were not being used.
As the first comment above aludes, it is posible to include third party dependencies in a JAR package.
Within src/main/resources of my maven project I've added the sub directories modules/com/example/mymodule/main and I've added module.xml inside of the main directory.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.example.mymodule">
<resources>
<artifact name="org.apache.pdfbox:pdfbox:2.0.13" />
</resources>
<dependencies>
<module name="org.apache.commons.logging"></module>
<module name="org.apache.commons.io"></module>
<module name="org.apache.httpcomponents"></module>
</dependencies>
</module>
The above xml references maven artifacts that I have included in my POM. You can also reference other modules.
I then added a jboss-deployment-structure.xml to src/main/resources/META-INF
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.example.mymodule" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Any 3rd party dependency that you add to your POM will now need adding to module.xml. It's a bit of a pain I know, it would be really nice if there was something that the maven plugin could do to automate this.

Error running local camel context

I am trying to execute the examples in Camel in action.
When I try to execute the "Spring DSL->Run As Local Camel Context" I am getting below error in JBoss Developer IDE:
Source locator does not exist: org.fusesource.ide.server.karaf.core.server.sourceLocator
Can any one help me?
I'm unaware of the build system of the project, but if it is Maven you may add following plugin to the pom.xml:
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.12.0</version>
<configuration>
<!--
the spring context file must be separate from the OSGi bundle, so we provide one here
-->
<fileApplicationContextUri>
src/main/resources/META-INF/spring/camel-context.xml
</fileApplicationContextUri>
</configuration>
</plugin>
where you can put the path to the camel-context.xml, and then you can run
mvn camel:run
to test the routes.
Hope I've helped you.
I had updated the plugin for fuse integration in Jboss IDE and it is working fine now.
Thanks a lot for your response.

GAE OAuth deploy using different accounts based on project

So when deploying to GAE with maven using OAuth it creates .appcfg_oauth2_tokens_java file in your home directory. This works great if you can deploy all your projects with one account. But what can you do when you wish to use different account for one of projects?
Can this file be project specific?
I don't wish to delete this file every time I want to deploy with different account.
You can prevent storing cookies with appcfg.sh --oauth2 --no_cookies.
For use with maven you can add the following config to your pom.xml:
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.9</version>
<configuration>
<oauth2>true</oauth2>
<noCookies>true</noCookies>
</configuration>
</plugin>

Using the google appengine maven plugin to deploy a Jax-RS war

I'm trying to make a simple base project to deploy a service I make using Jax-RS librarys to my Google app engine cloud space. The problem is that I don't know how to configure the plugin properly to not keep looking to a webapp directory under the target folder. The structure of the Jax-rs project puts the web.xml and all other WEB-INF files under the resources directory instead of a webapp directory. Is there a way to configure the maven plugin to deploy my already built and zipped up war file?
This is the error I see
[INFO] Updating Google App Engine Application Unable to find the
webapp directory C:\dev\gameTrunk\server\target\HOMMTG-server-1.0
usage: AppCfg [options] [] []
Action must be one of: help: Print help for a specific action.
download_app: Download a previously uploaded app version.
request_logs: Write request logs in Apache common log format.
rollback: Rollback an in-progress update. start: Start the specified
server version.
and it goes on with all the appengine plugin targets...
This s my pom
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.5.1</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/resources/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
</plugin>
</plugins>
Thats just the plugins part but its almost exactly the same as the guestbook example project except for the path for the WEB-INF directory
Currently there is no way to configure the appengine-maven-plugin to use a different directory for the war contents. It would be best though to probably create a multimodule build where one submodule just used the maven-ant-plugin to assemble the war directory and then run the plugin on that instead. I don't think we want to make that configurable in the plugin, since it doesn't really align with the maven-war-plugin, and configuring that would make it difficult to setup your project to use the maven-war-plugin seamlessly in the future.
The configuration you currently have for the war-plugin in your pom isn't necessary unless you want interpolation of the version number into the appengine-web.xml. I'm happy to help with setting up your pom so that the official Google App Engine Maven plugin works correctly for you.
(The instructions below apply to maven-gae-plugin, not appengine-maven-plugin.
Have I told you how much Google sucks in Open Source today?)
I think you must add in your maven-gae-plugin a property called appDir pointing to your webapp directory, like this:
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<configuration>
<appDir>PATH-TO-YOUR-BUILT-EXPLODED-WAR-PATH</appDir>
</configuration>
</plugin>
However, I must stress that changing the path in Maven produces undesirable results (you're mixing source and object code, your .ignore files will get messed up, and other weird things)
Note you STILL NEED your unpacked war somewhere. One way to achieve that is to create another .war project and use dependencies-unpack into it. See http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html
(reference: https://github.com/maven-gae-plugin/maven-gae-plugin/blob/master/maven-gae-plugin/src/main/java/net/kindleit/gae/EngineGoalBase.java)
(just in case, there is a JAX-RS based project for GAE I've wrote a while ago, and its open. See https://github.com/ipeirotis/ReadabilityMetrics/ for an overview)

Resources