Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

java - Specific compile rule Maven

I have a java project which uses some already existing specific code.

This code has a MakeFile

all: Parser.java 
     javac -cp java-cup-11b-runtime.jar:. *.java

Parser.java: Parser.cup
     java -jar java-cup-11b.jar -nonterms -expect 150 -interface -parser Parser Parser.cup

I know for example that with Gradle it will look like this:

task make {
    dependsOn build
    exec{
        workingdir './src/main/java'
        commandLine "bash","-c", "java -jar java-cup-11b.jar -nonterms -expect 150 -interface -parser Parser Parser.cup;javac -cp java-cup-11b-runtime.jar:. *.java"
    }
}

So I am using it on a bigger project on Intellij with Maven, and I don't know how to setup these specific rules.

I tried like this:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <compilerArgs>
                <arg>Parser.java:-nonterms -expect 150 -interface -parser Parser</arg>
            </compilerArgs>
        </configuration>
    </plugin> 

---EDIT

The package I would like to use is Cup.

They provide a code block for Ant. http://www2.cs.tum.edu/projects/cup/install.php

So I want the same for Maven.

I found an old plugin : http://czt.sourceforge.net/dev/cup-maven-plugin/ but the repository is down.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The java ... part cannot be handled by the maven-compiler-plugin. java is the Java Runtime, not the Java Compiler. Remove that declaration altogether. You have to use the Exec Maven Plugin with its java goal to run code from java-cup-11b.jar:

  1. Install the dependency java-cup-11b.jar into your local Maven repo with the install-file goal of the Maven Install Plugin. Note the Maven artifact name convention <artifactId>-<version>-<classifier/qualifier>.
mvn install:install-file -Dfile=java-cup-11-b.jar 
                         -DgroupId=org.some.group 
                         -DartifactId=java-cup 
                         -Dversion=11 
                         -Dclassifier=b 
                         -Dpackaging=jar 
                         -DgeneratePom=true 
                         -DcreateChecksum=true
  1. Use it in your POM like:
  <dependencies>
    <dependency>
      <groupId>org.some.group</groupId>
      <artifactId>java-cup</artifactId>
      <version>11-b</version>
    </dependency>
  </dependencies>

3. Add to your POM:

<build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>exec-parser-cup</id>
            <phase>process-resources</phase>  
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>Parser.cup</mainClass>
          <arguments>
            <argument>-nonterms</argument>
            <argument>-expect</argument>
            <argument>150</argument>
            <argument>-interface</argument>
            <argument>-parser</argument>
            <argument>Parser</argument>
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>

For the javac ... part:

  1. Place the *.java sources in src/main/java[/possible/package/path(s)].

  2. Install the dependency java-cup-11b-runtime.jar into your local Maven repo with the install-file goal of the Maven Install Plugin.

mvn install:install-file -Dfile=java-cup-runtime-11-b.jar 
                         -DgroupId=org.some.group 
                         -DartifactId=java-cup-runtime 
                         -Dversion=11 
                         -Dclassifier=b 
                         -Dpackaging=jar 
                         -DgeneratePom=true 
                         -DcreateChecksum=true
  1. Use it in your POM like:
  <dependencies>
    <dependency>
      <groupId>org.some.group</groupId>
      <artifactId>java-cup-runtime</artifactId>
      <version>11-b</version>
    </dependency>
  </dependencies>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...