I have a task to tackle into our old Grails application which developed by our previous co-worker. The version of grails apps used is 2.2.5 and run on Java 1.7. When I run the app I get this: ( about plugins.log4j.Log4jConfig.methodMissing BeanUtils)
Resolving [runtime] dependencies...
| Error log4j:ERROR Error initializing log4j: org/apache/commons/beanutils/BeanUtils
| Error java.lang.NoClassDefFoundError: org/apache/commons/beanutils/BeanUtils
| Error at org.codehaus.groovy.grails.plugins.log4j.Log4jConfig.methodMissing(Log4jConfig.groovy:103)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
The app does run but there is no log due to the above error message. Since there is no log so it is imposible to trace and understand the code. Thanks advance for any help.
Here are dependencies and plugin in BuildConfig.groovy
dependencies {
runtime 'mysql:mysql-connector-java:5.1.22'
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
compile "org.jadira.usertype:usertype.jodatime:1.9"
runtime 'com.paypal.sdk:rest-api-sdk:0.7.0'
}
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.1.6"
compile ':runtime-logging:0.4'
build ":tomcat:$grailsVersion"
compile ":spring-security-core:1.2.7.3"
compile ":spring-security-ui:0.2"
compile ":famfamfam:1.0.1"
compile ":jquery-ui:1.8.24"
compile ":joda-time:1.4"
compile ":quartz:1.0-RC6"
compile ":audit-logging:0.5.4"
compile ":console:1.2"
compile ":mail:1.0.1"
compile ":kickstart-with-bootstrap:0.9.6"
runtime ":database-migration:1.3.6"
compile ':cache:1.0.1'
compile ':crypto:2.0'
compile ":csv:0.3.1"
test ":code-coverage:1.2.6"
compile ":gmetrics:0.3.1"
compile ":codenarc:0.23"
compile ":export:1.6"
}
And Log4j configuration in Config.groovy
log4j = {
def gbPattern = pattern(conversionPattern: "%d{dd MMM yyyy HH:mm:ss} [%X{user_rid},%X{user_name},%X{user_action}] [%5p] %-30.30c{2} %m%n")
def infoLog = "${new File('./logs').exists() ? './logs' : '/tmp/'}/info.log"
def debugLog = "${new File('./logs').exists() ? './logs' : '/tmp/'}/debug.log"
appenders {
console name: 'stdout', layout: gbPattern
appender new DailyRollingFileAppender(
name: 'debugLog',
threshold: org.apache.log4j.Level.DEBUG,
datePattern: "'.'yyyy-MM-dd", // See the API for all patterns.
fileName: debugLog,
layout: gbPattern
)
appender new DailyRollingFileAppender(
name: 'rollingLog',
threshold: org.apache.log4j.Level.INFO,
datePattern: "'.'yyyy-MM-dd", // See the API for all patterns.
fileName: infoLog,
layout: gbPattern
)
}
root {
if(Environment.isDevelopmentMode()) {
info 'stdout', 'rollingLog', 'debugLog'
} else {
info 'rollingLog', 'debugLog'
}
additivity = false
}
Try adding bellow dependency in BuildConfig.groovy in plugins:
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4'
Related
I am trying to connect to a database using Spring. Unfortunately, it always gives me the error message, can that it could not find a certain method.
Incidental information that may not hurt. The program is complied with Java 8 . Accordingly, the server also runs on Java 8
Thanks for the help!
Error
build.gradle:
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'java'
}
group = 'io.github.rysefoxx'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
mavenLocal()
maven {
url "https://repo.codemc.org/repository/maven-public/"
}
}
dependencies {
compileOnly files('lib/spigot.jar')
compileOnly 'org.projectlombok:lombok:1.18.24'
implementation 'io.github.rysefoxx:RyseInventory-Plugin:1.1.9-SNAPSHOT'
implementation 'io.github.rysefoxx:Hologram:1.0-SNAPSHOT'
implementation 'net.wesjd:anvilgui:1.5.3-SNAPSHOT'
implementation 'org.hibernate:hibernate-core:5.6.5.Final'
implementation 'org.hibernate:hibernate-envers:5.6.5.Final'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-cache:2.6.7'
implementation 'org.springframework:spring-aspects:5.3.19'
implementation 'mysql:mysql-connector-java:8.0.28'
implementation 'org.reflections:reflections:0.10.2'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.2'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
}
shadowJar {
mergeServiceFiles()
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
spring.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/home
spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/home
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
spring.jpa.database=MYSQL
spring.jpa.hibernate.ddl-auto=none
hibernate.hbm2ddl.auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=false
spring.datasource.initialization-mode=always
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.factories:
org.springframework.data.repository.core.support.RepositoryFactorySupport=org.springframework.data.jpa.repository.support.JpaRepositoryFactory
org.springframework.data.util.ProxyUtils$ProxyDetector=org.springframework.data.jpa.util.HibernateProxyDetector
# Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener,\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer,\
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.autoconfigure.BackgroundPreinitializer,\
org.springframework.boot.ClearCachesApplicationListener,\
org.springframework.boot.builder.ParentContextCloserApplicationListener,\
org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\
org.springframework.boot.context.FileEncodingApplicationListener,\
org.springframework.boot.context.config.AnsiOutputApplicationListener,\
org.springframework.boot.context.config.ConfigFileApplicationListener,\
org.springframework.boot.context.config.DelegatingApplicationListener,\
org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,\
org.springframework.boot.context.logging.LoggingApplicationListener,\
org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener
# Auto Configuration Import Listeners
org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\
org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener
# Auto Configuration Import Filters
org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\
org.springframework.boot.autoconfigure.condition.OnBeanCondition,\
org.springframework.boot.autoconfigure.condition.OnClassCondition,\
org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.github.rysefoxx.spring.SpringSpigotAutoConfiguration,\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\
org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration,\
org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\
org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\
org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\
org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\
org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\
org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,\
org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration,\
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketRequesterAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketServerAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration,\
org.springframework.boot.autoconfigure.security.rsocket.RSocketSecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
# Failure analyzers
org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.boot.autoconfigure.data.redis.RedisUrlSyntaxFailureAnalyzer,\
org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\
org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingFailureAnalyzer,\
org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\
org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer,\
org.springframework.boot.autoconfigure.session.NonUniqueSessionRepositoryFailureAnalyzer,\
org.springframework.boot.context.properties.NotConstructorBoundInjectionFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BeanCurrentlyInCreationFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BeanDefinitionOverrideFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BeanNotOfRequiredTypeFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BindFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.BindValidationFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.UnboundConfigurationPropertyFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.ConnectorStartFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.NoSuchMethodFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.NoUniqueBeanDefinitionFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.PortInUseFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer
# Temcensored availability providers
org.springframework.boot.autoconfigure.temcensored.TemcensoredAvailabilityProvider=\
org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemcensoredAvailabilityProvider,\
org.springframework.boot.autoconfigure.mustache.MustacheTemcensoredAvailabilityProvider,\
org.springframework.boot.autoconfigure.groovy.temcensored.GroovyTemcensoredAvailabilityProvider,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemcensoredAvailabilityProvider
# PropertySource Loaders
org.springframework.boot.env.PropertySourceLoader=\
org.springframework.boot.env.PropertiesPropertySourceLoader,\
org.springframework.boot.env.YamlPropertySourceLoader
# Run Listeners
org.springframework.boot.SpringApplicationRunListener=\
org.springframework.boot.context.event.EventPublishingRunListener
# Error Reporters
org.springframework.boot.SpringBootExceptionReporter=\
org.springframework.boot.diagnostics.FailureAnalyzers
# Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\
org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor,\
org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor,\
org.springframework.boot.reactor.DebugAgentEnvironmentPostProcessor
# FailureAnalysisReporters
org.springframework.boot.diagnostics.FailureAnalysisReporter=\
org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter
org.springframework.beans.BeanInfoFactory=org.springframework.beans.ExtendedBeanInfoFactory
It's not unlikely to be a problem caused by the Shadow Plugin, it has a hurdle: You have to tell it how to handle file collisions, i.e. files with the same name. While this is not hard, and you already did it partially ( mergeServiceFiles()), I use it with Gradle Kotlin DSL like:
tasks.withType<ShadowJar> {
mergeServiceFiles()
append("META-INF/spring.handlers")
append("META-INF/spring.schemas")
append("META-INF/spring.tooling")
transform(
PropertiesFileTransformer().apply {
paths = mutableListOf("META-INF/spring.factories")
mergeStrategy = "append"
})
}
It doesn't tell in its current version when such a conflict occurs, so you have to waste big amounts of time finding the conflicts yourself. But there is a pull request that it tells if there is a collision: https://github.com/johnrengelman/shadow/pull/773.
Until the pull request gets merged you could use the forked branch to be always informed about file collisions: https://github.com/JD-CSTx/shadow/tree/chapmajs-collision_logging.
Maybe I'm guessing wrong, and your problem is caused by something else, but this looks definitely like it could come from file collisions.
I'm new to Gradle.
When I run the build, instead of copying specific dependencies to specific directories, the build adds both compile and testCompile dependencies to src/test/resources.
I would like to be able to copy only test compile dependencies to src/test/resources and all other dependencies to main/src/resources.
Thank you
apply plugin: 'java'
apply plugin: 'war'
String spring_version = "3.1.2.RELEASE#jar" ;
String spring_sec_version = "3.1.2.RELEASE#jar" ;
String hibernate_version = "4.1.7.Final#jar" ;
repositories {
mavenCentral()
}
// "org.springframework:spring-oxm:"+spring_version,
List spring = [
"org.springframework:spring-context:"+spring_version,
"org.springframework:spring-beans:"+spring_version,
"org.springframework:spring-core:"+spring_version,
"org.springframework:spring-aop:"+spring_version,
"org.springframework:spring-expression:"+spring_version,
"org.springframework:spring-jdbc:"+spring_version,
"org.springframework:spring-tx:"+spring_version,
"org.springframework:spring-web:"+spring_version,
"org.springframework:spring-webmvc:"+spring_version,
"org.springframework:spring-orm:"+spring_version,
"org.springframework:spring-asm:"+spring_version
]
List spring_security = [
"org.springframework.security:spring-security core:"+spring_sec_version,
"org.springframework.security:spring-security-config:"+spring_sec_version,
"org.springframework.security:spring-security-web:"+spring_sec_version
]
List spring_aop = [
"aopalliance:aopalliance:1.0#jar",
"cglib:cglib-nodep:2.2.2#jar"
]
List validation_lib = [
"org.hibernate:hibernate-validator:4.3.0.Final#jar",
"javax.validation:validation-api:1.0.0.GA#jar"
]
List log_lib = [
"org.jboss.logging:jboss-logging:3.1.2.GA#jar",
"org.slf4j:slf4j-api:1.6.6#jar",
"org.slf4j:slf4j-jdk14:1.6.6#jar",
"org.slf4j:log4j-over-slf4j:1.6.6#jar",
"org.slf4j:jcl-over-slf4j:1.6.6#jar",
"log4j:log4j:1.2.17#jar"
]
List hibernate_api = [
"org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final#jar"
]
List hibernate = [
"org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.1.Final#jar",
"org.hibernate.common:hibernate-commons-annotations:4.0.1.Final#jar",
"org.javassist:javassist:3.16.1-GA",
"org.hibernate:hibernate-entitymanager:"+hibernate_version,
"org.hibernate:hibernate-core:"+hibernate_version
]
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.10'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
compile hibernate_api
compile hibernate
compile spring
compile spring_security
compile spring_aop
compile "org.codehaus.jackson:jackson-jaxrs:1.9.9" //lib jackson for JSON
compile validation_lib
compile log_lib
runtime "postgresql:postgresql:9.1-901.jdbc4#jar"
compile "rhino:js:1.7R2#jar"
}
task copyDependencies(type: Copy) {
from (configurations.compile)
into "src/main/resources"
}
task copyTestDependencies(type: Copy) {
from (configurations.testCompile)
into "src/test/resources"
}
build.dependsOn(copyDependencies)
build.dependsOn(copyTestDependencies)
Two things before answering:
The Gradle configurations compile and testCompile should be replaced with implementation and testImplementation. See documentation for details. My answer will use these instead.
Gradle has a great work avoidance approach, which is based on inputs / outputs computation. Copying anything into directories that are inputs of tasks, such as the resources directories, will mess that up. You really should avoid doing that and instead create new directories that are properly wired to be used where needed.
The problem you have is that testImplementation extends implementation and thus you will collect both runtime and test dependencies into the location for test dependencies.
The easiest path is to create a custom configuration for your tests dependencies so that you can access them independently of the runtime ones:
configurations {
testDependencies
testImplementations {
extendsFrom testDependencies
}
}
dependencies {
testDependencies group: 'junit', name: 'junit', version: '4.10'
// And others
}
And then you would copy the contents of testDependencies.
The one downside with this approach is that resolution of testDependencies will not be influenced by the runtime dependencies. This could be a problem but is context sensitive.
The other option is to filter runtime dependencies when copying the test ones. That solution is required if you realise that runtime dependencies impact the version of test dependencies.
I am trying to read gradle.properties into my build.gradle. I have defined some argument values in the property file and now wanted to pass these values to the argument. So that it will pass this argument value to my main methode.
But I am getting the following error:
group 'org.name'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'groovy'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "joda-time:joda-time:2.2"
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
// https://mvnrepository.com/artifact/org.dbunit/dbunit
compile group: 'org.dbunit', name: 'dbunit', version: '2.4.7'
compile "org.slf4j:slf4j-simple:1.7.9";
}
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'ExportDatatoXML'
println url
println username
println password
println folderPath
// arguments to pass to the application
args
[project.property('url'),project.property('username'),
project.property('password'),project.property('folderPath')]
}
This is my build.gradle file
gradle.properties file is:
url =jdbc:mysql://127.0.0.1:3306/name
username =root
password =name
folderPath =C:/Users/name/Desktop/DataBase/
Error is following:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\name\IdeaProjects\HelloWorld\build.gradle' line: 36
* What went wrong:
A problem occurred evaluating root project 'AI'.
> Cannot cast object 'jdbc:mysql://127.0.0.1:3306/name' with class
'java.lang.String' to class 'int'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info
or --debug option to get more log output.
BUILD FAILED
Total time: 12.448 secs
Cannot cast object 'jdbc:mysql://127.0.0.1:3306/name' with class
'java.lang.String' to class 'int'
13:01:41: External task execution finished 'build'
JavaExec.args is a list, so args[<anything>] is interpreted as "array-like-access" and so has to be an integer, but you give it a string.
Replace
args
[project.property('url'),project.property('username'),
project.property('password'),project.property('folderPath')]
with one of the following:
args
([project.property('url'),project.property('username'),
project.property('password'),project.property('folderPath')])
args project.property('url'), project.property('username'),
project.property('password'), project.property('folderPath')
args project.url, project.username, project.password, project.folderPath
args url, username, password, folderPath
All should be equivalent.
I wrote an ontology importer in Java to parse an RDF-formatted .owl file into a JSON-formatted string. More specifically, the static method parseOntologyObjectHierarchy parses the class hierarchy defined in the ontology into JSON. Everything works fine if I call the method from a JUnit test or the main method of a class (JUnit and the class main are invoked from IntelliJ IDEA Professional 2017). However, if I package my classes as a jar using gradle (including all dependencies), I get an org.semanticweb.owlapi.io.UnparsableOntologyException. The jar actually contains the required RDFXMLParser. Is the classpath in the jar not set properly?
Here is a minimal example IntelliJ IDEA project: https://drive.google.com/open?id=0B10MbhsMWfrydVNKZVJ0QVg1NlE
And here is the corresponding minimal jar: https://drive.google.com/open?id=0B10MbhsMWfrybjJIcDNWd0JFMUk
Here is the code:
public static String parseOntologyObjectHierarchy(String filename) throws OWLException {
System.out.println("OWL file: " + filename);
OWLOntology ontology = loadOntology(filename);
OWLDataFactory df = OWLManager.getOWLDataFactory();
return json = hierarchyToString(ontology, df.getOWLThing());
}
public static OWLOntology loadOntology(String filename) throws OWLOntologyCreationException {
File ontologyFile = new File(filename);
if (!ontologyFile.exists() || !ontologyFile.isFile()) {
throw new IllegalArgumentException("OWL file is not a file");
}
OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
OWLOntologyDocumentSource source = new FileDocumentSource(new File(filename), new RDFXMLDocumentFormat());
return ontologyManager.loadOntologyFromOntologyDocument(source);
}
Here is my build.gradle:
group 'com.example'
version '0.1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'net.sourceforge.owlapi', name: 'owlapi-osgidistribution', version: '5.1.0'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-apibinding', version: '5.1.0'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-parsers', version: '5.1.0'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-impl', version: '5.1.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'net.sourceforge.owlapi:org.semanticweb.hermit:1.3.8.510'
compile group: 'org.glassfish', name: 'javax.json', version: '1.0.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'ExampleCom Ontology Importer',
'Implementation-Version': version,
'Main-Class': 'com.example.ontology.OntologyImporter'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Here is the exception text:
$ java -jar am-ontology_importer-all-0.1.0-SNAPSHOT.jar
OWL file: C:/Users/me/Desktop/Projects/example/example-0.1.0.owl
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further detail
s.
Exception in thread "main" org.semanticweb.owlapi.io.UnparsableOntologyException
: Problem parsing file:/C:/Users/me/Desktop/Projects/example/example-0.1.0.owl
Could not parse ontology. Either a suitable parser could not be found, or parsi
ng failed. See parser logs below for explanation.
The following parsers were tried:
1) org.coode.owlapi.obo12.parser.OWLOBO12Parser#1ca3d04
Detailed logs:
--------------------------------------------------------------------------------
Parser: org.coode.owlapi.obo12.parser.OWLOBO12Parser#1ca3d04
Stack trace:
Lexical error at line 1, column 22. Encountered: "\n" (10), after : "" o
rg.coode.owlapi.obo12.parser.OBOParserTokenManager.getNextToken(OBOParserTokenMa
nager.java:1059)
org.coode.owlapi.obo12.parser.OBOParser.jj_ntk_f(OBOParser.java:296)
org.coode.owlapi.obo12.parser.OBOParser.TagValuePair(OBOParser.java:147)
org.coode.owlapi.obo12.parser.OBOParser.Header(OBOParser.java:110)
org.coode.owlapi.obo12.parser.OBOParser.parse(OBOParser.java:80)
org.coode.owlapi.obo12.parser.OWLOBO12Parser.parse(OWLOBO12Parser.java:1
09)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OW
LOntologyFactoryImpl.java:188)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyMa
nagerImpl.java:1072)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOn
tologyManagerImpl.java:1033)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOn
tologyDocument(OWLOntologyManagerImpl.java:982)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology
(OWLOntologyFactoryImpl.java:229)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntolog
yManagerImpl.java:1072)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OW
LOntologyManagerImpl.java:1033)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFro
mOntologyDocument(OWLOntologyManagerImpl.java:982)
at com.example.ontology.OntologyImporter.loadOntology(OntologyImpo
rter.java:52)
at com.example.ontology.OntologyImporter.parseOntologyObjectHierar
chy(OntologyImporter.java:64)
at com.example.ontology.OntologyImporter.main(OntologyImporter.jav
a:142)
in your minimal jar, the META-INF/services folder contains multiple copies of org.semanticweb.owlapi.io.OWLParserFactory - these are likely coming from your merging of OWLAPI dependencies.
Each module declares in this file which parsers can be found in the module (they are interpreted by ServiceLoader to provide instances); owlapi-distribution contains a merged copy of all the files provided by OWLAPI modules. You need to ensure that that's the only file included in your jar.
The same is true for the other files found in this folder.
I have this problem with the annotations for few days...
Error:(13, 26) cannot find symbol class LoginActivityAnnotations_
But the annotation class exist and the class import in my MainActivity work greate
http://imagizer.imageshack.us/v2/150x100q90/911/x8RzRM.png
The annotaitons classes were generated correctly in this directory:
http://imagizer.imageshack.us/v2/150x100q90/538/bEplNx.png
This is my build.grandle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:+'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
repositories {
mavenCentral()
mavenLocal()
}
apt {
arguments {
resourcePackageName "com.ar.sdocs"
androidManifestFile variant.processResources.manifestFile
}
}
dependencies {
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
apt "org.androidannotations:androidannotations:+"
compile 'org.androidannotations:androidannotations-api:+'
compile 'com.nhaarman.listviewanimations:library:2.6.0'
compile files('libs/commons-lang3-3.3.1.jar')
compile 'com.google.android.gms:play-services:4.3.+'
compile files('libs/joda-time-2.3.jar')
compile files('libs/bcprov-ext-jdk15on-150.jar')
compile files('libs/bugsense-3.6.1.jar')
compile 'org.apache.httpcomponents:httpcore:4.3.2'
compile 'org.apache.httpcomponents:httpmime:4.3.4'
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/json-simple-1.1.1.jar')
apt "org.androidannotations:androidannotations:+"
compile 'org.androidannotations:androidannotations-api:+'
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName '0.1'
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
android.applicationVariants.each { variant ->
aptOutput = file("${project.buildDir}/generated/source/apt/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
variant.javaCompile.doFirst {
println "*** compile doFirst ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', aptOutput
]
}
variant.addJavaSourceFoldersToModel(aptOutput)
}
But every time I run a build, I get the error I mentioned before. I'm trying different configurations days ago but I can not find one that works
Thats the complete error (I only import the annotations class)
Error:(14, 26) cannot find symbol class LoginActivityAnnotations_
Note: Resolve log file to /Users/CARRY/AndroidStudioProjects/sdocs/SDocs/build/generated/source/apt/androidannotations.log
Note: Initialize AndroidAnnotations 3.0.1 with options {resourcePackageName=com.ar.sdocs, androidManifestFile=/Users/CARRY/AndroidStudioProjects/sdocs/SDocs/build/intermediates/manifests/debug/AndroidManifest.xml}
Note: Start processing for 5 annotations on 145 elements
Note: AndroidManifest.xml file found with specified path: /Users/CARRY/AndroidStudioProjects/sdocs/SDocs/build/intermediates/manifests/debug/AndroidManifest.xml
Note: AndroidManifest.xml found: AndroidManifest [applicationPackage=com.ar.sdocs, componentQualifiedNames=[com.ar.sdocs.main.MainActivity, com.ar.sdocs.login.LoginActivity, com.ar.sdocs.dashboard.DashboardActivity, com.ar.sdocs.login.registro.RegistroActivity, com.ar.sdocs.dashboard.settings.editar.SettingsUserEditActivity, com.ar.sdocs.dashboard.upload.UploadActivity, com.ar.sdocs.dashboard.materias.main.MateriaActivity, com.ar.sdocs.util.media.FilePickerActivity, com.ar.sdocs.gcm.GcmIntentService, com.ar.sdocs.gcm.GcmBroadcastReceiver], permissionQualifiedNames=[android.permission.USE_CREDENTIALS, android.permission.GET_ACCOUNTS, android.permission.READ_PROFILE, android.permission.READ_CONTACTS, android.permission.INTERNET, android.permission.WAKE_LOCK, com.google.android.c2dm.permission.RECEIVE, android.permission.CAMERA, android.permission.READ_EXTERNAL_STORAGE, com.example.gcm.permission.C2D_MESSAGE], applicationClassName=null, libraryProject=false, debugabble=false, minSdkVersion=14, maxSdkVersion=-1, targetSdkVersion=19]
Note: Found project R class: com.ar.sdocs.R
Note: Found Android class: android.R
Note: Validating elements
Note: Validating with EActivityHandler: [com.ar.sdocs.login.LoginActivityAnnotations]
/Users/CARRY/AndroidStudioProjects/sdocs/SDocs/src/main/java/com/ar/sdocs/login/LoginActivityAnnotations.java
Warning:(45, 1) The component LoginActivityAnnotations_ is not registered in the AndroidManifest.xml file.
Note: Validating with ViewByIdHandler: [emailEditText, passwordEditText]
Note: Validating with ClickHandler: [loginButtonClicked(), registerButtonClicked()]
Note: Validating with TouchHandler: [loginRelativeLayoutTouched(android.view.View,android.view.MotionEvent)]
Note: Validating with AfterViewsHandler: [verificarLogin()]
Note: Processing root elements
Note: Processing root elements EActivityHandler: [com.ar.sdocs.login.LoginActivityAnnotations]
Note: Processing enclosed elements
Note: Number of files generated by AndroidAnnotations: 1
Note: Writting following API classes in project: []
Note: Generating class: com.ar.sdocs.login.LoginActivityAnnotations_
Note: Time measurements: [Whole Processing = 148 ms], [Process Annotations = 32 ms], [Generate Sources = 31 ms], [Find R Classes = 24 ms], [Extract Annotations = 23 ms], [Validate Annotations = 16 ms], [Extract Manifest = 11 ms],
Note: Finish processing
Note: Start processing for 0 annotations on 1 elements
Note: Time measurements: [Whole Processing = 3 ms],
Note: Finish processing
Note: Start processing for 0 annotations on 0 elements
Note: Time measurements: [Whole Processing = 1 ms],
Note: Finish processing
Warning:Unclosed files for the types '[dummy1407025286017]'; these types will not undergo annotation processing
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Information:BUILD SUCCESSFUL
Information:Total time: 21.886 secs
Information:1 error
Information:4 warnings
Information:See complete output in console
I could be because you havn't included the LoginActivityAnnotations_ file where you use it - because Android Studio does not help you with that. I had that problem.
You need to make an include of the package where the LoginActivityAnnotations file.
If you were using this include, to get the file without the underscore:
com.example.LoginActivityAnnotations
Then use this one:
com.example.* //To load LoginActivityAnnotations_
(The include will be grey and you will still be left with red words but it will compile)