2016-01-17 132 views
0

我正在使用Eclipse来编译带有aspectj的java代码。 我的代码(与方面)工作正常,但我努力创建这个我的代码的jar文件。例如,如果我选择Export> Runnable JAR文件,在组合框中,我看不到我的项目(所有其他不基于aspecj的项目都显示在组合框中)。如何使用AspectJ创建可运行jar文件?

回答

2

如果你喜欢重复的建立,其工作由命令行以及来自像Eclipse或IntelliJ IDEA的IDE中,我推荐一个Maven构建。该onejar - Maven的插件创建一个可运行的JAR包括AspectJ运行,并为你的所有其他声明的依赖性:

<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>de.scrum_master.stackoverflow</groupId> 
    <artifactId>my_project</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <java.source-target.version>1.7</java.source-target.version> 
     <aspectj.version>1.8.8</aspectj.version> 
     <main-class>de.scrum_master.app.Application</main-class> 
    </properties> 

    <build> 

     <pluginManagement> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>3.3</version> 
        <configuration> 
         <source>${java.source-target.version}</source> 
         <target>${java.source-target.version}</target> 
         <!-- IMPORTANT --> 
         <useIncrementalCompilation>false</useIncrementalCompilation> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>aspectj-maven-plugin</artifactId> 
        <version>1.8</version> 
        <configuration> 
         <!--<showWeaveInfo>true</showWeaveInfo>--> 
         <source>${java.source-target.version}</source> 
         <target>${java.source-target.version}</target> 
         <Xlint>ignore</Xlint> 
         <complianceLevel>${java.source-target.version}</complianceLevel> 
         <encoding>${project.build.sourceEncoding}</encoding> 
         <!--<verbose>true</verbose>--> 
         <!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn>--> 
        </configuration> 
        <executions> 
         <execution> 
          <!-- IMPORTANT --> 
          <phase>process-sources</phase> 
          <goals> 
           <goal>compile</goal> 
           <goal>test-compile</goal> 
          </goals> 
         </execution> 
        </executions> 
        <dependencies> 
         <dependency> 
          <groupId>org.aspectj</groupId> 
          <artifactId>aspectjtools</artifactId> 
          <version>${aspectj.version}</version> 
         </dependency> 
        </dependencies> 
       </plugin> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>exec-maven-plugin</artifactId> 
        <version>1.4.0</version> 
        <configuration> 
         <mainClass>${main-class}</mainClass> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.dstovall</groupId> 
        <artifactId>onejar-maven-plugin</artifactId> 
        <version>1.4.4</version> 
        <executions> 
         <execution> 
          <goals> 
           <goal>one-jar</goal> 
          </goals> 
         </execution> 
        </executions> 
        <configuration> 
         <onejarVersion>0.96</onejarVersion> 
         <mainClass>${main-class}</mainClass> 
         <attachToBuild>true</attachToBuild> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 

     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>aspectj-maven-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <groupId>org.dstovall</groupId> 
       <artifactId>onejar-maven-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 

    </build> 

    <pluginRepositories> 
     <pluginRepository> 
      <id>OneJAR googlecode.com</id> 
      <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url> 
     </pluginRepository> 
    </pluginRepositories> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.aspectj</groupId> 
       <artifactId>aspectjrt</artifactId> 
       <version>${aspectj.version}</version> 
       <scope>runtime</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <dependency> 
      <groupId>org.aspectj</groupId> 
      <artifactId>aspectjrt</artifactId> 
     </dependency> 
    </dependencies> 

    <organization> 
     <name>Scrum-Master.de - Agile Project Management</name> 
     <url>http://scrum-master.de</url> 
    </organization> 
</project> 
+0

你好@kriegaex - 我得到了同样的历程此消息 - 找不到跳过AspectJ的编译源代码 - ,我的代码没有 $ {主级}这样,什么可以在这种情况下 –

+0

[完成INFO] --- aspectj-maven-plugin:1.8:compile(default)@ Switchlite --- [INFO]没有修改发现跳过aspectJ编译 [INFO] [INFO] --- aspectj-maven-plugin:1.8 :test-compile(默认)@Switchlite --- [警告]没有发现源代码跳过aspectJ编译 [信息] –

+0

你不需要使用Exec Maven插件,它是可选的,而不是你的问题的根源。但是,如果没有主类要执行,为什么要尝试构建可执行JAR?如果AspectJ Maven插件没有找到任何方面资源,也许你只是没有命名你的方面'* .aj',而是'* .java',或者你可能会把它们放到错误的目录中。我希望你有一个标准的Maven目录布局,例如'src/main/java'和'src/test/java'。也许最好为自己的问题创建一个自己的问题,而不是劫持这个问题。 – kriegaex

相关问题