我有以下目錄結構的dropwizard java應用程序。我有我的客戶端文件鏈接在index.html。Dropwizard無法加載客戶端文件
|-- 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 here.when運行環節以及所有加載的庫,但這裏指數.html被加載,而其中引用的文件無法加載。請在這裏獲取幫助。
注:
我看過很多帖子SO和HERE如何在Maven項目包裝資源「」>在這裏等,但一切都是徒勞?
編輯:
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");
}
}
你可以發佈一些信息嗎?您的主要應用程序類和服務器配置可能很有用 - 您需要確保已添加AssetsBundle,詳情請參見http://www.dropwizard.io/0.9.1/docs/manual/core.html#serving-資產 –
我已經使用此鏈接編輯了帶有文件的問題。 –