我有以下目录结构的dropwizard java application.I我的客户端文件链接在index.html中。
|-- pom.xml
|-- src
| |-- main
| | |-- java
| | |-- resources
| | | |--assets
| | | | |--css
| | | | |--js all js files
| | | | |--lib all libraries
| | | | |--index.html
Index.html包含
等链接<link href="/css/bundle.css" rel="stylesheet">
<script src="/js/index.js"></script>
<script src="/lib/satellizer.min.js"></script>
我在这里尝试了几乎所有类型的链接。当在xampp中运行时,这个客户端正在运行,并且所有库都已加载但是这里加载了index.html,而其中引用的文件没有加载。请任何帮助这里。
注:
我见过很多SO帖子HERE以及如何在Maven项目中打包资源?“”&gt; HERE等但都是徒劳。
修改:
helloworldapplication.java:
package com.example.helloworld;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.hibernate.HibernateBundle;
import io.dropwizard.migrations.MigrationsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import javax.ws.rs.client.Client;
import com.example.helloworld.HelloWorldConfiguration.ClientSecretsConfiguration;
import com.example.helloworld.auth.AuthFilter;
import com.example.helloworld.core.User;
import com.example.helloworld.db.UserDAO;
import com.example.helloworld.resources.AuthResource;
import com.example.helloworld.resources.ClientResource;
import com.example.helloworld.resources.UserResource;
public class HelloWorldApplication extends Application<HelloWorldConfiguration> {
public static void main(final String[] args) throws Exception {
new HelloWorldApplication().run(args);
}
private final HibernateBundle<HelloWorldConfiguration> hibernateBundle =
new HibernateBundle<HelloWorldConfiguration>(User.class) {
@Override
public DataSourceFactory getDataSourceFactory(final HelloWorldConfiguration configuration) {
return configuration.getDataSourceFactory();
}
};
@Override
public String getName() {
return "hello-world";
}
@Override
public void initialize(final Bootstrap<HelloWorldConfiguration> bootstrap) {
bootstrap.addBundle(new MigrationsBundle<HelloWorldConfiguration>() {
@Override
public DataSourceFactory getDataSourceFactory(final HelloWorldConfiguration configuration) {
return configuration.getDataSourceFactory();
}
});
bootstrap.addBundle(hibernateBundle);
bootstrap.addBundle(new AssetsBundle("/assets/js/bundle.js", "/bundle.js", null, "bundle"));
bootstrap.addBundle(new AssetsBundle("/assets/css", "/stylesheets", null, "css"));
bootstrap.addBundle(new AssetsBundle("/assets/lib/lib.js", "/lib.js", null, "lib"));
bootstrap.addBundle(new AssetsBundle("/assets/vendor", "/vendor", null, "vendor"));
}
@Override
public void run(final HelloWorldConfiguration configuration, final Environment environment)
throws ClassNotFoundException {
final UserDAO dao = new UserDAO(hibernateBundle.getSessionFactory());
final Client client =
new JerseyClientBuilder(environment).using(configuration.getJerseyClient())
.build(getName());
final ClientSecretsConfiguration clientSecrets = configuration.getClientSecrets();
environment.jersey().register(new ClientResource());
environment.jersey().register(new UserResource(dao));
environment.jersey().register(new AuthResource(client, dao, clientSecrets));
environment.servlets().addFilter("AuthFilter", new AuthFilter())
.addMappingForUrlPatterns(null, true, "/api/me");
}
}
答案 0 :(得分:0)
将客户端资源链接到index.html(请在资源文件夹 src / main / resources 下提供正确的路径)
更改AssetsBundle构造函数以将资源包文件添加到dropwizard
@Override
public void initialize(Bootstrap<FulfilmentOptionsConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets/*", "/index"));
}