由于新的模块系统,Java 9(jdk-9 + 170)默认情况下不允许应用程序查看JDK中的所有类,这与以前的所有Java版本不同.
要解决此问题,java命令行会提供一个新参数--add-exports,允许按如下方式中断封装:
java -jar josm.jar --add-exports java.base/sun.security.util=ALL-UNNAMED --add-exports java.base/sun.security.x509=ALL-UNNAMED
这在JEP 261中得到了很好的解释.
我已经阅读了--add-opens使用相同语法的类似选项,但是JEP 261尚未更新来描述它(最后更新:2017/03/08 13:58).
这两个选项有什么区别?
编辑:JEP 261已在2017-09-22更新以解释它.
java command-line-arguments java-platform-module-system java-9 java-module
我们在Java应用程序中定义了一个包含以下内容的自定义HTTP User-Agent:
我们希望将此用户代理应用于应用程序创建的所有HTTP连接,包括我们手动打开的连接,以及JRE自动创建的连接,例如,当JEditorPane解析HTML代码中引用的外部图像时.
为此,我们在应用程序启动时将"http.agent"系统属性设置为1/2/3点(让JRE自己添加Java版本):
System.setProperty("http.agent", Version.getAgentString());
Run Code Online (Sandbox Code Playgroud)
当我们从jar运行应用程序时,这很有用,但不是从Java Web Start运行.
作为解决方法,我们手动将完整的User-Agent设置为我们手动创建的连接:
public static HttpURLConnection openHttpConnection(URL httpURL) throws IOException {
HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection();
connection.setRequestProperty("User-Agent", Version.getFullAgentString());
return connection;
}
Run Code Online (Sandbox Code Playgroud)
但这并不能处理JRE(JEditorPane示例)创建连接的情况.
在这种情况下,我们如何设置用户代理?
我们试图sun.net.www.protocol.http.HttpURLConnection.userAgent通过使用这个例子中的反射来改变它的值,但它不起作用,我们正面临着一个问题IllegalAccessException.
我们既不能在JNLP文件中设置User-Agent,因为无法确定客户端信息(用户语言+平台).
我在使“ @link”和“ @see”标签适用于内部/嵌套类的构造函数时遇到了问题,希望这里有人能提供帮助。这个简短的示例类在第25行上给出了Javadoc警告,引用了“ Layer()”文档前几行中的“ @link”和(等效)“ @ see”标记。
package bogus;
import javax.swing.JPanel;
public class LayeredPlot extends JPanel {
/**
* Constructor for the plot.
*/
public LayeredPlot() {
}
public static class Layer {
private String name;
/**
* Construct a default layer with a default name. This method calls
* {@link LayeredPlot.Layer#Layer(String)} OR calls == JAVADOC WARNING
* {@link #Layer(String)} OR calls == JAVADOC WARNING
* {@link Layer#Layer(String)} == JAVADOC WARNING
* with a null name to perform the construction. …Run Code Online (Sandbox Code Playgroud) 我们的Java 7应用程序需要在localhost上侦听HTTPS请求.它必须接受https://localhost:8112和的连接https://127.0.0.1:8112.
为此,我们以编程方式构建了自动签名的X509v3证书,并且我们已在Windows-ROOT密钥库中安装此证书,如下所示:
KeyStore.TrustedCertificateEntry trustedCert = ...;
KeyStore ks = KeyStore.getInstance("Windows-ROOT");
ks.load(null, null);
ks.setEntry("xxxx_localhost", trustedCert, null);
Run Code Online (Sandbox Code Playgroud)
这使得Chrome 36在两种情况下都接受了证书(localhost和127.0.0.1),但IE 11在访问127.0.0.1时无法将证书识别为有效localhost:

为什么?通过使用包,使用BasicConstraints,ExtendedKeyUsage和SubjectAlternativeName扩展来构建证书,如下所示sun.security.x509:
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(2048);
KeyPair kp = generator.generateKeyPair();
X509Certificate cert = generateCertificate("CN=localhost, OU=XXX, O=XXX", kp,
1825, "SHA256withRSA", "ip:127.0.0.1,dns:localhost,uri:https://127.0.0.1:8112");
/**
* Create a self-signed X.509 Certificate.
* @param dn the X.509 Distinguished Name
* @param pair the KeyPair
* @param days how …Run Code Online (Sandbox Code Playgroud) 我在eclipse中运行了一个JSF2(Richfaces 4.1.0)项目.我正在尝试使用mojarra jsf实现(2.2.0)在WAS 8.5上运行它.然后lib提供maven但服务器似乎覆盖它们,因为在控制台中我可以读取Myfaces已被加载.
我想知道为什么这样做?如何让项目使用mojarra而不使用共享库是管理控制台?
这是maven相关的代码部分:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
提前致谢
java ×4
http ×1
java-9 ×1
java-module ×1
java-platform-module-system ×1
javadoc ×1
localhost ×1
maven-3 ×1
richfaces ×1
ssl ×1
user-agent ×1
websphere-8 ×1