当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Separating front end assets from back end server in spring

问题描述:

I'm very new to spring, I created a project and would like to be able to run the project with both node and spring, so i would like to separate the project into a structure like this:

myapp

| _____ui

| |______ js

| |______ css

|

|______server

| |____src/main/java etc

|

i have created the following pom files

pom.xml in myapp directory

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"

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>

<groupId>org.springframework.samples</groupId>

<artifactId>spring-resource-handling</artifactId>

<version>0.1.0.BUILD-SNAPSHOT</version>

<packaging>pom</packaging>

<name>Spring Resource Handling</name>

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.2.3.RELEASE</version>

</parent>

<modules>

<module>server</module>

</modules>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<java.version>1.8</java.version>

</properties>

<repositories>

<repository>

<id>spring-snapshots</id>

<name>spring-snapshots</name>

<snapshots/>

<url>http://repo.spring.io/libs-snapshot</url>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<id>spring-snapshots</id>

<name>spring-snapshots</name>

<snapshots/>

<url>http://repo.spring.io/libs-snapshot</url>

</pluginRepository>

</pluginRepositories>

pom file in myapp/server directory

<?xml version="1.0" encoding="UTF-8"?>

<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>

<groupId>org.test</groupId>

<artifactId>demo</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>

<name>demo</name>

<description>Demo project for Spring Boot</description>

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.2.5.RELEASE</version>

<relativePath/> <!-- lookup parent from repository -->

</parent>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<java.version>1.8</java.version>

</properties>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-war-plugin</artifactId>

<version>2.6</version>

<configuration>

<webResources>

<resource>

<!-- this is relative to the pom.xml directory -->

<directory>../ui</directory>

</resource>

</webResources>

</configuration>

</plugin>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>

so I'm trying to use the pom file to copy the resources file before the build

 <plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-war-plugin</artifactId>

<version>2.6</version>

<configuration>

<webResources>

<resource>

<!-- this is relative to the pom.xml directory -->

<directory>../ui</directory>

</resource>

</webResources>

</configuration>

</plugin>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

does this even going to work?? currently I can't find my js files in the target directory when i do mvn package - is there a better way of doing this?

分享给朋友:
您可能感兴趣的文章:
随机阅读: