简体   繁体   中英

Running a java jar with eclipse swt dependencies with maven-dependency-plugin

I'm making an eclipse plugin that I also want to make it work command line. As normal the usual problem is encountering the eclipse dependencies in command-line:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Layout
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 3 more

Now I know there is an eclipse FAQ for this problem however here is a bit different. I'm using Maven for build with the maven-dependency-plugin to add jars I need from other project to this jar as dependencies:

<build>
    <plugins>
        <plugin>
            <!-- Copy non-Eclipse plugins to target/dependency so that may be referenced 
                for runtime use. -->
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <!-- seems the line below is needed otherwise every second run the 
                            copy-dependencies fails , link to bug : https://bugs.eclipse.org/bugs/show_bug.cgi?id=393978 -->
                        <includeScope>runtime</includeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The dependencies in my Manifest file looks like this:

Rsrc-Class-Path: ./ 
 lib/jcommon-1.0.23.jar
 lib/jfreechart-1.0.19.jar
 lib/jfreechart-1.0.19-swt.jar
 lib/jfreechart-1.0.19-experimental.jar
 lib/swt.jar
 target/dependency/my.first.package.jar
 target/dependency/my.second.package.jar
Class-Path: .
Rsrc-Main-Class: my.package.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

Bundle-ClassPath: .,
 lib/jcommon-1.0.23.jar,
 lib/jfreechart-1.0.19-experimental.jar,
 lib/jfreechart-1.0.19-swt.jar,
 lib/jfreechart-1.0.19.jar,
 lib/swt.jar

Require-Bundle: org.eclipse.core.runtime,
 org.eclipse.ui,
 my.first.package;visibility:=reexport,
 my.second.package;visibility:=reexport,
 ca.odell.glazedlists,
 org.eclipse.nebula.widgets.nattable.core,
 org.eclipse.core.resources,
 org.eclipse.swt

As you can see I added an swt.jar to a lib inside my project and am referencing it there as to have all my dependencies inside my jar.

Still I get the above error when I try to run it command line as if the swt.jar isn't there.

What am I missing?

如果要使Eclipse插件命令行友好,最好的办法是让该插件还定义一个Eclipse应用程序,然后可以从命令行调用它: https : //wiki.eclipse.org/FAQ_How_do_I_create_an_application%3F

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM