小编Pau*_*lor的帖子

如何使用Maven创建具有完整依赖关系的独立应用程序?

我有一个使用Maven 2构建的桌面Java应用程序(但是如果有帮助的话我可以升级到Maven 3)有许多开源依赖项.我现在正尝试将其打包为独立版,以便最终用户无需安装maven或其他任何东西.

我已经成功地使用maven-assembly-plugin来构建一个包含所有依赖项的jar,但这并不是我想要的,因为在使用LGPL库时,您需要将您正在使用的库重新分发为单独的jar.

我希望Maven使用我的代码构建一个包含jar的zip,并且MANIFEST.MF引用我需要的其他jar和其他jar.这似乎是标准做法,但我看不出怎么做.

这是我的pom的摘录

     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <compilerVersion>1.6</compilerVersion>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.company.widget.Main</mainClass>
                            <packageName>com.company.widget</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.company.widget.Main</mainClass>
                            <packageName>com.company.widget</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build> 
Run Code Online (Sandbox Code Playgroud)

编辑:采取卡尔斯的想法

创建了一个名为descriptor.xml的文件

<?xml version="1.0" encoding="UTF-8"?>
<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>distribution</id> …
Run Code Online (Sandbox Code Playgroud)

java maven maven-assembly-plugin maven-jar-plugin

9
推荐指数
2
解决办法
1万
查看次数

如何在jstree中获取叶子节点,以便在使用jstree ui时单击时打开它们的超链接

我使用jtree显示层次结构,数据如下

<div id="songchanges"><ul>
<li id="phtml_1">
<a href="#">C:</a>
<ul>
<li id="phtml_2">
<a href="#">Music</a>
<ul>
<li id="phtml_3">
<a href="#">Z</a>
<ul>
<li id="phtml_4">
<a href="#">Hans Zimmer</a>
<ul>
<li id="phtml_5"><a href="FixSongsReport_00107_2013-09-04-11-11-55_body_blqxgT7E7YOmnBbjFXQGUg==.html">C:\Music\Z\Hans Zimmer\Hannibal</a></li>
</ul>
</li>
<li id="phtml_6">
<a href="#">The Zombies</a>
<ul>
<li id="phtml_7"><a href="FixSongsReport_00107_2013-09-04-11-11-55_body_er7mjWKbAaYaf8DygP84Fg==.html">C:\Music\Z\The Zombies\Best of The Zombies</a></li>
<li id="phtml_8"><a href="FixSongsReport_00107_2013-09-04-11-11-55_body_56XgVDhsjEKWXFd4OzVldA==.html">C:\Music\Z\The Zombies\The Zombies featuring Colin Blunstone & Rod Argent</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)

它显示没问题,作为一个文件系统.

这是框架集的一部分,显示在屏幕的左侧,当用户点击叶子节点时,我希望它打开右手边的附加链接(就像我在应用jtree之前一样)

我的jtree配置如下

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="songkong.css">
<base target="main">
<script type="text/javascript" …
Run Code Online (Sandbox Code Playgroud)

html javascript jstree

9
推荐指数
2
解决办法
2万
查看次数

H2和Postgres数组兼容性

我可以获得h2来支持Postgres数组语法

CREATE TABLE artists
(
release_id integer,
artist_name text,
roles text[]
)
Run Code Online (Sandbox Code Playgroud)

我在我的单元测试中使用h2来模仿Postgres,但由于角色的定义,它不喜欢上面的DDL(如果我注释掉它的工作列).H2确实有一个ARRAY数据类型有一种我可以编写的方式,以便我的代码可以使用h2或postgres

java postgresql h2

9
推荐指数
1
解决办法
1573
查看次数

我可以将谷歌博客网站嵌入我的网站

我有一个博客博客,我已经成功将域名设置为我的网站的子域名,例如http://blog.jthink.net

