首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >WebLogic不使用上下文路径加载javascript文件

WebLogic不使用上下文路径加载javascript文件
EN

Stack Overflow用户
提问于 2017-05-24 20:56:39
回答 2查看 1K关注 0票数 0

我创建了一个war,其中包含我的后端应用程序(Spring Boot)和前端应用程序(Angular2)。在前端应用程序中,我使用Angular CLI来创建分发文件。

我需要将这个war部署到WebLogic应用服务器。

为了构建前端项目,我通过exec-maven-plugin运行“ng build”命令。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
        <execution>
            <id>exec-npm-install</id>
            <phase>generate-sources</phase>
            <configuration>
                <workingDirectory>${project.basedir}/src/main/ngapp</workingDirectory>
                <executable>npm.cmd</executable>
                <arguments>
                    <argument>install</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
        <execution>
            <id>exec-npm-ng-build</id>
            <phase>generate-sources</phase>
            <configuration>
                <workingDirectory>${project.basedir}/src/main/ngapp</workingDirectory>
                <executable>ng.cmd</executable>
                <arguments>
                    <argument>build</argument>
                    <argument>--base-href=/applicationName</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

index.html的内容

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>CometTest</title>
  <base href="/applicationName">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app>Loading...</app>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="scripts.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>

当我在本地机器上使用contextPath='applicationName'将产生的war部署到Tomcat时,它工作得很好。

但是当我部署到远程WebLogic时,它在加载javascript文件时抛出错误。

Failed to load resource: the server responded with a status of 404 (Not Found) http://24.211.213.46:7611/inline.bundle.js

为什么WebLogic尝试在url中没有applicationName的情况下下载文件?

我可以通过下面的url访问这个javascript文件:

http://24.211.213.46:7611/applicationName/inline.bundle.js
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-14 21:54:07

为了正确加载我的javascript文件,我必须使用deploy-url参数

ng build --environment=prod --deploy-url http://24.211.213.46:7611/applicationName
票数 0
EN

Stack Overflow用户

发布于 2017-06-07 23:57:17

我也有同样的问题。我能够通过更改路由策略来修复它,以使用如下所示的散列:

imports: [RouterModule.forRoot(APP_ROUTES, { useHash: true })]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44159074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档