我已经看到其他人遇到过这个问题,在安装m2e插件后,Maven没有在Eclipse中出现这个问题,但大多数解决方案似乎建议做"配置>转换为Maven".但Maven没有在配置列表中显示给我,也没有显示在Console> Open Console或File> New列表中.我看到一些解决方案是指编辑项目的类路径,但我不清楚如何做到这一点.我正在尝试开始编写一本关于Java EE7的书,它在示例中使用了Maven.有人可以帮忙吗?
我在我的VPS上部署war文件时遇到了很多问题.
我有java-8和tomcat-8.我的服务器是Apache/2.2.22(Debian),我的HTTP在端口80上,tomcat在8080上.
目前,如果您访问www.drew-jocham.com,则会列出一个空目录.但是,如果您访问www.drew-jocham.com:8080/resumesite,您将获得在tomcat上运行的页面.
当然,我要做的是让用户输入www.drew-jocham.com而不是端口等.
到目前为止,我已经设置了一个虚拟主机 nano /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin drew@drew-jocham.com
ServerName www.drew-jocham.com
ServerAlias drew-jocham.com
ProxyPass /resumesite http://localhost:8080/resumesite
ProxyPassReverse /resumesite http://localhost:8080/resumesite
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
在tomcat中我的server.xml文件中我设置了一个 <Host></Host>
<Host name="www.drew-jocham.com" appbase="webapps"
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="resumesite_log." suffix=".txt"
pattern="common"/>
</Host>
Run Code Online (Sandbox Code Playgroud)
通过上面的设置,每个域都只列出了我的VPS目录.此时我不知道该怎么办.
我的问题是:
我希望用户输入www.drew-jocham.com而不是www.drew-jocham.com:8080/resumesite.我试图这样做,但就像我上面说的,我的VPS上的每个域都只是用上面的设置列出我的服务器整个目录.
很快所有网站都将成为战争文件,因此服务器上会有多个域名.有些将直接存储在tomcat webapps中,有些则存储在端口80上的HTTP服务器上.
-------------------更新1 -------------------
我去nano /etc/apache2/sites-enabled/000-default.conf添加以下内容并重新启动我的tomcat服务器.
<VirtualHost *:80>
ServerAdmin drew@drew-jocham.com
ServerName www.drew-jocham.com
ServerAlias drew-jocham.com
ProxyPass / http://localhost:8080/resumesite
ProxyPassReverse / http://localhost:8080/resumesite
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
当我去www.drew-jocham.com时,除了以下图片之外,仍然没有任何渲染:
它还将www.drew-jocham/resumesite添加到我的VPS上的每个域中,其中我有几个,从而打破了它们.
但是,如果我仍然去www.drew-jocham.com:8080/resumesite它渲染.
我正在测试/切换到Java EE7(Glassfish 4),我遇到的一个问题是拦截器,每当我尝试运行项目时,我都会收到以下错误.
严重:加载应用程序时出现异常:CDI部署失败:WELD-001417文件中启用拦截器类com.xxxxxx.security.SecuredInterceptor:/home/xxxxxx/xxxxxx/target/xxxxxx/WEB-INF/beans.xml@7既不是注释@Interceptor也没有通过便携式扩展注册
我正在看CDI 1.1规范的1.3.6节,它看起来没什么变化,所以我做错了什么?
这是我正在使用的代码;
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Secured {}
Run Code Online (Sandbox Code Playgroud)
@Secured
@Interceptor
public class SecuredInterceptor implements Serializable
{
@AroundInvoke
public Object interceptSecured(InvocationContext ic) throws Exception
{
// Do Stuff
}
}
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">
<interceptors>
<class>com.xxxxxx.security.SecuredInterceptor</class>
</interceptors>
</beans>
Run Code Online (Sandbox Code Playgroud) 我喜欢在Java中使用JSON序列化标准的想法,javax.json是向前迈出的一大步,你可以像这样做一个对象图:
JsonObject jsonObject3 =
Json.createObjectBuilder()
.add("name", "Ersin")
.add("surname", "Çetinkaya")
.add("age", 25)
.add("address",
Json.createObjectBuilder()
.add("city", "Bursa")
.add("country", "Türkiye")
.add("zipCode", "33444"))
.add("phones",
Json.createArrayBuilder()
.add("234234242")
.add("345345354"))
.build();
Run Code Online (Sandbox Code Playgroud)
就是这样,但是如何将pojo或简单的Java对象(如Map)直接序列化为JSON?就像我在Gson中所做的那样:
Person person = new Person();
String jsonStr = new Gson().toJson(person);
Run Code Online (Sandbox Code Playgroud)
如何使用新标准API执行此操作?
我有多个java项目.这些项目使用gradle创建jar,war和ear文件.在每个项目中,我使用清单文件来维护元数据,如版本,日期时间......为此我在每个build.gradle文件中都包含了清单文件创建逻辑.
manifest {
attributes(
'Bundle-Vendor' : "$BUNDLE_VENDOR",
'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"))
}
Run Code Online (Sandbox Code Playgroud)
但在Gradle中有一个功能调用sharedManifest.我在主项目build.gradle脚本中定义了以下两个任务.但是在每个jar和war文件中都有Gradle创建的默认MANIFEST.MF文件.
ext.sharedManifest = manifest {
attributes(
'Bundle-Vendor' : "$BUNDLE_VENDOR",
'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
)
}
task fooJar(type: Jar) {
manifest = project.manifest {
from sharedManifest
}
}
task fooWar(type: War) {
manifest = project.manifest {
from sharedManifest
}
}
Run Code Online (Sandbox Code Playgroud)
jar.manifest.writeTo("/ MANIFEST.MF")war.manifest.writeTo("/ MANIFEST.MF")
请有人提出如何做的建议.
我试图使用Java EE 7 JsonBuilder并且无法理解createBuilderFactory的config参数.是的,可以将其留空或为空,但还有什么可以做的?
JsonBuilderFactory factory = Json.createBuilderFactory(config);
JsonObject value = factory.createObjectBuilder()
.add("firstName", "John")
.add("lastName", "Smith")
.add("age", 25).build();
Run Code Online (Sandbox Code Playgroud)
配置怎么办?冒号或逗号周围的间距?每个阵列的换行符?我不知道如何查看源代码,它似乎没有记录在json的Java EE页面上(http://docs.oracle.com/javaee/7/api/index.html?javax /json/Json.html)
在javax.faces.webapp.FacesServlet文档中,提到了,
允许的HTTP方法
JSF规范只需要使用GET和POST http方法.如果您的Web应用程序不需要任何其他http方法,例如PUT和DELETE,请考虑使用
<http-method>和<http-method-omission>元素限制允许的http方法.有关使用这些元素的更多信息,请参阅Java Servlet规范的安全性.
我的应用程序确实不依赖于其他HTTP方法(除了GET和POST).因此,我试图使用<http-method>(或<http-method-omission>)排除除GET和之外的所有方法POST.
在web.xml中,JAAS Servlet安全性约束配置如下.
<security-constraint>
<display-name>AdminConstraint</display-name>
<web-resource-collection>
<web-resource-name>ROLE_ADMIN</web-resource-name>
<description/>
<url-pattern>/admin_side/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>ROLE_ADMIN</role-name>
</auth-constraint>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<display-name>UserConstraint</display-name>
<web-resource-collection>
<web-resource-name>ROLE_USER</web-resource-name>
<description/>
<url-pattern>/user_side/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>ROLE_USER</role-name>
</auth-constraint>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
使用这些元素,
<http-method>GET</http-method>
<http-method>POST</http-method>
Run Code Online (Sandbox Code Playgroud)
我希望不允许所有其他HTTP方法.
但是,GlassFish Server 4.1在服务器终端上记录以下警告.
警告:JACC:对于URL模式
/user_side/*,除了以下方法之外的所有方法都被发现:POST,GET警告:JACC:对于URL模式
/admin_side/*,除了以下方法之外的所有方法都被发现:POST,GET
这是什么意思?
此外,它不是在所有<security-constraint>元素中执行,而是可以全局配置,以便它可以应用于应用程序中的所有资源, …
我想知道Java EE 7的核心接口是否扩展AutoCloseable.(通过核心接口我的主要意思EntityManager和喜欢,但我不确定是否有其他接口或类可能会自动关闭.)
我认为他们应该而且这里是我假设的基础.
Java 6Connection甚至没有扩展Closeable,但Java 7的Connection扩展AutoCloseable(就像java.sql包中的其他几个接口一样).
在Java 7的声明中,接口是否可以EntityManager扩展AutoCloseable以便为我们提供良好的服务?或者自动神奇地关闭太复杂了?try-with-resourcesEntityManager
这个特殊功能是否被认为是JSR-342的一部分?
如何使用认可的标准机制在GlassFish 4.0 WAR应用程序中使用xerces?根据文档*,你应该把它放进去domain-dir/lib/endorsed.但是,当我将xercesImpl,xml-apis以及xml-resolver放在那里时,这些类在WAR中的类中不可用.这最可能是由于文档和默认配置之间的不一致:domain.xml不列出domain-dir/lib/endorsed.
当我包含它或放入文件时glassfish-install-dir/lib/endorsed,启动失败,出现以下异常:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:97)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:54)
Caused by: A MultiException has 5 exceptions. They are:
1. javax.xml.stream.FactoryConfigurationError: Provider com.ctc.wstx.stax.WstxOutputFactory not found
2. java.lang.IllegalStateException: Unable to perform operation: create on com.sun.enterprise.v3.server.DomainXmlPersistence
3. javax.xml.stream.FactoryConfigurationError: Provider com.ctc.wstx.stax.WstxInputFactory not found
4. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.sun.enterprise.v3.server.GFDomainXml errors were found
5. java.lang.IllegalStateException: Unable …Run Code Online (Sandbox Code Playgroud) 我有以下GenericRest类,我用它来扩展基于使用@XmlRootElement注释的Entity类的rest类.
public class GenericRest<T extends BaseEntity> {
@Inject @Service
GenericService<T> service;
public GenericService<T> getService() {
return service;
}
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getAll() {
// This works for JSON but does not work for XML Requests.
List<T> list = getService().findAll();
// This just gives the attributes for the BaseEntity.
//GenericEntity<List<T>> list = new GenericEntity<List<T>>(getService().findAll()) {};
return Response.ok(list).build();
}
}
Run Code Online (Sandbox Code Playgroud)
将APPLICATION_JSON在目前注释掉情况做工精细,但APPLICATION_XML给错误:
找不到类型的响应对象的MessageBodyWriter:java.util.Array媒体类型列表:application/xml
注释的情况适用于两种MediaTypes,但只返回BaseEntity扩展类的属性,而不是添加的属性.如何获取扩展类的属性并使两个MediaType都有效?
可在此处找到完整的存储库(正在进行中):https://github.com/martijnburger/multitenant
===更新1 ===
我更改@XmlSeeAlso了实体上的注释.这是在特定的实体,但需要在 …