但是我如何实际将博客嵌入到我的网站上,以便它与我的主网站(http://www.jthink.net)具有相同的页眉和页脚,所以它更像是他们在这里做的方式

甚至可以与博主一起使用?

html blogger

9
推荐指数
2
解决办法
3万
查看次数

使用com4j连接到现有的iTunes实例

使用com4j和iTunes包装器,我可以启动iTunes的实例

 ClassFactory.createiTunesApp();
Run Code Online (Sandbox Code Playgroud)

从我的应用程序和成功使用api.

但是,如果iTunes已经独立运行,那么它就失败了

com4j.ExecutionException: com4j.ComException: 80080005 CoCreateInstance failed : Server execution failed : .\com4j.cpp:153
    at com4j.ComThread.execute(ComThread.java:236)
    at com4j.Task.execute(Task.java:26)
    at com4j.COM4J.createInstance(COM4J.java:99)
    at com4j.COM4J.createInstance(COM4J.java:74)
    at com.jthink.songkong.itunes.ClassFactory.createiTunesApp(ClassFactory.java:16)
    at com.jthink.songkong.ituneshelper.WindowsITunesModelCreator.createITunesModelInternal(WindowsITunesModelCreator.java:42)
    at com.jthink.songkong.ituneshelper.ITunesModelCreator.createITunesModel(ITunesModelCreator.java:263)
    at com.jthink.songkong.ituneshelper.ITunesModelCreator.run(ITunesModelCreator.java:227)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: com4j.ComException: 80080005 CoCreateInstance failed : Server execution failed : .\com4j.cpp:153
    at com4j.Native.createInstance(Native Method)
    at com4j.COM4J$CreateInstanceTask.call(COM4J.java:119)
    at com4j.COM4J$CreateInstanceTask.call(COM4J.java:106)
    at com4j.Task.invoke(Task.java:50)
    at com4j.ComThread.run0(ComThread.java:172)
    at com4j.ComThread.run(ComThread.java:153)
Run Code Online (Sandbox Code Playgroud)

因为iTunes已经在运行所以有没有办法可以连接到现有的iTunes实例,而不是在iTunes已经运行的情况下尝试创建一个新实例?

java com4j

9
推荐指数
1
解决办法
194
查看次数

如何在不渲染所有内容的情况下使用j2html

我正在转换我的HTML渲染代码以使用j2html.虽然我喜欢这个库,但我不容易一次性转换所有代码,所以有时我可能会将外部html转换为使用j2html,但无法同时将内部html转换为j2html.所以我希望j2html能够接受已经渲染的传递给它的文本,但它总是重新渲染它

System.out.println(p("<b>the bridge</b>"));
Run Code Online (Sandbox Code Playgroud)

回报

<p>&lt;b&gt;the bridge&lt;/b&gt;</p>
Run Code Online (Sandbox Code Playgroud)

有没有办法让它输出

<p><b>the bridge</b></p>
Run Code Online (Sandbox Code Playgroud)

完整测试案例

import j2html.tags.Text;

import static j2html.TagCreator.b;
import static j2html.TagCreator.p;

public class HtmlTest
{
    public static void main(String[] args)
    {
        System.out.println(p(b("the bridge")));
        System.out.println(p("<b>the bridge</b>"));
    }

}
Run Code Online (Sandbox Code Playgroud)

html java j2html

9
推荐指数
1
解决办法
752
查看次数

在Tomcat 7中,您需要将context.xml复制到conf/Catalina/locahost才能生效

刚刚从Tomcat 6迁移到Tomcat 7并注意到当您部署名为widget的webapp时,META-INF/context.xml不再被复制到conf/Catalina/localhost/widget.xml.

我不清楚它是否需要,如果保留在META-INF中,是否会使用context.xml中的设置,或者如果移动到conf/Catalina/localhost/widget.xml它们是否只有效果

我使用香草tomcat 7安装

java tomcat tomcat7

8
推荐指数
1
解决办法
2万
查看次数

如何根据AWS Elastic Beanstalk中的延迟配置扩展?

部署到AWS Elastic Beanstalk的应用程序的延迟通常约为50毫秒,如果平均延迟时间达到500毫秒(1/2秒),我希望启动另一个实例.您可以在配置改变缩放触发和选择延迟,但最小的计量单位第二上部下部规模增量值必须为整数或百分比.

因此,似乎无法根据需要设置触发器.

amazon-web-services amazon-elastic-beanstalk

8
推荐指数
1
解决办法
3844
查看次数

如何向非超级用户提供Postgres扩展

我安装了Postgres扩展(unaccent)

sudo su posgres
psql create extension unaccent
Run Code Online (Sandbox Code Playgroud)

现在我可以在sql中使用unacccent,前提是我是Postgres用户.

如何向所有/另一个用户提供Postgres扩展

(我在Ubuntu上使用apt-install安装Postgres 9.3.5)

jthinksearch=# \dx;
                         List of installed extensions
   Name   | Version |   Schema   |                 Description
----------+---------+------------+---------------------------------------------
 plpgsql  | 1.0     | pg_catalog | PL/pgSQL procedural language
 unaccent | 1.0     | public     | text search dictionary that removes accents
(2 rows)

jthinksearch=#


jthinksearch=> \du;
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 ubuntu    |                                                | …
Run Code Online (Sandbox Code Playgroud)

postgresql psql

8
推荐指数
2
解决办法
8593
查看次数

ITunes似乎没有为其新的运动和工作领域公开COM接口

我使用Com4j让我的Java应用程序与Windows上的iTunes通信,我看到我生成的类不包含让我更新移动工作字段的方法,比如我可以更新其他字段,如艺术家专辑.

所以我重新使用了这些类

  c:\Code\jthink\opensrc\com4j-20120426-2>java -jar tlbimp.jar -o C:\Code\jthink\SongKong\src\main\java -p com.jthink.songkong.itunes  "C:\Program Files\iTunes\iTunes.exe"
Run Code Online (Sandbox Code Playgroud)

针对最新的12.6 iTunes exe,他们仍然不在这里.(我希望它们在IITFileOrCDTrack.java中)我做错了什么或者这是否意味着iTunes必须明确代码才能公开新字段并且他们决定不这样做.

那么这是否意味着iTunes必须明确地编写一个新的COM接口,以使其他程序可以访问这些字段

请注意,这些新字段可通过Mac机器上的applescript获得

com itunes com4j

8
推荐指数
1
解决办法
104
查看次数