我不能爲我的生活弄清楚如何讓我的Spring項目在IDE之外運行。我正在使用Gradle。我搜索了上下,包括pply插件:'應用'的措辭,我看到罐生成,但當我通過gradlew運行,它死了說它無法找到文件。春天的項目將不會從命令行運行
1)我需要一個單獨的build.gradle文件來運行它嗎?在試圖運行之前,我必須拿出大量其他項目的東西(必須用#刪除所有時間)
2)爲什麼它不工作?我甚至需要一個build.gradle文件嗎?你如何從Spring IDE以最簡單的方式在命令行上運行?搖籃的
apply plugin: 'application'
dependencies {
compile project(':caffeine')#
compile libraries.guava#
testCompile test_libraries.junit#
testCompile test_libraries.truth#
testCompile test_libraries.easymock#
testCompile test_libraries.guava_testlib#
compile group: 'org.apache.activemq', name: 'activemq-kahadb-store', version: '5.13.3'
compile group: 'org.apache.activemq', name: 'activemq-all', version: '5.13.3'
}
jar.manifest {#
name 'com.github.ben-manes.caffeine.guava'#
instruction 'Import-Package',#
'com.google.common.cache',#
'com.github.benmanes.caffeine.cache',#
'com.github.benmanes.caffeine.cache.stats'#
instruction 'Export-Package',#
'com.github.benmanes.caffeine.guava'#
}#
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
repositories {
mavenCentral()
}
test {#
systemProperty 'guava.osgi.version', versions.guava#
systemProperty 'caffeine.osgi.jar',
project(':caffeine').jar.archivePath.path#
systemProperty 'caffeine-guava.osgi.jar',#
project(':guava').jar.archivePath.path#
}#
mainClassName = 'org.apache.activemq.store.kahadb.disk.util.DiskMark'
編輯輸出用剝離的build.gradle:
Total time: 0.579 secs
tareks-MacBook-Pro:distributions tarekzegar$ gradlew run --stacktrace
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
Error: Could not find or load main class org.apache.activemq.store.kahadb.disk.util.DiskMark
:run FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java'' finished with non-zero exit value
EDIT2: 感謝您的響應。我使用disk.util.DiskBenchmark並修改了特定的文件,因爲我需要添加一個緩存,因此我的名爲DiskMark.Java。這裏是我的DiskMark的前幾行
package org.apache.activemq.store.kahadb.disk.util;
import java.io.File;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.Random;
import java.util.Iterator;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.RemovalListener;
import com.github.benmanes.caffeine.guava.CaffeinatedGuava;
import com.google.common.cache.Cache;
import org.apache.activemq.util.RecoverableRandomAccessFile;
/**
* This class is used to get a benchmark the raw disk performance.
*/
public class DiskMark {
private static final boolean SKIP_METADATA_UPDATE =
Boolean.getBoolean("org.apache.activemq.file.skipMetadataUpdate");
boolean verbose;
// reads and writes work with 4k of data at a time.
int bs = 1024 * 4;
// Work with 100 meg file.
long size = 1024 * 1024 * 500;
long sampleInterval = 10 * 1000;
static Cache<Long, byte[]> cache;
static Callable<byte[]> loader;
static ArrayList<Long> longIndexList;
boolean enableCache = true;
public static void main(String[] args) {
我應該採取不同的方式嗎?它在IDE
EDIT運行正常3: 我感動的java文件在src/main/java下一個新的包,包的名字是DiskCharacterize,類名DiskMark。還是不是工作。
我這個的build.gradle
/**
* Guava compatibility adapter.
*
* The tests are forked from Guava commit e370dde.
*/
apply plugin: 'application'
dependencies {
compile project(':caffeine')
compile libraries.guava
testCompile test_libraries.junit
testCompile test_libraries.truth
testCompile test_libraries.easymock
testCompile test_libraries.guava_testlib
compile group: 'org.apache.activemq', name: 'activemq-kahadb-store', version: '5.13.3'
compile group: 'org.apache.activemq', name: 'activemq-all', version: '5.13.3'
}
jar.manifest {
name 'com.github.ben-manes.caffeine.guava'
instruction 'Import-Package',
'com.google.common.cache',
'com.github.benmanes.caffeine.cache',
'com.github.benmanes.caffeine.cache.stats'
instruction 'Export-Package',
'com.github.benmanes.caffeine.guava'
}
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
repositories {
mavenCentral()
}
test {
systemProperty 'guava.osgi.version', versions.guava
systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path
systemProperty 'caffeine-guava.osgi.jar', project(':guava').jar.archivePath.path
}
mainClassName = 'DiskCharacterize.DiskMark'
我切換到/編譯/庫/目錄,其中GS-gradle這個-0.1.0.jar存在建造它。我填充此目錄與此的build.gradle
/**
* Guava compatibility adapter.
*
* The tests are forked from Guava commit e370dde.
*/
apply plugin: 'application'
/*dependencies {
compile project(':caffeine')
compile libraries.guava
testCompile test_libraries.junit
testCompile test_libraries.truth
testCompile test_libraries.easymock
testCompile test_libraries.guava_testlib
compile group: 'org.apache.activemq', name: 'activemq-kahadb-store', version: '5.13.3'
compile group: 'org.apache.activemq', name: 'activemq-all', version: '5.13.3'
}
jar.manifest {
name 'com.github.ben-manes.caffeine.guava'
instruction 'Import-Package',
'com.google.common.cache',
'com.github.benmanes.caffeine.cache',
'com.github.benmanes.caffeine.cache.stats'
instruction 'Export-Package',
'com.github.benmanes.caffeine.guava'
}*/
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
repositories {
mavenCentral()
}
/*test {
systemProperty 'guava.osgi.version', versions.guava
systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path
systemProperty 'caffeine-guava.osgi.jar', project(':guava').jar.archivePath.path
}*/
mainClassName = 'DiskCharacterize.DiskMark'
它失敗
xxxxxx$ gradlew run
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
Error: Could not find or load main class DiskCharacterize.DiskMark
:run FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
這是怎麼回事?我需要它來運行,不能爲我的生活弄清楚
EDIT4: gradle這個運行不起作用,即使申請插件:「Java」作爲補充,插件應用隱式調用Java插件反正。
但是,我得到它運行。我去../build/distributions/文件夾,它們都有番石榴-2.3.1-SNAPSHOT.tar & guava-2.3.1-SNAPSHOT.zip,我解壓zip文件,找到一個bash文件並簡單地執行它;程序運行。爲什麼Gradle運行不起作用對我來說是未知的(如果您有任何想法,我仍然非常想知道)。謝謝大家你幫順便說一句,謝謝你奔M.
您可以在此處添加Gradle輸出以顯示它正在搜索但未找到的文件? – romeara
添加失敗的輸出 –
文件源路徑../Documents/caffeine-master/guava/src/test/java/org/apache/activemq/store/kahadb/disk/util/DiskMark.java –