小编Mir*_*rko的帖子

来自一个maven项目的多个程序集

我们有不同的java源代码"项目".3个项目完全相同(fatclient,相同的依赖项等) - 只有另一个主类必须被调用.

今天我们有一个带有主类的基础项目:

<project>
    <groupId>net.company.BaseTool</groupId>
    <artifactId>BaseTool</artifactId>
    <version>1.1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>BaseTool</name>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>net.company.BaseTool</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

以及取决于基础项目的其他项目

<project>
    <groupId>net.company.AnotherTool</groupId>
    <artifactId>AnotherTool</artifactId>
    <version>1.1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AnotherTool</name>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>net.company.AnotherTool</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>net.company.BaseTool</groupId>
            <artifactId>BaseTool</artifactId>
            <version>1.1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

我们这样做,因为我们需要简单的双击可启动应用程序.

但我不想为每个应用程序创建一个额外的Java项目.

我的问题是:是否可以从一个项目创建多个程序集?如果是的话,应该怎么做.

这是解决方案

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.company.toolbox</groupId>
    <artifactId>toolbox</artifactId>
    <version>1.1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>toolbox</name>
    <url>http://wiki.company.my/toolbox</url>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <finalName>toolbox</finalName> …
Run Code Online (Sandbox Code Playgroud)

java maven maven-assembly-plugin

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

未调用Tomcat ServletContextListener.contextDestroyed

我们有多个MemoryLeaks(在catalina.out中找到),同时重新加载上下文.

为了清理这些线程,我创建了一个ServletContextListener的实现.

contextInitialized()创建上下文时成功调用该方法,因为我可以看到日志条目.

但是contextDestroyed()没有调用该方法,因此不会调用我的清理代码.任何想法为什么会这样?

我是否应该在需要重新加载上下文时实现另一个接口?

public class MyContextListener implements ServletContextListener {

    private static final Logger log = Logger.getLogger(MyContextListener.class);

    @Override
    public void contextDestroyed(final ServletContextEvent arg0) {
        MyContextListener.log.info("destroying Servlet Context");
        //Do stuff
        MyContextListener.log.info("Servlet Context destroyed");
    }

    @Override
    public void contextInitialized(final ServletContextEvent arg0) {
        try {
            MyContextListener.log.info("Creating Servlet Context");
            //Do stuff
        } finally {
            MyContextListener.log.info("Servlet Context created");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

tomcat servletcontextlistener

7
推荐指数
1
解决办法
7020
查看次数

无法识别带有Cp1252的DocumentException Arial

最近几个月,我使用字体Courier生成了成千上万的pdf(在Windows 7上进行开发,在OpenSuse进行测试和生产)。

现在我有了使用Arial的目标。所以我在属性文件中切换了字体名称,但出现了以下异常:

Stacktrace片段:com.itextpdf.text.DocumentException:无法识别带有'Cp1252'的字体'Arial'。在com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:708)在com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:615)在com.itextpdf.text.pdf.BaseFont.createFont (BaseFont.java:450)

谷歌一段时间后,我找到了解决方案。我只需要在设置中使用“ Arial.ttf”(如文件名)即可。但是之后,我又有了一个例外:

java.io.IOException: Arial.ttf not found as file or resource.
  at com.itextpdf.text.io.RandomAccessSourceFactory.createByReadingToMemory(RandomAccessSourceFactory.java:224)
  at com.itextpdf.text.io.RandomAccessSourceFactory.createBestSource(RandomAccessSourceFactory.java:173)
  at com.itextpdf.text.pdf.RandomAccessFileOrArray.<init>(RandomAccessFileOrArray.java:147)
  at com.itextpdf.text.pdf.TrueTypeFont.process(TrueTypeFont.java:625)
  at com.itextpdf.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:369)
  at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:699)
  at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:615)
  at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:450)
Run Code Online (Sandbox Code Playgroud)

因此,有一个提示,即itextpdf正在寻找文件。所以我只是将文件名输入C:\\Windows\\Fonts\\Arial.ttf到我们的配置中。现在可以了!

但是目标只是使用“ Arial”作为字体名称。可能吗?

非常感谢!

java itextpdf

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